problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define rep(i, a, b) for (int i = a; i < b; i++) #define repA(i, a, b) for (ll i = a; i <= b; i++) #define repD(i, b, a) for (int i = b; i >= a; i--) #define fill(a) memset(a, 0, sizeof(a)) #define f first #define s second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; int main() { ll k; cin >> k; queue<ll> q; repA(i, 1, 9) q.push(i); if (k <= 9) { return k; } else { k -= 9; while (k) { ll a = q.front(); q.pop(); if (a % 10 != 0) { ll var = a * 10 + (a % 10 - 1); k--; if (k == 0) { cout << var << endl; return 0; } q.push(var); } q.push(a * 10 + (a % 10)); k--; if (k == 0) { cout << a * 10 + (a % 10) << endl; return 0; } if (a % 10 != 9) { ll var = a * 10 + (a % 10 + 1); k--; if (k == 0) { cout << var << endl; return 0; } q.push(var); } } } }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define rep(i, a, b) for (int i = a; i < b; i++) #define repA(i, a, b) for (ll i = a; i <= b; i++) #define repD(i, b, a) for (int i = b; i >= a; i--) #define fill(a) memset(a, 0, sizeof(a)) #define f first #define s second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; int main() { ll k; cin >> k; queue<ll> q; repA(i, 1, 9) q.push(i); if (k <= 9) { cout << k << endl; } else { k -= 9; while (k) { ll a = q.front(); q.pop(); if (a % 10 != 0) { ll var = a * 10 + (a % 10 - 1); k--; if (k == 0) { cout << var << endl; return 0; } q.push(var); } q.push(a * 10 + (a % 10)); k--; if (k == 0) { cout << a * 10 + (a % 10) << endl; return 0; } if (a % 10 != 9) { ll var = a * 10 + (a % 10 + 1); k--; if (k == 0) { cout << var << endl; return 0; } q.push(var); } } } }
replace
20
21
20
21
0
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define rng(a) a.begin(), a.end() #define ina(n, a) \ cin >> n; \ for (int i = 1; i <= n; i++) \ cin >> a[i] #define sz(x) (int)(x).size() #define se second #define fi first #define prev coyhhhhhhyoc #define next sdNNNmNNNNNNNmds #define y0 hNNNNy_yNNNNNN_sNh #define y1 mNNNNNdtdNNNNNNtsNNm #define yn mNNNNNNNNy___smNNNms #define tm oooooosyysooooot #define read tyhyt #define rank ytmNmo #define index yyy #define pb push_back #define pcnt __builtin_popcountll #define rrep(i, a, b) for (int i = (b); i >= (a); i--) #define rall(x, a) for (auto x : a) #define MOD 1000000007 #define endl "\n" #define int long long typedef long long ll; using namespace std; bool isl(int x) { int p = x % 10; while (x) { int c = x % 10; if (abs(c - p) > 1) { return false; } p = c; x /= 10; } return true; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int k; cin >> k; int x = 0; while (k) { x++; k -= isl(x); } cout << x << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define rng(a) a.begin(), a.end() #define ina(n, a) \ cin >> n; \ for (int i = 1; i <= n; i++) \ cin >> a[i] #define sz(x) (int)(x).size() #define se second #define fi first #define prev coyhhhhhhyoc #define next sdNNNmNNNNNNNmds #define y0 hNNNNy_yNNNNNN_sNh #define y1 mNNNNNdtdNNNNNNtsNNm #define yn mNNNNNNNNy___smNNNms #define tm oooooosyysooooot #define read tyhyt #define rank ytmNmo #define index yyy #define pb push_back #define pcnt __builtin_popcountll #define rrep(i, a, b) for (int i = (b); i >= (a); i--) #define rall(x, a) for (auto x : a) #define MOD 1000000007 #define endl "\n" #define int long long typedef long long ll; using namespace std; bool isl(int x) { int p = x % 10; while (x) { int c = x % 10; if (abs(c - p) > 1) { return false; } p = c; x /= 10; } return true; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int k; cin >> k; int x = 0; while (k) { x++; int p = 1, tp = 10; while (x / tp) { int u = x / p % 10, d = x / tp % 10; if (u == d + 2) { x += 8 * p; x -= x % p; } else if (u < d - 1) { x += (d - 1 - u) * p; x -= x % p; } p *= 10, tp *= 10; } k -= isl(x); } cout << x << endl; return 0; }
insert
50
50
50
62
TLE
p02720
C++
Runtime Error
/** * Author: @glaucoacassioc * Created on 11.09.2020, 15:32:16 **/ #include <bits/stdc++.h> #define INF 1000000000 using namespace std; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; vector<vii> AdjList; vi pai, color, dist, ts; ll vals[1000002]; ll maxnr = 400000000; set<ll> s; void bkt(ll x) { if (s.find(x) != s.end()) return; if (x == 0) for (int i = 1; i <= 9; i++) bkt(i); else { int lst = x % 10; if (lst > 0) bkt(x * 10 + (lst - 1)); bkt(x * 10 + lst); if (lst < 9) bkt(x * 10 + (lst + 1)); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int k; cin >> k; bkt(0); while (k) { s.erase(s.begin()); --k; } cout << *s.begin() << endl; return 0; }
/** * Author: @glaucoacassioc * Created on 11.09.2020, 15:32:16 **/ #include <bits/stdc++.h> #define INF 1000000000 using namespace std; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; vector<vii> AdjList; vi pai, color, dist, ts; ll vals[1000002]; ll maxnr = 400000000; set<ll> s; void bkt(ll x) { if (s.find(x) != s.end()) return; s.insert(x); if (x >= maxnr) return; if (x == 0) for (int i = 1; i <= 9; i++) bkt(i); else { int lst = x % 10; if (lst > 0) bkt(x * 10 + (lst - 1)); bkt(x * 10 + lst); if (lst < 9) bkt(x * 10 + (lst + 1)); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int k; cin >> k; bkt(0); while (k) { s.erase(s.begin()); --k; } cout << *s.begin() << endl; return 0; }
insert
21
21
21
26
-11
p02720
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <stdio.h> #include <vector> using namespace std; #define int long long #define double long double #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define P pair<int, int> // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } bool integer(double n) { if (n == long(n)) return true; else return false; } int pow(int b, int a) { int aa = 1; rep(0, i, a) aa *= b; return aa; } int sankaku(int a) { return a * (a + 1) / 2; } bool search(int x) { int n; int a[n]; int l = 0, r = n; while (r - l >= 1) { int i = (l + r) / 2; if (a[i] == x) return true; else if (a[i] < x) l = i + 1; else r = i; } return false; } int lun[114514]; signed main() { ic(n) int sum = 1; rep(1, i, 10) { lun[sum] = i; sum++; } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { lun[sum] = i * 10 + j; sum++; } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { lun[sum] = i * 100 + j * 10 + k; sum++; } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { lun[sum] = i * 1000 + j * 100 + k * 10 + l; sum++; } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { lun[sum] = i * 10000 + j * 1000 + k * 100 + l * 10 + m; sum++; } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { lun[sum] = i * 100000 + j * 10000 + k * 1000 + l * 100 + m * 10 + o; sum++; } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { lun[sum] = i * 1000000 + j * 100000 + k * 10000 + l * 1000 + m * 100 + o * 10 + p; sum++; } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { lun[sum] = i * 10000000 + j * 1000000 + k * 100000 + l * 10000 + m * 1000 + o * 100 + p * 10 + q; sum++; } } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { rep(max(0, q - 1), r, min(10, q + 2)) { lun[sum] = i * 100000000 + j * 10000000 + k * 1000000 + l * 100000 + m * 10000 + o * 1000 + p * 100 + q * 10 + r; sum++; } } } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { rep(max(0, q - 1), r, min(10, q + 2)) { rep(max(0, r - 1), s, min(10, r + 2)) { lun[sum] = i * 1000000000 + j * 100000000 + k * 10000000 + l * 1000000 + m * 100000 + o * 10000 + p * 1000 + q * 100 + r * 10 + s; sum++; } } } } } } } } } } c(lun[n]) }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <stdio.h> #include <vector> using namespace std; #define int long long #define double long double #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define P pair<int, int> // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } bool integer(double n) { if (n == long(n)) return true; else return false; } int pow(int b, int a) { int aa = 1; rep(0, i, a) aa *= b; return aa; } int sankaku(int a) { return a * (a + 1) / 2; } bool search(int x) { int n; int a[n]; int l = 0, r = n; while (r - l >= 1) { int i = (l + r) / 2; if (a[i] == x) return true; else if (a[i] < x) l = i + 1; else r = i; } return false; } int lun[314514]; signed main() { ic(n) int sum = 1; rep(1, i, 10) { lun[sum] = i; sum++; } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { lun[sum] = i * 10 + j; sum++; } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { lun[sum] = i * 100 + j * 10 + k; sum++; } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { lun[sum] = i * 1000 + j * 100 + k * 10 + l; sum++; } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { lun[sum] = i * 10000 + j * 1000 + k * 100 + l * 10 + m; sum++; } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { lun[sum] = i * 100000 + j * 10000 + k * 1000 + l * 100 + m * 10 + o; sum++; } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { lun[sum] = i * 1000000 + j * 100000 + k * 10000 + l * 1000 + m * 100 + o * 10 + p; sum++; } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { lun[sum] = i * 10000000 + j * 1000000 + k * 100000 + l * 10000 + m * 1000 + o * 100 + p * 10 + q; sum++; } } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { rep(max(0, q - 1), r, min(10, q + 2)) { lun[sum] = i * 100000000 + j * 10000000 + k * 1000000 + l * 100000 + m * 10000 + o * 1000 + p * 100 + q * 10 + r; sum++; } } } } } } } } } rep(1, i, 10) { rep(max(0, i - 1), j, min(10, i + 2)) { rep(max(0, j - 1), k, min(10, j + 2)) { rep(max(0, k - 1), l, min(10, k + 2)) { rep(max(0, l - 1), m, min(10, l + 2)) { rep(max(0, m - 1), o, min(10, m + 2)) { rep(max(0, o - 1), p, min(10, o + 2)) { rep(max(0, p - 1), q, min(10, p + 2)) { rep(max(0, q - 1), r, min(10, q + 2)) { rep(max(0, r - 1), s, min(10, r + 2)) { lun[sum] = i * 1000000000 + j * 100000000 + k * 10000000 + l * 1000000 + m * 100000 + o * 10000 + p * 1000 + q * 100 + r * 10 + s; sum++; } } } } } } } } } } c(lun[n]) }
replace
153
154
153
154
-11
p02720
C++
Runtime Error
#define ll long long #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mp make_pair #define fo(i, n) for (ll i = 0; i < n; i++) // #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> ll pi = acos(-1); ll z = 998244353; ll inf = 100000000000000000; ll p1 = 37; ll p2 = 53; ll mod1 = 202976689; ll mod2 = 203034253; ll gcd(ll a, ll b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll p) { if (b == 0) return 1; ll c = power(a, b / 2, p); if (b % 2 == 0) return ((c * c) % p); else return ((((c * c) % p) * a) % p); } ll inverse(ll a, ll n) { return power(a, n - 2, n); } ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll left(ll i) { return ((2 * i)); } ll right(ll i) { return ((2 * i) + 1); } void swap(ll &a, ll &b) { ll c = a; a = b; b = c; return; } // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> // ordered_set s ; s.order_of_key(val) no. of elements strictly less than val // s.find_by_order(i) itertor to ith element (0 indexed) void solve() { ll n; cin >> n; ll dp[11][10]; fo(i, 11) { fo(j, 10) { dp[i][j] = 0; } } fo(j, 10) { dp[1][j] = 1; } for (ll i = 2; i < 11; i++) { fo(j, 10) { if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1]; dp[i][j] += dp[i - 1][j]; if (j + 1 < 10) dp[i][j] += dp[i - 1][j + 1]; } } /* fo(i , 11) { fo(j , 10) cout << dp[i][j] << ' '; cout << endl ; }*/ ll sum = 0, dig = 0; vector<ll> ans; /*for(ll i = 1 ; i < 11 ; i++) { for(ll j = 0 ; j <= 9 ; j++) { cout << dp[i][j] << ' '; } cout << endl ; } cout << endl ;*/ for (ll i = 1; i < 11; i++) { for (ll j = 1; j < 10; j++) { if (sum + dp[i][j] >= n) { n -= sum; dig = i - 1; ans.pub(j); break; } else sum += dp[i][j]; } if (ans.size() == 1) break; } /*cout << "here " << endl ; cout << dig << endl; cout << n << endl ; //exit(0) ;*/ while (dig > 0) { ll ssum = 0; ll last_dig = ans[ans.size() - 1]; // cout << last_dig << ' ' << ssum << endl ; for (ll i = last_dig - 1; i <= last_dig + 1; i++) { if (i < 0 || i > 9) continue; if (ssum + dp[dig][i] >= n) { n -= ssum; dig--; ans.pub(i); break; } else ssum += dp[dig][i]; // cout << "sum = " << ssum << endl ; } } fo(i, ans.size()) { cout << ans[i]; } cout << endl; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll t; // cin >> t ; t = 1; while (t--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#define ll long long #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mp make_pair #define fo(i, n) for (ll i = 0; i < n; i++) // #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> ll pi = acos(-1); ll z = 998244353; ll inf = 100000000000000000; ll p1 = 37; ll p2 = 53; ll mod1 = 202976689; ll mod2 = 203034253; ll gcd(ll a, ll b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll p) { if (b == 0) return 1; ll c = power(a, b / 2, p); if (b % 2 == 0) return ((c * c) % p); else return ((((c * c) % p) * a) % p); } ll inverse(ll a, ll n) { return power(a, n - 2, n); } ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll left(ll i) { return ((2 * i)); } ll right(ll i) { return ((2 * i) + 1); } void swap(ll &a, ll &b) { ll c = a; a = b; b = c; return; } // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> // ordered_set s ; s.order_of_key(val) no. of elements strictly less than val // s.find_by_order(i) itertor to ith element (0 indexed) void solve() { ll n; cin >> n; ll dp[11][10]; fo(i, 11) { fo(j, 10) { dp[i][j] = 0; } } fo(j, 10) { dp[1][j] = 1; } for (ll i = 2; i < 11; i++) { fo(j, 10) { if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1]; dp[i][j] += dp[i - 1][j]; if (j + 1 < 10) dp[i][j] += dp[i - 1][j + 1]; } } /* fo(i , 11) { fo(j , 10) cout << dp[i][j] << ' '; cout << endl ; }*/ ll sum = 0, dig = 0; vector<ll> ans; /*for(ll i = 1 ; i < 11 ; i++) { for(ll j = 0 ; j <= 9 ; j++) { cout << dp[i][j] << ' '; } cout << endl ; } cout << endl ;*/ for (ll i = 1; i < 11; i++) { for (ll j = 1; j < 10; j++) { if (sum + dp[i][j] >= n) { n -= sum; dig = i - 1; ans.pub(j); break; } else sum += dp[i][j]; } if (ans.size() == 1) break; } /*cout << "here " << endl ; cout << dig << endl; cout << n << endl ; //exit(0) ;*/ while (dig > 0) { ll ssum = 0; ll last_dig = ans[ans.size() - 1]; // cout << last_dig << ' ' << ssum << endl ; for (ll i = last_dig - 1; i <= last_dig + 1; i++) { if (i < 0 || i > 9) continue; if (ssum + dp[dig][i] >= n) { n -= ssum; dig--; ans.pub(i); break; } else ssum += dp[dig][i]; // cout << "sum = " << ssum << endl ; } } fo(i, ans.size()) { cout << ans[i]; } cout << endl; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); /* #ifndef ONLINE_JUDGE freopen("inputf.txt" , "r" , stdin) ; freopen("outputf.txt" , "w" , stdout) ; freopen("error.txt" , "w" , stderr) ; #endif*/ ll t; // cin >> t ; t = 1; while (t--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
replace
152
157
152
157
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef pair<int, int> pii; typedef pair<long long, int> pli; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() ll mod = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int k; cin >> k; vvi dp(k, vi(10)); vi sum(k + 1); rep(i, 10) { dp[1][i] = 1; } sum[1] = 9; int num = 1; for (num = 2; num <= k; num++) { sum[num] = sum[num - 1]; rep(d, 10) { dp[num][d] = dp[num - 1][d]; if (d) { dp[num][d] += dp[num - 1][d - 1]; } if (d < 9) { dp[num][d] += dp[num - 1][d + 1]; } if (d) sum[num] += dp[num][d]; } if (sum[num] >= k) break; } string ret = ""; int cnt = sum[num - 1]; int prev = 0; for (int d = 1; d <= 9; d++) { if (cnt + dp[num][d] >= k) { prev = d; ret += '0' + d; break; } else cnt += dp[num][d]; } num--; while (num) { for (int d = prev - 1; d <= prev + 1; d++) { if (d >= 0 && d <= 9) { if (cnt + dp[num][d] >= k) { prev = d; ret += '0' + d; break; } else { cnt += dp[num][d]; } } } num--; } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef pair<int, int> pii; typedef pair<long long, int> pli; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() ll mod = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int k; cin >> k; if (k <= 9) { cout << k << endl; return 0; } vvi dp(k, vi(10)); vi sum(k + 1); rep(i, 10) { dp[1][i] = 1; } sum[1] = 9; int num = 1; for (num = 2; num <= k; num++) { sum[num] = sum[num - 1]; rep(d, 10) { dp[num][d] = dp[num - 1][d]; if (d) { dp[num][d] += dp[num - 1][d - 1]; } if (d < 9) { dp[num][d] += dp[num - 1][d + 1]; } if (d) sum[num] += dp[num][d]; } if (sum[num] >= k) break; } string ret = ""; int cnt = sum[num - 1]; int prev = 0; for (int d = 1; d <= 9; d++) { if (cnt + dp[num][d] >= k) { prev = d; ret += '0' + d; break; } else cnt += dp[num][d]; } num--; while (num) { for (int d = prev - 1; d <= prev + 1; d++) { if (d >= 0 && d <= 9) { if (cnt + dp[num][d] >= k) { prev = d; ret += '0' + d; break; } else { cnt += dp[num][d]; } } } num--; } cout << ret << endl; }
insert
21
21
21
25
0
p02720
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll k; set<string> st; int main() { io(); cin >> k; queue<string> q; rep(i, 1, 9) q.push(to_string(i)); vector<ll> vec; while (st.size() <= 2e5) { string top = q.front(); q.pop(); st.insert(top); if (top.back() != '9' && top.back() != '0') { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); ch += 2; q.push(top + ch); } else if (top.back() == '0') { char ch = top.back(); ++ch; q.push(top + top.back()); q.push(top + ch); } else { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); } } for (auto i : st) { // cout << i << '\n'; // ll num = stoi(i); vec.emplace_back((ll)stoi(i)); } sort(vec.begin(), vec.end()); // for (auto i : vec) cout << i << '\n'; cout << vec[k - 1]; }
#define _CRT_SECURE_NO_WARNINGS #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> #define rep(i, a, b) for (long long i = a; i <= b; ++i) #define mp make_pair #define ll long long #define SIZE 1005 using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll k; set<string> st; int main() { io(); cin >> k; queue<string> q; rep(i, 1, 9) q.push(to_string(i)); vector<ll> vec; while (st.size() <= 2e5) { string top = q.front(); q.pop(); st.insert(top); if (top.back() != '9' && top.back() != '0') { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); ch += 2; q.push(top + ch); } else if (top.back() == '0') { char ch = top.back(); ++ch; q.push(top + top.back()); q.push(top + ch); } else { char ch = top.back(); --ch; q.push(top + ch); q.push(top + top.back()); } } for (auto i : st) { // cout << i << '\n'; // ll num = stoi(i); vec.emplace_back((ll)stoll(i)); } sort(vec.begin(), vec.end()); // for (auto i : vec) cout << i << '\n'; cout << vec[k - 1]; }
replace
50
51
50
51
-6
terminate called after throwing an instance of 'std::out_of_range' what(): stoi
p02720
C++
Runtime Error
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long long ll; int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); queue<ll> numbers; for (ll i = 1; i <= 9; i++) numbers.push(i); ll k; cin >> k; while (k > 1) { // cout<<numbers.front()<<endl; ll curr = numbers.front(); numbers.pop(); if (curr % 10 != 0) numbers.push((curr * 10 + ((curr % 10) - 1))); numbers.push((curr * 10 + ((curr % 10)))); if (curr % 10 != 9) numbers.push((curr * 10 + ((curr % 10) + 1))); k--; } cout << numbers.front() << endl; return 0; }
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); queue<ll> numbers; for (ll i = 1; i <= 9; i++) numbers.push(i); ll k; cin >> k; while (k > 1) { // cout<<numbers.front()<<endl; ll curr = numbers.front(); numbers.pop(); if (curr % 10 != 0) numbers.push((curr * 10 + ((curr % 10) - 1))); numbers.push((curr * 10 + ((curr % 10)))); if (curr % 10 != 9) numbers.push((curr * 10 + ((curr % 10) + 1))); k--; } cout << numbers.front() << endl; return 0; }
delete
6
13
6
6
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) int main() { int K; cin >> K; vector<ll> lun(K + 3); rep1(i, 10) { lun[i] = i; } int i = 1, j = 10; while (j <= K) { int r = lun[i] % 10; ll x10 = lun[i] * 10; if (r != 0) lun[j++] = x10 + r - 1; lun[j++] = x10 + r; if (r != 9) lun[j++] = x10 + r + 1; i++; } cout << lun[K] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) int main() { int K; cin >> K; vector<ll> lun(max(11, K + 3)); rep1(i, 10) { lun[i] = i; } int i = 1, j = 10; while (j <= K) { int r = lun[i] % 10; ll x10 = lun[i] * 10; if (r != 0) lun[j++] = x10 + r - 1; lun[j++] = x10 + r; if (r != 9) lun[j++] = x10 + r + 1; i++; } cout << lun[K] << endl; }
replace
11
12
11
12
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int k, i = -1; vector<long long> vec = {}; void dfs(long long x, int a) { vec.push_back(x); if (x > 10000000) return; if (x == 0) { for (int j = 1; j < 10; j++) { dfs(j, j); } } else { if (a != 0 && a != 9) { dfs(10 * x + a - 1, a - 1); dfs(10 * x + a, a); dfs(10 * x + a + 1, a + 1); } if (a == 0) { dfs(10 * x + 0, 0); dfs(10 * x + 1, 1); } if (a == 9) { dfs(10 * x + 8, 8); dfs(10 * x + 9, 9); } } } int main() { cin >> k; dfs(0, 0); sort(vec.begin(), vec.end()); cout << vec[k] << endl; }
#include <bits/stdc++.h> using namespace std; int k, i = -1; vector<long long> vec = {}; void dfs(long long x, int a) { vec.push_back(x); if (x > 1000000000) return; if (x == 0) { for (int j = 1; j < 10; j++) { dfs(j, j); } } else { if (a != 0 && a != 9) { dfs(10 * x + a - 1, a - 1); dfs(10 * x + a, a); dfs(10 * x + a + 1, a + 1); } if (a == 0) { dfs(10 * x + 0, 0); dfs(10 * x + 1, 1); } if (a == 9) { dfs(10 * x + 8, 8); dfs(10 * x + 9, 9); } } } int main() { cin >> k; dfs(0, 0); sort(vec.begin(), vec.end()); cout << vec[k] << endl; }
replace
6
7
6
7
0
p02720
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; #define bay_bay return 0; #define fori(n) for (int i = 0; i < n; ++i) #define for1(n) for (int i = 1; i <= n; i += 3) #define all(v) ((v).begin()), ((v).end()) #define sz(v) v.size() #define endl "\n" constexpr auto EPS = 1e-9; #define ff fflush(stdout); clock_t T; #define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl void GOAT() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("output.txt", "w", stdout); #else #endif } ll m; ll a[1000005]; int pos = 0; void solve(ll x) { if (x > 1e10) return; pos++; a[pos] = x; int last = x % 10; if (last == 0) { solve(x * 10 + 0); solve(x * 10 + 1); } else if (last == 9) { solve(x * 10 + 8); solve(x * 10 + 9); } else { solve(x * 10 + last - 1); solve(x * 10 + last); solve(x * 10 + last + 1); } } int main() { GOAT(); cin >> m; for (ll i = 1; i <= 9; i++) solve(i); sort(a, a + pos + 1); cout << a[m] << endl; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; #define bay_bay return 0; #define fori(n) for (int i = 0; i < n; ++i) #define for1(n) for (int i = 1; i <= n; i += 3) #define all(v) ((v).begin()), ((v).end()) #define sz(v) v.size() #define endl "\n" constexpr auto EPS = 1e-9; #define ff fflush(stdout); clock_t T; #define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl void GOAT() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("output.txt", "w", stdout); #else #endif } ll m; ll a[1000005]; int pos = 0; void solve(ll x) { if (x > 1e10) return; pos++; a[pos] = x; int last = x % 10; if (last == 0) { solve(x * 10 + 0); solve(x * 10 + 1); } else if (last == 9) { solve(x * 10 + 8); solve(x * 10 + 9); } else { solve(x * 10 + last - 1); solve(x * 10 + last); solve(x * 10 + last + 1); } } int main() { // GOAT(); cin >> m; for (ll i = 1; i <= 9; i++) solve(i); sort(a, a + pos + 1); cout << a[m] << endl; }
replace
48
49
48
49
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for (int i = 0; i < int(n); i++) #define fore(i, l, r) for (int i = int(l); i < int(r); i++) #define pb push_back #define deb(x) cout << #x << " " << x << endl; #define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define deb3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define all(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> pii; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; } template <typename T> void print(T v, bool show_index = false) { int w = 2; if (show_index) { for (int i = 0; i < v.size(); i++) cout << setw(w) << i << " "; cout << endl; } for (auto i = v.begin(); i != v.end(); i++) cout << setw(w) << *i << " "; cout << endl; } template <typename T> void print_vv(T v) { if (v.size() == 0) { cout << "Empty" << endl; return; } int w = 3; cout << setw(w) << " "; for (int j = 0; j < v[0].size(); j++) cout << setw(w) << j << " "; cout << endl; for (auto i = 0; i < v.size(); i++) { cout << i << " {"; for (auto j = 0; j != v[i].size(); j++) { cout << setw(w) << v[i][j] << ","; } cout << "}," << endl; } cout << endl; } template <class T, class U> void print_m(map<T, U> m, int w = 3) { if (m.empty()) { cout << "Empty" << endl; return; } for (auto x : m) cout << "(" << x.first << ": " << x.second << ")," << endl; cout << endl; } int main() { int k; while (cin >> k) { vector<string> a = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}; int sz = a.size(); int i = 0; while (sz + 1 < k) { string top = a[i]; int bk = top.back() - '0'; int l = bk - 1; int r = bk + 1; if (bk == 0) l = 0; if (bk == 9) r = 9; for (int j = l; j <= r; ++j) { string ntop = top + to_string(j); a.push_back(ntop); ++sz; } ++i; } // print(a); cout << a[k - 1] << endl; cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for (int i = 0; i < int(n); i++) #define fore(i, l, r) for (int i = int(l); i < int(r); i++) #define pb push_back #define deb(x) cout << #x << " " << x << endl; #define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define deb3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define all(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> pii; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; } template <typename T> void print(T v, bool show_index = false) { int w = 2; if (show_index) { for (int i = 0; i < v.size(); i++) cout << setw(w) << i << " "; cout << endl; } for (auto i = v.begin(); i != v.end(); i++) cout << setw(w) << *i << " "; cout << endl; } template <typename T> void print_vv(T v) { if (v.size() == 0) { cout << "Empty" << endl; return; } int w = 3; cout << setw(w) << " "; for (int j = 0; j < v[0].size(); j++) cout << setw(w) << j << " "; cout << endl; for (auto i = 0; i < v.size(); i++) { cout << i << " {"; for (auto j = 0; j != v[i].size(); j++) { cout << setw(w) << v[i][j] << ","; } cout << "}," << endl; } cout << endl; } template <class T, class U> void print_m(map<T, U> m, int w = 3) { if (m.empty()) { cout << "Empty" << endl; return; } for (auto x : m) cout << "(" << x.first << ": " << x.second << ")," << endl; cout << endl; } int main() { int k; while (cin >> k) { vector<string> a = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}; int sz = a.size(); int i = 0; while (sz < k) { string top = a[i]; int bk = top.back() - '0'; int l = bk - 1; int r = bk + 1; if (bk == 0) l = 0; if (bk == 9) r = 9; for (int j = l; j <= r; ++j) { string ntop = top + to_string(j); a.push_back(ntop); ++sz; } ++i; } // print(a); cout << a[k - 1] << endl; cout << endl; } }
replace
83
84
83
84
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const long long MOD = 1000000007; const long long INF = 1LL << 60; const int INT_INF = 1000000000; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int K; cin >> K; queue<ll> que; for (int i = 1; i < 10; i++) que.push(i); for (int i = 0; i < K - 1; i++) { ll s = que.front(); que.pop(); for (int j = -1; j <= 1; j++) { ll add = (s % 10) + j; if (add <= 0 && add >= 9) que.push(s * 10 + add); } } cout << que.front() << endl; return 0; } // K番目に小さいものを求めよという問題でpriority_queueが使える問題は多い.まず,priority_queueに1から9をpushする.以下の操作をK回繰り返す. // キューの先頭を取り出す.(sとする) // sの一の位がdであるとき // d > 0ならキューに10v + (d - 1)をpush // キューに10v + dをpush // d < 9ならキューに10v + (d + 1)をpush // キューにpushされる値は,時系列にそって単調増加であるためpriority_queueではなくqueueでかまわない // これらの操作はBFSと見なすことが出来る.
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const long long MOD = 1000000007; const long long INF = 1LL << 60; const int INT_INF = 1000000000; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int K; cin >> K; queue<ll> que; for (int i = 1; i < 10; i++) que.push(i); for (int i = 0; i < K - 1; i++) { ll s = que.front(); que.pop(); for (int j = -1; j <= 1; j++) { ll add = (s % 10) + j; if (add >= 0 && add <= 9) que.push(s * 10 + add); } } cout << que.front() << endl; return 0; } // K番目に小さいものを求めよという問題でpriority_queueが使える問題は多い.まず,priority_queueに1から9をpushする.以下の操作をK回繰り返す. // キューの先頭を取り出す.(sとする) // sの一の位がdであるとき // d > 0ならキューに10v + (d - 1)をpush // キューに10v + dをpush // d < 9ならキューに10v + (d + 1)をpush // キューにpushされる値は,時系列にそって単調増加であるためpriority_queueではなくqueueでかまわない // これらの操作はBFSと見なすことが出来る.
replace
27
28
27
28
0
p02720
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; long long arr[100001]; int ind1, ind2; ind1 = 0; ind2 = 1; for (int i = 1; i < 10; i++) { arr[i] = i; ind1++; } int cur = ind1; for (int j = 0; j < 8; j++) { for (int i = ind2; i <= ind1; i++) { int a = arr[i] % 10; if (a != 0) { arr[++cur] = arr[i] * 10 + a - 1; } arr[++cur] = arr[i] * 10 + a; if (a != 9) { arr[++cur] = arr[i] * 10 + a + 1; } } ind2 = ind1 + 1; ind1 = cur; } for (int i = ind2; i <= ind1 && cur < 100001; i++) { int a = arr[i] % 10; if (a != 0) { arr[++cur] = arr[i] * 10 + a - 1; } arr[++cur] = arr[i] * 10 + a; if (a != 9) { arr[++cur] = arr[i] * 10 + a + 1; } } // for(int i=1;i<20;i++)cout<<arr[i]<<endl; // cout<<n<<endl; cout << arr[n] << endl; return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; long long arr[100001]; int ind1, ind2; ind1 = 0; ind2 = 1; for (int i = 1; i < 10; i++) { arr[i] = i; ind1++; } int cur = ind1; for (int j = 0; j < 8; j++) { for (int i = ind2; i <= ind1; i++) { int a = arr[i] % 10; if (a != 0) { arr[++cur] = arr[i] * 10 + a - 1; } arr[++cur] = arr[i] * 10 + a; if (a != 9) { arr[++cur] = arr[i] * 10 + a + 1; } } ind2 = ind1 + 1; ind1 = cur; } for (int i = ind2; i <= ind1 && cur < 100000; i++) { int a = arr[i] % 10; if (a != 0) { arr[++cur] = arr[i] * 10 + a - 1; } arr[++cur] = arr[i] * 10 + a; if (a != 9) { arr[++cur] = arr[i] * 10 + a + 1; } } // for(int i=1;i<20;i++)cout<<arr[i]<<endl; // cout<<n<<endl; cout << arr[n] << endl; return 0; }
replace
36
37
36
37
-6
*** stack smashing detected ***: terminated
p02720
C++
Runtime Error
#include <deque> #include <iostream> #include <string> #include <vector> using namespace std; int main() { long long K; cin >> K; deque<long long> d; if (K <= 10) return K; // init for (int i = 1; i <= 9; ++i) { d.emplace_back(i); } long long cnt = 0; while (true) { cnt++; if (cnt == K) break; long long f = d.front(); d.pop_front(); long long new_num = 10 * f + (f % 10); if (new_num % 10 != 0) { d.emplace_back(new_num - 1); } d.emplace_back(new_num); if (new_num % 10 != 9) { d.emplace_back(new_num + 1); } } cout << d.front() << endl; }
#include <deque> #include <iostream> #include <string> #include <vector> using namespace std; int main() { long long K; cin >> K; deque<long long> d; // init for (int i = 1; i <= 9; ++i) { d.emplace_back(i); } long long cnt = 0; while (true) { cnt++; if (cnt == K) break; long long f = d.front(); d.pop_front(); long long new_num = 10 * f + (f % 10); if (new_num % 10 != 0) { d.emplace_back(new_num - 1); } d.emplace_back(new_num); if (new_num % 10 != 9) { d.emplace_back(new_num + 1); } } cout << d.front() << endl; }
delete
11
14
11
11
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<long long> v; void dfs(ll x, ll num, ll st, ll cc) { if (v.size() > 100050) return; if (num == 0) num += x; else { num *= 10; num += x; } if (cc > st) return; if (cc == st) { v.push_back(num); return; } if (x - 1 >= 0) dfs(x - 1, num, st, cc + 1); if (x + 1 <= 9) dfs(x + 1, num, st, cc + 1); dfs(x, num, st, cc + 1); return; } int main() { ll k; cin >> k; for (int i = 1; i <= 8; i++) { for (int j = 1; j <= 9; j++) { dfs(j, 0, i, 1); } } sort(v.begin(), v.end()); cout << v[k - 1] << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<long long> v; void dfs(ll x, ll num, ll st, ll cc) { if (v.size() > 100050) return; if (num == 0) num += x; else { num *= 10; num += x; } if (cc > st) return; if (cc == st) { v.push_back(num); return; } if (x - 1 >= 0) dfs(x - 1, num, st, cc + 1); if (x + 1 <= 9) dfs(x + 1, num, st, cc + 1); dfs(x, num, st, cc + 1); return; } int main() { ll k; cin >> k; for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 9; j++) { dfs(j, 0, i, 1); } } sort(v.begin(), v.end()); cout << v[k - 1] << "\n"; }
replace
32
33
32
33
0
p02720
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = 1; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(a) (a).begin(), (a).end() typedef pair<int, int> P; typedef long long ll; vector<ll> lun; void dfs(int d, ll now) { lun.push_back(now); if (d == 10) return; for (int i = -1; i <= 1; i++) { int add = now % 10 + i; if (add >= 0 && add <= 9) dfs(d + 1, now * 10 + add); } } int main() { int k; cin >> k; vector<ll> lun; rep(i, 9) dfs(1, i + 1); sort(all(lun)); dunk(lun[k - 1]); return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = 1; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(a) (a).begin(), (a).end() typedef pair<int, int> P; typedef long long ll; vector<ll> lun; void dfs(int d, ll now) { lun.push_back(now); if (d == 10) return; for (int i = -1; i <= 1; i++) { int add = now % 10 + i; if (add >= 0 && add <= 9) dfs(d + 1, now * 10 + add); } } int main() { int k; cin >> k; rep(i, 9) dfs(1, i + 1); sort(all(lun)); dunk(lun[k - 1]); return 0; }
delete
28
29
28
28
-6
/usr/include/c++/12/debug/vector:442: In function: std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, _Allocator>::operator[](size_type) [with _Tp = long long int; _Allocator = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int] Error: attempt to subscript container with out-of-bounds index 14, but container only holds 0 elements. Objects involved in the operation: sequence "this" @ 0x7ffcc21a1030 { type = std::debug::vector<long long, std::allocator<long long> >; }
p02720
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> using namespace std; typedef long long ll; const int INF = 100; typedef pair<int, int> P; const int ld = 10; int main() { int n; cin >> n; int a[ld]; fill(a, a + ld, 0); // cout<<n<<endl; int i = 0; while (i < n) { // cout<<n<<" "<<endl; int jj = -1; for (int j = ld - 1; j >= 0; j--) { if (a[j] != 9) { a[j]++; jj = j; break; } } if (jj == -1) return 0; for (int j = jj + 1; j < n; j++) { a[j] = max(0, a[j - 1] - (j - jj)); } bool ng = false; for (int j = 1, st = 0; j < ld; j++) { if (a[j - 1] != 0) st = 1; if (st && abs(a[j - 1] - a[j]) > 1) { ng = true; break; } } if (!ng) i++; } for (int i = 0, st = 0; i < ld; i++) { if (a[i] != 0) st++; if (st) cout << a[i]; } cout << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> using namespace std; typedef long long ll; const int INF = 100; typedef pair<int, int> P; const int ld = 10; int main() { int n; cin >> n; int a[ld]; fill(a, a + ld, 0); // cout<<n<<endl; int i = 0; while (i < n) { // cout<<n<<" "<<endl; int jj = -1; for (int j = ld - 1; j >= 0; j--) { if (a[j] != 9) { a[j]++; jj = j; break; } } if (jj == -1) return 0; for (int j = jj + 1; j < ld; j++) { a[j] = max(0, a[j - 1] - (j - jj)); } bool ng = false; for (int j = 1, st = 0; j < ld; j++) { if (a[j - 1] != 0) st = 1; if (st && abs(a[j - 1] - a[j]) > 1) { ng = true; break; } } if (!ng) i++; } for (int i = 0, st = 0; i < ld; i++) { if (a[i] != 0) st++; if (st) cout << a[i]; } cout << endl; }
replace
30
31
30
31
-6
*** stack smashing detected ***: terminated
p02720
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long int ll; typedef long double ld; #define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define INF (1LL << 62) #define PI (acos(-1)) #define PRINT(x) cout << x << endl ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll countDigit(ll n) { return floor(log10(n) + 1); } typedef pair<ll, ll> P; static const ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " "; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &m) { for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; return os; } void dfs(ll num, vector<ll> &v) { if (num > 3234566667) { return; } else { v.push_back(num); if (num % 10 == 0) { dfs(num * 10, v); dfs(num * 10 + 1, v); } else if (num % 10 == 9) { dfs(num * 10 + 9, v); dfs(num * 10 + 8, v); } else { dfs(num * 10 + num % 10, v); dfs(num * 10 + (num % 10) + 1, v); dfs(num * 10 + (num % 10) - 1, v); } } return; } int main() { ll K; cin >> K; vector<ll> s; if (K < 10) { PRINT(K); } else { FOR(i, 1, 10) { dfs(i, s); } } sort(ALL(s)); PRINT(s[K - 1]); return 0; }
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long int ll; typedef long double ld; #define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define INF (1LL << 62) #define PI (acos(-1)) #define PRINT(x) cout << x << endl ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll countDigit(ll n) { return floor(log10(n) + 1); } typedef pair<ll, ll> P; static const ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " "; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &m) { for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; return os; } void dfs(ll num, vector<ll> &v) { if (num > 3234566667) { return; } else { v.push_back(num); if (num % 10 == 0) { dfs(num * 10, v); dfs(num * 10 + 1, v); } else if (num % 10 == 9) { dfs(num * 10 + 9, v); dfs(num * 10 + 8, v); } else { dfs(num * 10 + num % 10, v); dfs(num * 10 + (num % 10) + 1, v); dfs(num * 10 + (num % 10) - 1, v); } } return; } int main() { ll K; cin >> K; vector<ll> s; if (K < 10) { PRINT(K); return 0; } else { FOR(i, 1, 10) { dfs(i, s); } } sort(ALL(s)); PRINT(s[K - 1]); return 0; }
insert
61
61
61
62
0
p02720
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-9) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < n; i++) int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll beki(ll a, ll b) { ll tmp = 1; REP(i, b) tmp *= a; return tmp; } ll K; queue<ll> que; ll ans[100010]; ll num = 0; ll nowNum = 0; int main() { cin >> K; // queに1の桁をつめる for (ll i = 1; i <= 9; i++) { que.push(i); ans[num] = i; num++; nowNum++; } // queにつまってるやつまでのをやるまでやる while (true) { // n回めはn桁のものをn+1桁にする for (ll i = 0; i < nowNum; i++) { for (ll j = -1; j <= 1; j++) { // ここで0、1、2とかを後ろにつける ll a = que.front(); ll b = a % 10; if (b == 0 && j == -1) continue; if (b == 9 && j == 1) continue; que.push(a * 10 + b + j); ans[num] = a * 10 + b + j; num++; if (num == K) { cout << ans[K - 1] << endl; // REP(i, K) { // cout << ans[i] << endl; // } return 0; } } que.pop(); } // 最後にもどす nowNum = num - nowNum; } }
#include <algorithm> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-9) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < n; i++) int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll beki(ll a, ll b) { ll tmp = 1; REP(i, b) tmp *= a; return tmp; } ll K; queue<ll> que; ll ans[100010]; ll num = 0; ll nowNum = 0; int main() { cin >> K; if (K <= 9) { cout << K << endl; return 0; } // queに1の桁をつめる for (ll i = 1; i <= 9; i++) { que.push(i); ans[num] = i; num++; nowNum++; } // queにつまってるやつまでのをやるまでやる while (true) { // n回めはn桁のものをn+1桁にする for (ll i = 0; i < nowNum; i++) { for (ll j = -1; j <= 1; j++) { // ここで0、1、2とかを後ろにつける ll a = que.front(); ll b = a % 10; if (b == 0 && j == -1) continue; if (b == 9 && j == 1) continue; que.push(a * 10 + b + j); ans[num] = a * 10 + b + j; num++; if (num == K) { cout << ans[K - 1] << endl; // REP(i, K) { // cout << ans[i] << endl; // } return 0; } } que.pop(); } // 最後にもどす nowNum = num - nowNum; } }
replace
43
44
43
47
0
p02721
C++
Time Limit Exceeded
// #include <bits/stdc++.h> #include <algorithm> // sort, min/max, upper/lower_bound, transform, count/copy_if #include <array> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> // setprecision #include <iostream> // cin, cout, string #include <iterator> #include <list> #include <map> #include <numeric> // accumulate, itoa #include <queue> // priority_queue #include <random> // mt19937 #include <ratio> #include <set> // multiset #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> // pair, swap #include <vector> using namespace std; // #define int long long using i64 = int64_t; using ll = long long; using ld = long double; template <typename T> using vec = vector<T>; template <typename T> using mat = vec<vec<T>>; template <typename T> using dic = unordered_map<string, T>; template <typename T> using pqg = priority_queue<T, vector<T>, greater<T>>; // dijkstra // template<typename T, typename U> using P = pair<T, U>; // template<typename... Args> using func = function<Args...>; // template<typename T> using pq = priority_queue<T>; using pii = pair<int, int>; using ppi = pair<pii, int>; using pip = pair<int, pii>; using ppp = pair<pii, pii>; using vi = vec<int>; using mi = mat<int>; // Graph using vp = vec<pii>; constexpr int IINF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; // constexpr int INF = sizeof(int) == sizeof(long long) ? LINF : IINF; constexpr long long MOD = 1e9 + 7; #define _overload(_1, _2, _3, name, ...) name #define _rep1(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i) #define _rep2(i, n) _rep1(i, 0, n) #define _rep3(n) _rep2(i, n) #define rep(...) _overload(__VA_ARGS__, _rep1, _rep2, _rep3)(__VA_ARGS__) #define _rrep1(i, a, b) for (int i = (b)-1, _##i = (a); i >= _##i; --i) #define _rrep2(i, n) _rrep1(i, 0, n) #define _rrep3(n) _rrep2(i, n) #define rrep(...) _overload(__VA_ARGS__, _rrep1, _rrep2, _rrep3)(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define each2(i, a) for (const auto &i : a) #define pb push_back // emplace_back(*) == push_back(constructor(*)) #define eb emplace_back #define pob pop_back #define pf push_front #define pof pop_front #define np next_permutation #define pp prev_permutation // make_pair(A, B) == pair<T, U>(A, B) #define mp make_pair // mt(...) == tie(...) #define mt make_tuple #define ft first #define sd second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define sz(a) (int)(a).size() #define rev(a) reverse(all(a)) #define rs(a, l) (a).resize(l) #define upper(s) transform(all(s), (s).begin(), topper) #define lower(s) transform(all(s), (s).begin(), tolower) #define sum(a) accumulate(all(a), 0) #define elif else if #define unless(a) if (!(a)) #define qt(a) #a #define endl '\n' #define dec(n) fixed << setprecision(n) #define zfl(n) setfill(‘0’) << setw(n) template <typename T = int, T l = 0, T r = (T)MOD> auto rnd = bind(uniform_int_distribution<T>(l, r), mt19937(chrono::steady_clock::now().time_since_epoch().count())); template <typename T> inline constexpr T gcd(T a, T b) { if (a == 0 || b == 0) return 0; while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline constexpr T extgcd2(T a, T b, T &x, T &y) { x = 1; y = 0; while (b) { T t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return a; } template <typename T> inline constexpr T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> inline constexpr bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline constexpr bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { is >> p.first; is >> p.second; return is; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << p.first << " " << p.second; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << (i + 1 != (int)v.size() ? " " : ""); return os; } #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg> void __f(const char *name, const Arg &arg) { cerr << name << " : " << arg << endl; } template <typename Arg, typename... Args> void __f(const char *names, const Arg &arg, const Args &...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg << " | "; __f(comma + 1, args...); } inline auto yes(const bool &c) { return c ? "yes" : "no"; } inline auto Yes(const bool &c) { return c ? "Yes" : "No"; } inline auto YES(const bool &c) { return c ? "YES" : "NO"; } inline auto Possible(const bool &c) { return c ? "Possible" : "Impossible"; } inline auto POSSIBLE(const bool &c) { return c ? "POSSIBLE" : "IMPOSSIBLE"; } constexpr int lim = 100007; // 10^5+7 ll n, k, c; string s; bool check(int i) { if (s.at(i) == 'x') return false; int j = 0; int w = k; while (j < n) { if (s[j] == 'o' && i != j) { // cout << i << j << endl; j += c; w -= 1; if (w == 0) return false; } j++; } return true; } signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> k >> c >> s; rep(n) { if (check(i)) { cout << i + 1 << endl; } } return 0; }
// #include <bits/stdc++.h> #include <algorithm> // sort, min/max, upper/lower_bound, transform, count/copy_if #include <array> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> // setprecision #include <iostream> // cin, cout, string #include <iterator> #include <list> #include <map> #include <numeric> // accumulate, itoa #include <queue> // priority_queue #include <random> // mt19937 #include <ratio> #include <set> // multiset #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> // pair, swap #include <vector> using namespace std; // #define int long long using i64 = int64_t; using ll = long long; using ld = long double; template <typename T> using vec = vector<T>; template <typename T> using mat = vec<vec<T>>; template <typename T> using dic = unordered_map<string, T>; template <typename T> using pqg = priority_queue<T, vector<T>, greater<T>>; // dijkstra // template<typename T, typename U> using P = pair<T, U>; // template<typename... Args> using func = function<Args...>; // template<typename T> using pq = priority_queue<T>; using pii = pair<int, int>; using ppi = pair<pii, int>; using pip = pair<int, pii>; using ppp = pair<pii, pii>; using vi = vec<int>; using mi = mat<int>; // Graph using vp = vec<pii>; constexpr int IINF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; // constexpr int INF = sizeof(int) == sizeof(long long) ? LINF : IINF; constexpr long long MOD = 1e9 + 7; #define _overload(_1, _2, _3, name, ...) name #define _rep1(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i) #define _rep2(i, n) _rep1(i, 0, n) #define _rep3(n) _rep2(i, n) #define rep(...) _overload(__VA_ARGS__, _rep1, _rep2, _rep3)(__VA_ARGS__) #define _rrep1(i, a, b) for (int i = (b)-1, _##i = (a); i >= _##i; --i) #define _rrep2(i, n) _rrep1(i, 0, n) #define _rrep3(n) _rrep2(i, n) #define rrep(...) _overload(__VA_ARGS__, _rrep1, _rrep2, _rrep3)(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define each2(i, a) for (const auto &i : a) #define pb push_back // emplace_back(*) == push_back(constructor(*)) #define eb emplace_back #define pob pop_back #define pf push_front #define pof pop_front #define np next_permutation #define pp prev_permutation // make_pair(A, B) == pair<T, U>(A, B) #define mp make_pair // mt(...) == tie(...) #define mt make_tuple #define ft first #define sd second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define sz(a) (int)(a).size() #define rev(a) reverse(all(a)) #define rs(a, l) (a).resize(l) #define upper(s) transform(all(s), (s).begin(), topper) #define lower(s) transform(all(s), (s).begin(), tolower) #define sum(a) accumulate(all(a), 0) #define elif else if #define unless(a) if (!(a)) #define qt(a) #a #define endl '\n' #define dec(n) fixed << setprecision(n) #define zfl(n) setfill(‘0’) << setw(n) template <typename T = int, T l = 0, T r = (T)MOD> auto rnd = bind(uniform_int_distribution<T>(l, r), mt19937(chrono::steady_clock::now().time_since_epoch().count())); template <typename T> inline constexpr T gcd(T a, T b) { if (a == 0 || b == 0) return 0; while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline constexpr T extgcd2(T a, T b, T &x, T &y) { x = 1; y = 0; while (b) { T t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return a; } template <typename T> inline constexpr T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> inline constexpr bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline constexpr bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { is >> p.first; is >> p.second; return is; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << p.first << " " << p.second; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) cout << v[i] << (i + 1 != (int)v.size() ? " " : ""); return os; } #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg> void __f(const char *name, const Arg &arg) { cerr << name << " : " << arg << endl; } template <typename Arg, typename... Args> void __f(const char *names, const Arg &arg, const Args &...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg << " | "; __f(comma + 1, args...); } inline auto yes(const bool &c) { return c ? "yes" : "no"; } inline auto Yes(const bool &c) { return c ? "Yes" : "No"; } inline auto YES(const bool &c) { return c ? "YES" : "NO"; } inline auto Possible(const bool &c) { return c ? "Possible" : "Impossible"; } inline auto POSSIBLE(const bool &c) { return c ? "POSSIBLE" : "IMPOSSIBLE"; } constexpr int lim = 100007; // 10^5+7 ll n, k, c; string s; bool check(int i) { if (s.at(i) == 'x') return false; int j = 0; int w = k; while (j < n) { if (s[j] == 'o' && i != j) { // cout << i << j << endl; j += c; w -= 1; if (w == 0) return false; } j++; } return true; } signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> k >> c >> s; int i = 0; int j = 0; vec<int> l; vec<int> r; l.resize(n); r.resize(n); while (i < n && j < k) { if (s.at(i) == 'o') { l.at(j) = i; j += 1; i += c + 1; } else { i += 1; } } i = n - 1; j = k - 1; while (i >= 0 && j >= 0) { if (s.at(i) == 'o') { r.at(j) = i; j -= 1; i -= c + 1; } else { i -= 1; } } rep(k) { // cout << r.at(i) << " " << l.at(i) << endl; if (r.at(i) == l.at(i)) { cout << r.at(i) + 1 << endl; } } return 0; }
replace
223
226
223
255
TLE
p02721
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define M 100005 int sl[M], mp[M], vs[M]; char S[M]; inline void rd(int &l) { l = 0; int f = 0; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { l = l * 10 + ch - '0'; ch = getchar(); } if (f) l = -l; } int main() { int N, K, C, tp = 1; rd(N); rd(K); rd(C); scanf("%s", S + 1); for (int i = 1; i <= N; ++i) mp[i] = (S[i] == 'x'); for (int i = 1; i <= K; ++i) { while (tp <= N && mp[tp]) ++tp; sl[i] = tp; tp += C + 1; } if (K && sl[K]) { tp = N; for (int i = K; i; --i) { while (tp && mp[tp]) --tp; vs[i] = tp; // printf("%d %d\n",sl[i],vs[i]); tp -= C + 1; } for (int i = 1; i <= K; ++i) if (vs[i] == sl[i]) printf("%d\n", vs[i]); } // getchar(); // getchar(); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define M 200005 int sl[M], mp[M], vs[M]; char S[M]; inline void rd(int &l) { l = 0; int f = 0; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { l = l * 10 + ch - '0'; ch = getchar(); } if (f) l = -l; } int main() { int N, K, C, tp = 1; rd(N); rd(K); rd(C); scanf("%s", S + 1); for (int i = 1; i <= N; ++i) mp[i] = (S[i] == 'x'); for (int i = 1; i <= K; ++i) { while (tp <= N && mp[tp]) ++tp; sl[i] = tp; tp += C + 1; } if (K && sl[K]) { tp = N; for (int i = K; i; --i) { while (tp && mp[tp]) --tp; vs[i] = tp; // printf("%d %d\n",sl[i],vs[i]); tp -= C + 1; } for (int i = 1; i <= K; ++i) if (vs[i] == sl[i]) printf("%d\n", vs[i]); } // getchar(); // getchar(); return 0; }
replace
5
6
5
6
0
p02721
C++
Runtime Error
/*dismint|jjc*/ #include <bits/stdc++.h> using namespace std; #define forl(V, S, E) for (int V = S; V < E; V++) #define ford(V, S, E) for (int V = S; V >= E; V--) #define fore(E, X) for (auto &E : X) #define println(X) cout << X << endl #define printe(X) \ for (auto &E : X) \ cout << E << " "; \ cout << endl typedef unordered_map<int, unordered_set<int>> graph; typedef long long ll; int L[200001], R[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, c; string s; cin >> n >> k >> c >> s; int wd = 0, cd = 0; forl(i, 0, n) { if (cd) { cd--; continue; } if (s[i] != 'o') continue; L[wd++] = i; cd = c; } wd = k - 1, cd = 0; ford(i, n - 1, 0) { if (cd) { cd--; continue; } if (s[i] != 'o') continue; R[wd--] = i; cd = c; } vector<int> ans; forl(i, 0, k) { if (R[i] == L[i]) ans.push_back(R[i] + 1); } printe(ans); }
/*dismint|jjc*/ #include <bits/stdc++.h> using namespace std; #define forl(V, S, E) for (int V = S; V < E; V++) #define ford(V, S, E) for (int V = S; V >= E; V--) #define fore(E, X) for (auto &E : X) #define println(X) cout << X << endl #define printe(X) \ for (auto &E : X) \ cout << E << " "; \ cout << endl typedef unordered_map<int, unordered_set<int>> graph; typedef long long ll; int L[200001], R[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, c; string s; cin >> n >> k >> c >> s; int wd = 0, cd = 0; forl(i, 0, n) { if (cd) { cd--; continue; } if (s[i] != 'o') continue; L[wd++] = i; cd = c; } wd = k - 1, cd = 0; ford(i, n - 1, 0) { if (cd) { cd--; continue; } if (s[i] != 'o' or wd < 0) continue; R[wd--] = i; cd = c; } vector<int> ans; forl(i, 0, k) { if (R[i] == L[i]) ans.push_back(R[i] + 1); } printe(ans); }
replace
39
40
39
40
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrep(i, n) for (int(i) = ((n)-1); (i) >= 0; (i)--) #define itn int #define miele(v) min_element(v.begin(), v.end()) #define maele(v) max_element(v.begin(), v.end()) #define SUM(v) accumulate(v.begin(), v.end(), 0LL) #define lb(a, key) lower_bound(a.begin(), a.end(), key) #define ub(a, key) upper_bound(a.begin(), a.end(), key) #define COUNT(a, key) count(a.begin(), a.end(), key) #define BITCOUNT(x) __builtin_popcount(x) #define pb push_back #define all(x) (x).begin(), (x).end() #define F first #define S second using P = pair<int, int>; using WeightedGraph = vector<vector<P>>; using UnWeightedGraph = vector<vector<int>>; const long long INF = 1LL << 60; const int MOD = 1000000007; void YN(bool flg) { cout << (flg ? "YES" : "NO") << '\n'; } void Yn(bool flg) { cout << (flg ? "Yes" : "No") << '\n'; } void yn(bool flg) { cout << (flg ? "yes" : "no") << '\n'; } template <typename T> int getIndexOfLowerBound(vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <typename T> int getIndexOfUpperBound(vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p_var) { is >> p_var.first >> p_var.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> istream &operator>>(istream &is, vector<vector<T>> &df) { for (int i = 0; i < df.size(); i++) for (int j = 0; j < df[i].size(); j++) is >> df[i][j]; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { DUMPOUT << '{'; os << pair_var.first; DUMPOUT << ','; os << " " << pair_var.second; DUMPOUT << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { DUMPOUT << '['; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); DUMPOUT << ']'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &df) { for (auto &vec : df) os << vec; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { DUMPOUT << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { DUMPOUT << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } void print() { cout << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } void dump_func() { DUMPOUT << '#' << endl; } template <typename Head, typename... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> l(n + 2), r(n + 2); l[0] = -1, r[0] = -893; int mae = -INF; int cnt = 0; rep(i, n) { if (s[i] == 'x') continue; if (abs(mae - i) > c) { cnt++; l[cnt] = i; mae = i; } } dump(l); mae = INF; cnt = k; rrep(i, n) { if (s[i] == 'x') continue; if (abs(mae - i) > c) { r[cnt] = i; cnt--; mae = i; } } dump(r); rep(i, k + 1) { if (r[i] == l[i]) { print(r[i] + 1); } } }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrep(i, n) for (int(i) = ((n)-1); (i) >= 0; (i)--) #define itn int #define miele(v) min_element(v.begin(), v.end()) #define maele(v) max_element(v.begin(), v.end()) #define SUM(v) accumulate(v.begin(), v.end(), 0LL) #define lb(a, key) lower_bound(a.begin(), a.end(), key) #define ub(a, key) upper_bound(a.begin(), a.end(), key) #define COUNT(a, key) count(a.begin(), a.end(), key) #define BITCOUNT(x) __builtin_popcount(x) #define pb push_back #define all(x) (x).begin(), (x).end() #define F first #define S second using P = pair<int, int>; using WeightedGraph = vector<vector<P>>; using UnWeightedGraph = vector<vector<int>>; const long long INF = 1LL << 60; const int MOD = 1000000007; void YN(bool flg) { cout << (flg ? "YES" : "NO") << '\n'; } void Yn(bool flg) { cout << (flg ? "Yes" : "No") << '\n'; } void yn(bool flg) { cout << (flg ? "yes" : "no") << '\n'; } template <typename T> int getIndexOfLowerBound(vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <typename T> int getIndexOfUpperBound(vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p_var) { is >> p_var.first >> p_var.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> istream &operator>>(istream &is, vector<vector<T>> &df) { for (int i = 0; i < df.size(); i++) for (int j = 0; j < df[i].size(); j++) is >> df[i][j]; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { DUMPOUT << '{'; os << pair_var.first; DUMPOUT << ','; os << " " << pair_var.second; DUMPOUT << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { DUMPOUT << '['; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); DUMPOUT << ']'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &df) { for (auto &vec : df) os << vec; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { DUMPOUT << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { DUMPOUT << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } void print() { cout << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } void dump_func() { DUMPOUT << '#' << endl; } template <typename Head, typename... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> l(n + 2), r(n + 2); l[0] = -1, r[0] = -893; int mae = -INF; int cnt = 0; rep(i, n) { if (s[i] == 'x') continue; if (abs(mae - i) > c) { cnt++; l[cnt] = i; mae = i; } } dump(l); mae = INF; cnt = k; rrep(i, n) { if (s[i] == 'x') continue; if (abs(mae - i) > c) { if (cnt == -1) break; r[cnt] = i; cnt--; mae = i; } } dump(r); rep(i, k + 1) { if (r[i] == l[i]) { print(r[i] + 1); } } }
insert
163
163
163
165
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second // #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 100001; void pr(vector<int> v) { for (int x : v) { cout << x << " "; } cout << "\n"; } void solve() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> lf(n); vector<int> rt(n); int t = 1; int p = -MAX; for (int i = 0; i < n; i++) { if (s[i] == 'o') { int d = i - p; if (d > c) { lf[i] = t++; p = i; } if (t > k) break; } } reverse(s.begin(), s.end()); t = k; p = -MAX; for (int i = 0; i < n; i++) { if (s[i] == 'o') { int d = i - p; if (d > c) { rt[i] = t--; p = i; } // if(t > k) break; } } reverse(rt.begin(), rt.end()); int cnt = 0; for (int i = 0; i < n; i++) { if (rt[i] == lf[i] && rt[i] > 0) { cout << i + 1 << "\n"; } } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 100001; void pr(vector<int> v) { for (int x : v) { cout << x << " "; } cout << "\n"; } void solve() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> lf(n); vector<int> rt(n); int t = 1; int p = -MAX; for (int i = 0; i < n; i++) { if (s[i] == 'o') { int d = i - p; if (d > c) { lf[i] = t++; p = i; } if (t > k) break; } } reverse(s.begin(), s.end()); t = k; p = -MAX; for (int i = 0; i < n; i++) { if (s[i] == 'o') { int d = i - p; if (d > c) { rt[i] = t--; p = i; } // if(t > k) break; } } reverse(rt.begin(), rt.end()); int cnt = 0; for (int i = 0; i < n; i++) { if (rt[i] == lf[i] && rt[i] > 0) { cout << i + 1 << "\n"; } } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; while (t--) solve(); return 0; }
replace
7
8
7
8
0
p02721
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; char s[100010]; int a[100010], l[100010], r[100010], b[100010]; int n, k, c; int main() { scanf("%d%d%d", &n, &k, &c); scanf("%s", s); for (int i = 0; i < n; i++) { if (s[i] == 'x') a[i + 1] = 0; else a[i + 1] = 1; } for (int i = 1; i <= c + 1; i++) l[i] = a[i]; for (int i = c + 2; i <= n; i++) { l[i] = l[i - 1]; if (a[i] == 1) { l[i] = max(l[i], l[i - c - 1] + 1); } } int ans = l[n]; if (ans > k) return 0; for (int i = n; i >= n - c - 1 && i >= 1; i--) r[i] = ans; for (int i = n - c - 1; i >= 1; i--) { r[i] = r[i + 1]; if (a[i] == 1) { r[i] = min(r[i], r[i + c + 1] - 1); } } for (int i = 1; i <= n; i++) { if (l[i] == r[i]) { b[l[i]]++; } } for (int i = 1; i <= n; i++) { if (l[i] == r[i]) { if (b[l[i]] == 1) printf("%d\n", i); } } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; char s[200010]; int a[200010], l[200010], r[200010], b[200010]; int n, k, c; int main() { scanf("%d%d%d", &n, &k, &c); scanf("%s", s); for (int i = 0; i < n; i++) { if (s[i] == 'x') a[i + 1] = 0; else a[i + 1] = 1; } for (int i = 1; i <= c + 1; i++) l[i] = a[i]; for (int i = c + 2; i <= n; i++) { l[i] = l[i - 1]; if (a[i] == 1) { l[i] = max(l[i], l[i - c - 1] + 1); } } int ans = l[n]; if (ans > k) return 0; for (int i = n; i >= n - c - 1 && i >= 1; i--) r[i] = ans; for (int i = n - c - 1; i >= 1; i--) { r[i] = r[i + 1]; if (a[i] == 1) { r[i] = min(r[i], r[i + c + 1] - 1); } } for (int i = 1; i <= n; i++) { if (l[i] == r[i]) { b[l[i]]++; } } for (int i = 1; i <= n; i++) { if (l[i] == r[i]) { if (b[l[i]] == 1) printf("%d\n", i); } } return 0; }
replace
6
8
6
8
0
p02721
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn = 1e5 + 5; bool valid[maxn]; int l_minn[maxn], r_minn[maxn]; int main() { int n, k, c; scanf("%d%d%d", &n, &k, &c); char s; scanf("%c", &s); for (int i = 1; i <= n; i++) { scanf("%c", &s); valid[i] = (s == 'o'); } int cur = -c; for (int i = 1; i <= k; i++) { for (int j = cur + c + 1; j <= n; j++) if (valid[j]) { l_minn[i] = j; cur = j; break; } } reverse(valid + 1, valid + n + 1); cur = -c; for (int i = 1; i <= k; i++) { for (int j = cur + c + 1; j <= n; j++) if (valid[j]) { r_minn[i] = n + 1 - j; cur = j; break; } } reverse(r_minn + 1, r_minn + k + 1); for (int i = 1; i <= k; i++) if (l_minn[i] == r_minn[i] && l_minn[i]) printf("%d\n", l_minn[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn = 2e5 + 5; bool valid[maxn]; int l_minn[maxn], r_minn[maxn]; int main() { int n, k, c; scanf("%d%d%d", &n, &k, &c); char s; scanf("%c", &s); for (int i = 1; i <= n; i++) { scanf("%c", &s); valid[i] = (s == 'o'); } int cur = -c; for (int i = 1; i <= k; i++) { for (int j = cur + c + 1; j <= n; j++) if (valid[j]) { l_minn[i] = j; cur = j; break; } } reverse(valid + 1, valid + n + 1); cur = -c; for (int i = 1; i <= k; i++) { for (int j = cur + c + 1; j <= n; j++) if (valid[j]) { r_minn[i] = n + 1 - j; cur = j; break; } } reverse(r_minn + 1, r_minn + k + 1); for (int i = 1; i <= k; i++) if (l_minn[i] == r_minn[i] && l_minn[i]) printf("%d\n", l_minn[i]); return 0; }
replace
5
6
5
6
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define F first #define S second #define int long long #define lint long long #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5 + 5, MOD = 1e9 + 7; const lint INF = 1e18; lint _add(lint x, lint y) { lint ret = x + y; while (ret < 0LL) ret += MOD; return ret; } lint _mult(lint x, lint y) { x %= MOD; y %= MOD; lint ret = x * y; ret %= MOD; while (ret < 0LL) ret += MOD; return ret; } inline int modpow(lint base, int exp, int modulo) { base %= modulo; lint result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulo; base = (base * base) % modulo; exp >>= 1; } return result; } int n, k, c, suff[N]; string s; vi ans; signed main() { cin >> n >> k >> c; cin >> s; for (int i = n - 1; i >= n - 1 - c; i--) { int curr; if (s[i] == 'o') curr = 1; suff[i] = max(curr, suff[i + 1]); } for (int i = n - c - 2; i >= 0; i--) { int curr = 1 + suff[i + c + 1]; if (s[i] == 'x') curr = 0; suff[i] = max(suff[i + 1], curr); } if (suff[0] > k) { return 0; } int curr = 0, jmps = 0; while (jmps < k) { while (s[curr] == 'x') { curr++; } if (curr == n - 1) { ans.pb(curr + 1); } else if (suff[curr + 1] < suff[curr]) { ans.pb(curr + 1); } curr += c + 1; jmps++; } for (auto v : ans) { cout << v << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define F first #define S second #define int long long #define lint long long #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5 + 5, MOD = 1e9 + 7; const lint INF = 1e18; lint _add(lint x, lint y) { lint ret = x + y; while (ret < 0LL) ret += MOD; return ret; } lint _mult(lint x, lint y) { x %= MOD; y %= MOD; lint ret = x * y; ret %= MOD; while (ret < 0LL) ret += MOD; return ret; } inline int modpow(lint base, int exp, int modulo) { base %= modulo; lint result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulo; base = (base * base) % modulo; exp >>= 1; } return result; } int n, k, c, suff[N]; string s; vi ans; signed main() { cin >> n >> k >> c; cin >> s; for (int i = n - 1; i >= max(0LL, n - 1 - c); i--) { int curr; if (s[i] == 'o') curr = 1; suff[i] = max(curr, suff[i + 1]); } for (int i = n - c - 2; i >= 0; i--) { int curr = 1 + suff[i + c + 1]; if (s[i] == 'x') curr = 0; suff[i] = max(suff[i + 1], curr); } if (suff[0] > k) { return 0; } int curr = 0, jmps = 0; while (jmps < k) { while (s[curr] == 'x') { curr++; } if (curr == n - 1) { ans.pb(curr + 1); } else if (suff[curr + 1] < suff[curr]) { ans.pb(curr + 1); } curr += c + 1; jmps++; } for (auto v : ans) { cout << v << endl; } }
replace
58
59
58
59
0
p02721
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> a(2e5, 0), b(2e5, 0); for (int i = 0, cur = 0; i < n; i++) { if (s[i] == 'o') { a[cur++] = i; i += c; } } for (int i = n - 1, cur = k - 1; i >= 0; i--) { if (s[i] == 'o') { b[cur--] = i; i -= c; } } for (int i = 0; i < k; i++) { if (a[i] == b[i]) cout << a[i] + 1 << endl; } }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; int a[200000]; int b[200000]; for (int i = 0, cur = 0; i < n; i++) { if (s[i] == 'o') { a[cur++] = i; i += c; } } for (int i = n - 1, cur = k - 1; i >= 0; i--) { if (s[i] == 'o') { b[cur--] = i; i -= c; } } for (int i = 0; i < k; i++) { if (a[i] == b[i]) cout << a[i] + 1 << endl; } }
replace
10
11
10
12
0
p02721
C++
Runtime Error
#include <iostream> #include <limits> #include <map> #include <set> #include <sstream> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; typedef stringstream ss; const int mii = numeric_limits<int>::min(); const int mai = numeric_limits<int>::max(); const ll mil = numeric_limits<long long>::min(); const ll mal = numeric_limits<long long>::max(); #define REP(i, a, b) for (int i = a; i <= b; ++i) #define RREP(i, a, b) for (int i = a; i >= b; --i) #define PB(x) push_back(x) int main(int argc, char **argv) { int n, k, c; string s; cin >> n >> k >> c; cin >> s; vi l(k); vi r(k); int cc = 0; int kc = 0; REP(i, 0, n - 1 && kc < k) { if (cc > 0) { cc--; continue; } if (s[i] == 'o') { l[kc] = i; ++kc; cc = c; } } kc = k - 1; cc = 0; RREP(i, n - 1, 0 && kc < k) { if (cc > 0) { cc--; continue; } if (s[i] == 'o') { r[kc] = i; kc--; cc = c; } } REP(i, 0, k - 1) { if (l[i] == r[i]) cout << l[i] + 1 << endl; } }
#include <iostream> #include <limits> #include <map> #include <set> #include <sstream> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; typedef stringstream ss; const int mii = numeric_limits<int>::min(); const int mai = numeric_limits<int>::max(); const ll mil = numeric_limits<long long>::min(); const ll mal = numeric_limits<long long>::max(); #define REP(i, a, b) for (int i = a; i <= b; ++i) #define RREP(i, a, b) for (int i = a; i >= b; --i) #define PB(x) push_back(x) int main(int argc, char **argv) { int n, k, c; string s; cin >> n >> k >> c; cin >> s; vi l(k); vi r(k); int cc = 0; int kc = 0; REP(i, 0, n - 1 && kc < k) { if (cc > 0) { cc--; continue; } if (s[i] == 'o') { l[kc] = i; ++kc; cc = c; } } kc = k - 1; cc = 0; RREP(i, n - 1, 0 && kc >= 0) { if (cc > 0) { cc--; continue; } if (s[i] == 'o') { r[kc] = i; kc--; cc = c; } } REP(i, 0, k - 1) { if (l[i] == r[i]) cout << l[i] + 1 << endl; } }
replace
51
52
51
52
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int inf = 1000000; int n, k, c; string s; int main() { cin >> n >> k >> c >> s; vector<int> g1, g2; { int lst = -inf; int p = 0; for (int i = 0; i < n && p < k; ++i) { if (s[i] == 'o' && i > lst + c) { g1[p++] = i; lst = i; } } } { int lst = inf; int p = k - 1; for (int i = n - 1; i >= 0 && p >= 0; --i) { if (s[i] == 'o' && i < lst - c) { g2[p--] = i; lst = i; } } } for (int i = 0; i < k; ++i) { if (g1[i] == g2[i]) { cout << g1[i] + 1 << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1000000; int n, k, c; string s; int main() { cin >> n >> k >> c >> s; vector<int> g1(k), g2(k); { int lst = -inf; int p = 0; for (int i = 0; i < n && p < k; ++i) { if (s[i] == 'o' && i > lst + c) { g1[p++] = i; lst = i; } } } { int lst = inf; int p = k - 1; for (int i = n - 1; i >= 0 && p >= 0; --i) { if (s[i] == 'o' && i < lst - c) { g2[p--] = i; lst = i; } } } for (int i = 0; i < k; ++i) { if (g1[i] == g2[i]) { cout << g1[i] + 1 << '\n'; } } return 0; }
replace
7
8
7
8
-11
p02721
C++
Runtime Error
#include <cstdio> int n, k, c, f[100003][2]; char s[200003]; int main() { scanf("%d%d%d%s", &n, &k, &c, s + 1); int i, j = 0; for (i = 1; i <= n; i++) { if (s[i] == 'o' && i > j) f[i][0] = f[i - 1][0] + 1, j = i + c; else f[i][0] = f[i - 1][0]; } j = n + 1; for (i = n; i >= 1; i--) { if (s[i] == 'o' && i < j) f[i][1] = f[i + 1][1] + 1, j = i - c; else f[i][1] = f[i + 1][1]; } for (int i = 1; i <= n; i++) if (f[i - 1][0] + 1 + f[i + 1][1] == k) printf("%d\n", i); return 0; }
#include <cstdio> int n, k, c, f[200003][2]; char s[200003]; int main() { scanf("%d%d%d%s", &n, &k, &c, s + 1); int i, j = 0; for (i = 1; i <= n; i++) { if (s[i] == 'o' && i > j) f[i][0] = f[i - 1][0] + 1, j = i + c; else f[i][0] = f[i - 1][0]; } j = n + 1; for (i = n; i >= 1; i--) { if (s[i] == 'o' && i < j) f[i][1] = f[i + 1][1] + 1, j = i - c; else f[i][1] = f[i + 1][1]; } for (int i = 1; i <= n; i++) if (f[i - 1][0] + 1 + f[i + 1][1] == k) printf("%d\n", i); return 0; }
replace
1
2
1
2
0
p02721
C++
Runtime Error
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //----------------------- Print Function ----------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } template <typename T> void print(const vector<T> &v) { for (auto e : v) cout << e << ' '; cout << endl; } //------------------------- Libraries -------------------------// template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<1000000007>; //--------------------------- Solve ---------------------------// void solve() { int N, K, C; cin >> N >> K >> C; string s; cin >> s; s = '#' + s; vector<int> left(K + 1), right(K + 1); int cnt = 1; for (int i = 1; i <= N; i++) { if (s[i] == 'o') { left[cnt] = i; cnt++; i += C; } } cnt = K; for (int i = N; i >= 0 && cnt >= 0; i--) { if (s[i] == 'o') { right[cnt] = i; cnt--; i -= C; } } vector<int> ans; for (int i = 1; i <= K; i++) { if (left[i] == right[i]) ans.push_back(left[i]); } print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //----------------------- Print Function ----------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } template <typename T> void print(const vector<T> &v) { for (auto e : v) cout << e << ' '; cout << endl; } //------------------------- Libraries -------------------------// template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<1000000007>; //--------------------------- Solve ---------------------------// void solve() { int N, K, C; cin >> N >> K >> C; string s; cin >> s; s = '#' + s; vector<int> left(K + 1), right(K + 1); int cnt = 1; for (int i = 1; i <= N & cnt <= K; i++) { if (s[i] == 'o') { left[cnt] = i; cnt++; i += C; } } cnt = K; for (int i = N; i >= 0 && cnt >= 0; i--) { if (s[i] == 'o') { right[cnt] = i; cnt--; i -= C; } } vector<int> ans; for (int i = 1; i <= K; i++) { if (left[i] == right[i]) ans.push_back(left[i]); } print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }
replace
96
97
96
97
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1 << 30) - 1; const ll LINF = (1LL << 60) - 1; int l[200010]; int r[200010]; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; int num = 0; int now = 0; while (now < n) { if (s[now] == 'o') { l[++num] = now; now += c + 1; } else { now++; } } num = k; now = n - 1; while (now >= 0) { if (s[now] == 'o') { r[num--] = now; now -= c + 1; } else { now--; } } for (int i = 1; i <= k; ++i) { if (l[i] == r[i]) { cout << l[i] + 1 << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1 << 30) - 1; const ll LINF = (1LL << 60) - 1; int l[200010]; int r[200010]; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; int num = 0; int now = 0; while (now < n) { if (s[now] == 'o') { l[++num] = now; now += c + 1; } else { now++; } } num = k; now = n - 1; while (now >= 0) { if (s[now] == 'o') { r[num--] = now; if (num <= 0) break; now -= c + 1; } else { now--; } } for (int i = 1; i <= k; ++i) { if (l[i] == r[i]) { cout << l[i] + 1 << endl; } } }
insert
48
48
48
50
0
p02721
C++
Time Limit Exceeded
/* #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") */ #pragma GCC optimize("O3") #pragma GCC target("sse4") #define NDEBUG #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <stack> #include <vector> // find out the use of the below #include <cassert> #include <cstdlib> #include <ctime> #include <iomanip> #include <memory.h> #include <sstream> #include <utility> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define PQ(T) priority_queue<T, vector<T>, greater<T>> #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define PI acos(-1) int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt","w", stdout); fio; int n, k, c; cin >> n >> k >> c; string st; cin >> st; // lazy, eager vector<int> la(k), ea(k); int ind = 0; for (int i = 0; i < n && ind < k; ++i) { if (st[i] == 'o') { ea[ind] = i; ind++; i += c; } } ind = k - 1; for (int i = n - 1; i >= 0 && ind >= 0; --i) { if (st[i] == 'o') { la[ind] = i; ind--; i -= c; } } // nxt[i] gives the next 'o' index after i vector<int> nxt(n); int prev = n + 1; for (int i = n - 1; i >= 0; --i) { nxt[i] = prev; if (st[i] == 'o') prev = i; } int ce = 0; // current eager index for (int i = 0; i < n; ++i) { if (ce >= k) break; if (st[i] == 'x') continue; while (i < ea[ce]) { i++; } if (i == ea[ce]) { if (nxt[i] > la[ce]) { ce++; cout << i + 1 << '\n'; } } else if (i > la[ce]) { ce++; i = ea[ce] - 1; } } return 0; } /* BEFORE submitting, check for: * 1. Integer overflow * 2. Float/Double precision errors * 3. Array index out of bounds * 4. Edge cases.(n=1, n=max, etc.) * 5. Time complexity. No TLEs */
/* #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") */ #pragma GCC optimize("O3") #pragma GCC target("sse4") #define NDEBUG #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <stack> #include <vector> // find out the use of the below #include <cassert> #include <cstdlib> #include <ctime> #include <iomanip> #include <memory.h> #include <sstream> #include <utility> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define PQ(T) priority_queue<T, vector<T>, greater<T>> #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define PI acos(-1) int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt","w", stdout); fio; int n, k, c; cin >> n >> k >> c; string st; cin >> st; // lazy, eager vector<int> la(k), ea(k); int ind = 0; for (int i = 0; i < n && ind < k; ++i) { if (st[i] == 'o') { ea[ind] = i; ind++; i += c; } } ind = k - 1; for (int i = n - 1; i >= 0 && ind >= 0; --i) { if (st[i] == 'o') { la[ind] = i; ind--; i -= c; } } // nxt[i] gives the next 'o' index after i vector<int> nxt(n); int prev = n + 1; for (int i = n - 1; i >= 0; --i) { nxt[i] = prev; if (st[i] == 'o') prev = i; } int ce = 0; // current eager index for (int i = 0; i < n; ++i) { if (ce >= k) break; if (st[i] == 'x') continue; while (i < ea[ce]) { i++; } if (i == ea[ce]) { if (nxt[i] > la[ce]) { ce++; cout << i + 1 << '\n'; } } else if (i > la[ce]) { ce++; i--; } } return 0; } /* BEFORE submitting, check for: * 1. Integer overflow * 2. Float/Double precision errors * 3. Array index out of bounds * 4. Edge cases.(n=1, n=max, etc.) * 5. Time complexity. No TLEs */
replace
107
108
107
108
TLE
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; signed main() { int n, k, c; bool isWorkDays[200000]; cin >> n >> k >> c; for (int i = 0; i < n; i++) { char charaWork; cin >> charaWork; isWorkDays[i] = (charaWork == 'o'); } int holiday = c; int needsWorkAfter[100000]; int needsWorkBefore[100000]; int day = k - 1; for (int i = n - 1; i >= 0 || day >= 0; i--) { if (isWorkDays[i]) { needsWorkBefore[day] = i; i -= holiday; day--; } } day = 0; for (int i = 0; i < n || day < k; i++) { if (isWorkDays[i]) { needsWorkAfter[day] = i; i += holiday; day++; } } for (int i = 0; i < k; i++) { if (needsWorkAfter[i] == needsWorkBefore[i]) { cout << needsWorkAfter[i] + 1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { int n, k, c; bool isWorkDays[200000]; cin >> n >> k >> c; for (int i = 0; i < n; i++) { char charaWork; cin >> charaWork; isWorkDays[i] = (charaWork == 'o'); } int holiday = c; int needsWorkAfter[200000]; int needsWorkBefore[200000]; int day = k - 1; for (int i = n - 1; i >= 0 || day >= 0; i--) { if (isWorkDays[i]) { needsWorkBefore[day] = i; i -= holiday; day--; } } day = 0; for (int i = 0; i < n || day < k; i++) { if (isWorkDays[i]) { needsWorkAfter[day] = i; i += holiday; day++; } } for (int i = 0; i < k; i++) { if (needsWorkAfter[i] == needsWorkBefore[i]) { cout << needsWorkAfter[i] + 1 << endl; } } return 0; }
replace
15
17
15
17
0
p02721
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; const int MAXS = 100010; char str[MAXS]; int main() { int N; int K; int C; scanf("%d %d %d", &N, &K, &C); scanf("%s", str); vector<int> best(N); vector<int> slack(N, K); ++C; for (int i = 0; i < N; ++i) { if (i) { best[i] = max(best[i], best[i - 1]); } if (str[i] == 'o') { int preMax = 0; if (i - C >= 0) { preMax = best[i - C]; } best[i] = max(best[i], preMax + 1); } } for (int i = N - 1; i >= 0; --i) { if (str[i] == 'o') { if (i - C >= 0) { slack[i - C] = min(slack[i - C], slack[i] - 1); } } if (i) { slack[i - 1] = min(slack[i - 1], slack[i]); } } // for (int i = 0; i < N; ++i) { // cout << best[i] << " "; // } // cout << endl; // for (int i = 0; i < N; ++i) { // cout << slack[i] << " "; // } // cout << endl; unordered_map<int, int> critCount; for (int i = 0; i < N; ++i) { if (slack[i] == best[i] && str[i] == 'o') { ++critCount[best[i]]; } } for (int i = 0; i < N; ++i) { if (slack[i] == best[i] && str[i] == 'o' && critCount[best[i]] == 1) { cout << i + 1 << endl; ; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; const int MAXS = 300010; char str[MAXS]; int main() { int N; int K; int C; scanf("%d %d %d", &N, &K, &C); scanf("%s", str); vector<int> best(N); vector<int> slack(N, K); ++C; for (int i = 0; i < N; ++i) { if (i) { best[i] = max(best[i], best[i - 1]); } if (str[i] == 'o') { int preMax = 0; if (i - C >= 0) { preMax = best[i - C]; } best[i] = max(best[i], preMax + 1); } } for (int i = N - 1; i >= 0; --i) { if (str[i] == 'o') { if (i - C >= 0) { slack[i - C] = min(slack[i - C], slack[i] - 1); } } if (i) { slack[i - 1] = min(slack[i - 1], slack[i]); } } // for (int i = 0; i < N; ++i) { // cout << best[i] << " "; // } // cout << endl; // for (int i = 0; i < N; ++i) { // cout << slack[i] << " "; // } // cout << endl; unordered_map<int, int> critCount; for (int i = 0; i < N; ++i) { if (slack[i] == best[i] && str[i] == 'o') { ++critCount[best[i]]; } } for (int i = 0; i < N; ++i) { if (slack[i] == best[i] && str[i] == 'o' && critCount[best[i]] == 1) { cout << i + 1 << endl; ; } } return 0; }
replace
12
13
12
13
0
p02721
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int pre[N]; int n, m, k; string s; vector<int> ans; int dp[N]; int solve(int i) { if (i >= n) return 0; if (dp[i] != -1) return dp[i]; if (s[i] == 'o') { return 1 + solve(i + k + 1); } return dp[i] = solve(i + 1); } int main() { memset(dp, -1, sizeof dp); ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.in" , "r" , stdin) ; cin >> n >> m >> k; cin >> s; for (int i = 0; i < n; i++) { solve(i); } int l = -1, sum = 0; for (int i = 0; i < n; i++) { pre[i] = sum; if (i <= l) continue; if (s[i] == 'o') { sum++; l = i + k; } pre[i] = sum; } int r = n + N; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { int leftix = min(i - 1, r - k - 1); int right = solve(i + 1); int left = (leftix < 0 ? 0 : pre[leftix]); if (right + left < m) { ans.push_back(i + 1); } if (solve(i) > solve(r)) r = i; } } reverse(ans.begin(), ans.end()); for (auto u : ans) { cout << u << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int pre[N]; int n, m, k; string s; vector<int> ans; int dp[N]; int solve(int i) { if (i >= n) return 0; if (dp[i] != -1) return dp[i]; if (s[i] == 'o') { return dp[i] = 1 + solve(i + k + 1); } return dp[i] = solve(i + 1); } int main() { memset(dp, -1, sizeof dp); ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.in" , "r" , stdin) ; cin >> n >> m >> k; cin >> s; for (int i = 0; i < n; i++) { solve(i); } int l = -1, sum = 0; for (int i = 0; i < n; i++) { pre[i] = sum; if (i <= l) continue; if (s[i] == 'o') { sum++; l = i + k; } pre[i] = sum; } int r = n + N; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { int leftix = min(i - 1, r - k - 1); int right = solve(i + 1); int left = (leftix < 0 ? 0 : pre[leftix]); if (right + left < m) { ans.push_back(i + 1); } if (solve(i) > solve(r)) r = i; } } reverse(ans.begin(), ans.end()); for (auto u : ans) { cout << u << "\n"; } return 0; }
replace
19
20
19
20
TLE
p02721
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define REL #pragma GCC optimize("Ofast") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef int64_t i64; typedef long long LL; typedef long long ll; typedef long double LD; typedef complex<LD> cld; typedef unsigned int uint; typedef complex<double> cd; typedef unsigned long long ULL; #define endl "\n" #define dendl "\n\n" #define mp make_pair #define mt make_tuple #define size(v) (int)v.size() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() ///////////////////////////////////////////////////////////////////// template <typename T> T sqr(T a) { return a * a; } template <typename T> int sign(T a) { if (a == 0) return 0; return (a > 0 ? 1 : -1); } template <typename T1, typename T2> T2 sum_mod(T1 x, T2 MOD) { if (x < 0) x += MOD; if (x >= MOD) x -= MOD; return x; } template <typename T1, typename T2> T2 mul_mod(T1 x, T2 MOD) { if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD); return x % MOD; } template <typename T> bool uax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool uin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> &p) { out << p.first << ' ' << p.second; return out; } const int LOG = 18; const int N = (int)1e5 + 7; const int MAXN = (int)2e3 + 7; const int MOD = (int)998244353; const int INF = (int)1e9 + 7; const int CONST = 300; const LL LINF = (i64)2e15; const LD PI = 3.1415926535897932384626433832795; const LD EPS = 1; ///////////////////////////////////////////////////////////////////// int nxt[N], work[N]; int n, k, c; string s; int main() { double start = clock(); #ifdef _DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); #else cout << fixed << setprecision(20); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif cin >> n >> k >> c >> s; int lst = INF; for (int i = n - 1; i >= 0; i--) { nxt[i] = lst; if (s[i] == 'o') lst = i; } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'x') continue; int pos = i + c + 1; if (pos >= n || (s[pos] == 'x' && nxt[pos] == INF)) work[i] = 1; else { if (s[pos] == 'o') work[i] = work[pos] + 1; else work[i] = work[nxt[pos]] + 1; } } vector<int> day; int pos = (s[0] == 'o' ? 0 : nxt[0]); if (work[pos] > k) return 0; for (int i = 0; i < k; i++) { day.push_back(pos); if (i != k - 1) pos = (s[pos + c + 1] == 'o' ? pos + c + 1 : nxt[pos + c + 1]); } vector<int> ans; for (int i = 0; i < k; i++) { if (nxt[day[i]] == INF || i + work[nxt[day[i]]] < k) ans.push_back(day[i] + 1); } for (int x : ans) cout << x << endl; #ifdef _DEBUG cout << endl << "Time is " << (clock() - start) / 1000.0; #endif }
#define _CRT_SECURE_NO_WARNINGS #define REL #pragma GCC optimize("Ofast") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef int64_t i64; typedef long long LL; typedef long long ll; typedef long double LD; typedef complex<LD> cld; typedef unsigned int uint; typedef complex<double> cd; typedef unsigned long long ULL; #define endl "\n" #define dendl "\n\n" #define mp make_pair #define mt make_tuple #define size(v) (int)v.size() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() ///////////////////////////////////////////////////////////////////// template <typename T> T sqr(T a) { return a * a; } template <typename T> int sign(T a) { if (a == 0) return 0; return (a > 0 ? 1 : -1); } template <typename T1, typename T2> T2 sum_mod(T1 x, T2 MOD) { if (x < 0) x += MOD; if (x >= MOD) x -= MOD; return x; } template <typename T1, typename T2> T2 mul_mod(T1 x, T2 MOD) { if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD); return x % MOD; } template <typename T> bool uax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool uin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> &p) { out << p.first << ' ' << p.second; return out; } const int LOG = 18; const int N = (int)2e5 + 7; const int MAXN = (int)2e3 + 7; const int MOD = (int)998244353; const int INF = (int)1e9 + 7; const int CONST = 300; const LL LINF = (i64)2e15; const LD PI = 3.1415926535897932384626433832795; const LD EPS = 1; ///////////////////////////////////////////////////////////////////// int nxt[N], work[N]; int n, k, c; string s; int main() { double start = clock(); #ifdef _DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); #else cout << fixed << setprecision(20); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif cin >> n >> k >> c >> s; int lst = INF; for (int i = n - 1; i >= 0; i--) { nxt[i] = lst; if (s[i] == 'o') lst = i; } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'x') continue; int pos = i + c + 1; if (pos >= n || (s[pos] == 'x' && nxt[pos] == INF)) work[i] = 1; else { if (s[pos] == 'o') work[i] = work[pos] + 1; else work[i] = work[nxt[pos]] + 1; } } vector<int> day; int pos = (s[0] == 'o' ? 0 : nxt[0]); if (work[pos] > k) return 0; for (int i = 0; i < k; i++) { day.push_back(pos); if (i != k - 1) pos = (s[pos + c + 1] == 'o' ? pos + c + 1 : nxt[pos + c + 1]); } vector<int> ans; for (int i = 0; i < k; i++) { if (nxt[day[i]] == INF || i + work[nxt[day[i]]] < k) ans.push_back(day[i] + 1); } for (int x : ans) cout << x << endl; #ifdef _DEBUG cout << endl << "Time is " << (clock() - start) / 1000.0; #endif }
replace
97
98
97
98
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, k, c; string s; long long l[100100], r[100100]; vector<int> v; int main() { cin >> n >> k >> c; cin >> s; long long sum = 0; for (int i = 0; i < s.size(); i++) if (s[i] == 'o') { sum++; v.push_back(i); i += c; } if (sum > k) return 0; if (s[0] == 'o') l[0] = 1; for (int i = 1; i < s.size(); i++) { if (i >= c + 1) l[i] = max(l[i - 1], l[i - c - 1] + (s[i] == 'o')); else l[i] = max(l[i - 1], (long long)(s[i] == 'o')); } for (int i = s.size() - 1; i >= 0; i--) { if (i + c + 1 < s.size()) r[i] = max(r[i + 1], r[i + c + 1] + (s[i] == 'o')); else r[i] = max(r[i + 1], (long long)(s[i] == 'o')); } vector<int> ans; for (int i = 0; i < v.size(); i++) { if (v[i] == 0 && sum != +r[v[i] + 1]) cout << (v[i] + 1) << endl; else if (v[i] == s.size() - 1 && sum != l[v[i] - 1]) cout << v[i] + 1 << endl; else if (sum != l[v[i] - 1] + r[v[i] + 1]) cout << (v[i] + 1) << endl; } }
#include <bits/stdc++.h> using namespace std; long long n, k, c; string s; long long l[200100], r[200100]; vector<int> v; int main() { cin >> n >> k >> c; cin >> s; long long sum = 0; for (int i = 0; i < s.size(); i++) if (s[i] == 'o') { sum++; v.push_back(i); i += c; } if (sum > k) return 0; if (s[0] == 'o') l[0] = 1; for (int i = 1; i < s.size(); i++) { if (i >= c + 1) l[i] = max(l[i - 1], l[i - c - 1] + (s[i] == 'o')); else l[i] = max(l[i - 1], (long long)(s[i] == 'o')); } for (int i = s.size() - 1; i >= 0; i--) { if (i + c + 1 < s.size()) r[i] = max(r[i + 1], r[i + c + 1] + (s[i] == 'o')); else r[i] = max(r[i + 1], (long long)(s[i] == 'o')); } vector<int> ans; for (int i = 0; i < v.size(); i++) { if (v[i] == 0 && sum != +r[v[i] + 1]) cout << (v[i] + 1) << endl; else if (v[i] == s.size() - 1 && sum != l[v[i] - 1]) cout << v[i] + 1 << endl; else if (sum != l[v[i] - 1] + r[v[i] + 1]) cout << (v[i] + 1) << endl; } }
replace
4
5
4
5
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #define endl "\n" typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; template <class T> inline void fix(T &x) { if (x >= mod | x <= -mod) { x %= mod; } if (x < 0) { x += mod; } } const int MAX_N = 1e5 + 10; ll suf[MAX_N], pref[MAX_N]; int n, k, c; string in; bool ok[MAX_N]; signed main() { // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k >> c >> in; c++; for (int i = 0; i < n; i++) { if (in[i] == 'o' && i + c < n) { chkmax(pref[i + c], pref[i] + 1); } if (i + 1 < n) { chkmax(pref[i + 1], pref[i]); } } for (int i = n - 1; i >= 0; i--) { if (in[i] == 'o' && i - c >= 0) { chkmax(suf[i - c], suf[i] + 1); } if (i > 0) { chkmax(suf[i - 1], suf[i]); } } ll r = -1; for (int i = 0; i < n; i++) { if (pref[i] + suf[i] >= k) { ok[i] = true; } if (i <= r) { ok[i] = true; } if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) { r = i + c - 1; } } int l = n + 1; for (int i = n - 1; i >= 0; i--) { if (i >= l) { ok[i] = true; } if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) { l = i - c + 1; } } for (int i = 0; i < n; i++) { if (!ok[i]) { cout << i + 1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #define endl "\n" typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; template <class T> inline void fix(T &x) { if (x >= mod | x <= -mod) { x %= mod; } if (x < 0) { x += mod; } } const int MAX_N = 1e6 + 10; ll suf[MAX_N], pref[MAX_N]; int n, k, c; string in; bool ok[MAX_N]; signed main() { // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k >> c >> in; c++; for (int i = 0; i < n; i++) { if (in[i] == 'o' && i + c < n) { chkmax(pref[i + c], pref[i] + 1); } if (i + 1 < n) { chkmax(pref[i + 1], pref[i]); } } for (int i = n - 1; i >= 0; i--) { if (in[i] == 'o' && i - c >= 0) { chkmax(suf[i - c], suf[i] + 1); } if (i > 0) { chkmax(suf[i - 1], suf[i]); } } ll r = -1; for (int i = 0; i < n; i++) { if (pref[i] + suf[i] >= k) { ok[i] = true; } if (i <= r) { ok[i] = true; } if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) { r = i + c - 1; } } int l = n + 1; for (int i = n - 1; i >= 0; i--) { if (i >= l) { ok[i] = true; } if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) { l = i - c + 1; } } for (int i = 0; i < n; i++) { if (!ok[i]) { cout << i + 1 << endl; } } return 0; }
replace
24
25
24
25
0
p02721
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma warning(disable : 4996) #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m - 1; i >= n; --i) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()) #define ll long long #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long // #define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) \ REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ") template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<int, int> pii; typedef array<int, 3> arr3; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020; const double pi = acos(-1); constexpr double EPS = 1e-8; constexpr ll INF = 1e18; int sumL[300020], sumR[300020]; pair<int, int> dp[300020]; pair<int, int> rev[300020]; void solve() { // test(); int N, K, C; cin >> N >> K >> C; string S; cin >> S; int cnt = 0; int idx = 0; dp[0] = {0, -100010}; REP(i, N) { pii pre = dp[i]; dp[i + 1] = pre; if (S[i] == 'o') { if (i < C) { if (dp[i + 1].first) continue; else { dp[i + 1] = {1, i}; } } else { pre = dp[i - C]; if (pre.first + 1 > dp[i + 1].first) { dp[i + 1] = {pre.first + 1, i}; } } } } string T = S; VREVERSE(T); REP(i, N) { pii pre = rev[i]; rev[i + 1] = pre; if (T[i] == 'o') { if (i < C) { if (rev[i + 1].first) continue; else { rev[i + 1] = {1, i}; } } else { pre = rev[i - C]; if (pre.first + 1 > rev[i + 1].first) { rev[i + 1] = {pre.first + 1, i}; } } } } vector<int> A(N), cum(N + 1); REP(i, N) { if (i > 0) sumL[i] += sumL[i - 1]; if (S[i] == 'o') { sumL[i]++; sumL[i + 1]--; sumL[i + C + 1]++; } } FORR(i, N, 0) { sumR[i] += sumR[i + 1]; if (S[i] == 'o') { sumR[i]++; if (i) sumR[i - 1]--; if (i - C - 1 >= 0) sumR[i - C - 1]++; } } while (idx < N) { if (S[idx] == 'o') { cnt++; idx += 2 * C + 1; } else { idx++; } } if (cnt > K) { cout << endl; return; } REP(i, N) { if (S[i] == 'o') A[i] = 1; } REP(i, N) { cum[i + 1] = cum[i] + A[i]; } vector<int> ans; REP(i, N) { if (S[i] == 'o') { pii p = dp[i]; // cout << i << " " << p.first <<" "<< p.second << endl; int las = p.second; int nxt = las + C + 1; if (nxt <= i) nxt = i + 1; // cout << nxt << " " << rev[N-nxt].first << endl; if (p.first + rev[N - nxt].first < K) ans.push_back(i + 1); } } for (auto x : ans) { print(x); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); // int q; cin >> q; // while (q--) solve(); }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma warning(disable : 4996) #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m - 1; i >= n; --i) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()) #define ll long long #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long // #define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) \ REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ") template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<int, int> pii; typedef array<int, 3> arr3; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020; const double pi = acos(-1); constexpr double EPS = 1e-8; constexpr ll INF = 1e18; int sumL[300020], sumR[300020]; pair<int, int> dp[300020]; pair<int, int> rev[300020]; void solve() { // test(); int N, K, C; cin >> N >> K >> C; string S; cin >> S; int cnt = 0; int idx = 0; dp[0] = {0, -100010}; REP(i, N) { pii pre = dp[i]; dp[i + 1] = pre; if (S[i] == 'o') { if (i < C) { if (dp[i + 1].first) continue; else { dp[i + 1] = {1, i}; } } else { pre = dp[i - C]; if (pre.first + 1 > dp[i + 1].first) { dp[i + 1] = {pre.first + 1, i}; } } } } string T = S; VREVERSE(T); REP(i, N) { pii pre = rev[i]; rev[i + 1] = pre; if (T[i] == 'o') { if (i < C) { if (rev[i + 1].first) continue; else { rev[i + 1] = {1, i}; } } else { pre = rev[i - C]; if (pre.first + 1 > rev[i + 1].first) { rev[i + 1] = {pre.first + 1, i}; } } } } vector<int> A(N), cum(N + 1); REP(i, N) { if (i > 0) sumL[i] += sumL[i - 1]; if (S[i] == 'o') { sumL[i]++; sumL[i + 1]--; sumL[i + C + 1]++; } } FORR(i, N, 0) { sumR[i] += sumR[i + 1]; if (S[i] == 'o') { sumR[i]++; if (i) sumR[i - 1]--; if (i - C - 1 >= 0) sumR[i - C - 1]++; } } while (idx < N) { if (S[idx] == 'o') { cnt++; idx += 2 * C + 1; } else { idx++; } } if (cnt > K) { cout << endl; return; } REP(i, N) { if (S[i] == 'o') A[i] = 1; } REP(i, N) { cum[i + 1] = cum[i] + A[i]; } vector<int> ans; REP(i, N) { if (S[i] == 'o') { pii p = dp[i]; // cout << i << " " << p.first <<" "<< p.second << endl; int las = p.second; int nxt = las + C + 1; if (nxt <= i) nxt = i + 1; // cout << nxt << " " << rev[N-nxt].first << endl; if (p.first + rev[max(0LL, N - nxt)].first < K) ans.push_back(i + 1); } } for (auto x : ans) { print(x); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); // int q; cin >> q; // while (q--) solve(); }
replace
166
167
166
167
0
p02721
C++
Runtime Error
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define DEBUG(x) \ cerr << "line:" << __LINE__ << ", " << #x " == " << (x) << endl; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define FOR(it, s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++) #define fst first #define snd second #define ALL(a) a.begin(), a.end() #define RI(x) scanf("%d", &(x)) #define RII(x, y) scanf("%d%d", &(x), &(y)) #define RIII(x, y, z) scanf("%d%d%d", &(x), &(y), &(z)) #define DRI(x) \ int(x); \ scanf("%d", &(x)) #define DRII(x, y) \ int(x), (y); \ scanf("%d%d", &(x), &(y)) #define DRIII(x, y, z) \ int(x), (y), (z); \ scanf("%d%d%d", &(x), &(y), &(z)) using namespace std; typedef long long LL; typedef unsigned int uint; typedef unsigned long long ULL; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<vi> vvi; struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} }; typedef Point Vector; #define INF (int)1e9 #define EPS (1.0e-8) LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); } LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } LL qpow(LL a, LL b) { LL res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } LL qpow(LL a, LL b, LL mod) { a %= mod; LL res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } // ------------------ const int maxn = 1e5 + 10; int L[maxn], R[maxn]; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // DRIII(N, K, C); int N, K, C; cin >> N >> K >> C; string s; cin >> s; int cur = 0; REP(i, 0, K) { int tmp; if (i == 0) { tmp = 0; } else { tmp = C; } while (s[cur] != 'o' || tmp > 0) { tmp--; cur++; } // ok, find one L[i] = cur + 1; cur++; } // REP(i, 0, K) cout << L[i] << " "; cout << endl; cur = N - 1; for (int i = K - 1; i >= 0; i--) { int tmp; if (i == K - 1) { tmp = 0; } else { tmp = C; } while (s[cur] != 'o' || tmp > 0) { tmp--; cur--; } // ok, find one R[i] = cur + 1; cur--; } // REP(i, 0, K) cout << R[i] << " "; cout << endl; // REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << ' '; REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << endl; #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define DEBUG(x) \ cerr << "line:" << __LINE__ << ", " << #x " == " << (x) << endl; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define FOR(it, s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++) #define fst first #define snd second #define ALL(a) a.begin(), a.end() #define RI(x) scanf("%d", &(x)) #define RII(x, y) scanf("%d%d", &(x), &(y)) #define RIII(x, y, z) scanf("%d%d%d", &(x), &(y), &(z)) #define DRI(x) \ int(x); \ scanf("%d", &(x)) #define DRII(x, y) \ int(x), (y); \ scanf("%d%d", &(x), &(y)) #define DRIII(x, y, z) \ int(x), (y), (z); \ scanf("%d%d%d", &(x), &(y), &(z)) using namespace std; typedef long long LL; typedef unsigned int uint; typedef unsigned long long ULL; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<vi> vvi; struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} }; typedef Point Vector; #define INF (int)1e9 #define EPS (1.0e-8) LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); } LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } LL qpow(LL a, LL b) { LL res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } LL qpow(LL a, LL b, LL mod) { a %= mod; LL res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } // ------------------ const int maxn = 2e5 + 10; int L[maxn], R[maxn]; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // DRIII(N, K, C); int N, K, C; cin >> N >> K >> C; string s; cin >> s; int cur = 0; REP(i, 0, K) { int tmp; if (i == 0) { tmp = 0; } else { tmp = C; } while (s[cur] != 'o' || tmp > 0) { tmp--; cur++; } // ok, find one L[i] = cur + 1; cur++; } // REP(i, 0, K) cout << L[i] << " "; cout << endl; cur = N - 1; for (int i = K - 1; i >= 0; i--) { int tmp; if (i == K - 1) { tmp = 0; } else { tmp = C; } while (s[cur] != 'o' || tmp > 0) { tmp--; cur--; } // ok, find one R[i] = cur + 1; cur--; } // REP(i, 0, K) cout << R[i] << " "; cout << endl; // REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << ' '; REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << endl; #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
replace
76
77
76
77
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; int backcount = k; vector<int> v(n); for (int i = n - 1; i >= 0; i--) { if (s.at(i) == 'o') { v.at(backcount) = i; backcount--; i -= c; } if (backcount == 0) { break; } if (i < 0) { return 0; } } int frontcount = 1; for (int i = 0; i < n; i++) { if (s.at(i) == 'o') { if (v.at(frontcount) == i) { cout << i + 1 << endl; } frontcount++; i += c; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; int backcount = k; vector<int> v(n + 1); for (int i = n - 1; i >= 0; i--) { if (s.at(i) == 'o') { v.at(backcount) = i; backcount--; i -= c; } if (backcount == 0) { break; } if (i < 0) { return 0; } } int frontcount = 1; for (int i = 0; i < n; i++) { if (s.at(i) == 'o') { if (v.at(frontcount) == i) { cout << i + 1 << endl; } frontcount++; i += c; } } return 0; }
replace
11
12
11
12
0
p02721
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) typedef long long ll; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, K, C; cin >> N >> K >> C; string s; cin >> s; vector<int> dp(N + 1); dp[N] = 0; for (int i(N - 1); i >= 0; --i) { dp[i] = dp[i + 1]; if (s[i] == 'o') dp[i] = max(dp[i], 1 + dp[min(N, i + C + 1)]); } int l(0); while (l < N and K > 0) { int r = l; int cnt(0); while (r < N and dp[r] >= K) { cnt += s[r++] == 'o'; } if (cnt == 1) for (int i(l); i < r; ++i) if (s[i] == 'o') { cout << i + 1 << '\n'; break; } --K; for (int i(l); i < r; ++i) if (s[i] == 'o') { l = i + C + 1; break; } } }
#include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) typedef long long ll; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, K, C; cin >> N >> K >> C; string s; cin >> s; vector<int> dp(N + 1); dp[N] = 0; for (int i(N - 1); i >= 0; --i) { dp[i] = dp[i + 1]; if (s[i] == 'o') dp[i] = max(dp[i], 1 + dp[min(N, i + C + 1)]); } int l(0); while (l < N and K > 0) { int r = l; int cnt(0); while (r < N and dp[r] >= K and cnt <= 1) { cnt += s[r++] == 'o'; } if (cnt == 1) for (int i(l); i < r; ++i) if (s[i] == 'o') { cout << i + 1 << '\n'; break; } --K; for (int i(l); i < r; ++i) if (s[i] == 'o') { l = i + C + 1; break; } } }
replace
28
29
28
29
TLE
p02721
C++
Runtime Error
// Aleksander Łukasiewicz #include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; const int INF = 1000000009; const int MAXN = 2 * 100 * 1000; char tab[MAXN + 3]; int ff[2 * MAXN + 3], bb[2 * MAXN + 3]; int main() { int n, k, c; scanf("%d %d %d", &n, &k, &c); scanf("%s", tab + 1); for (int i = n; i >= 1; i--) if (tab[i] == 'o') ff[i] = 1 + ff[min(n + 1, i + c + 1)]; else ff[i] = ff[i + 1]; vector<int> ans; int last = -c; for (int i = 1; i <= n; i++) { if (tab[i] == 'o') { if (bb[last] + ff[max(i + 1, last + c + 1)] < k) ans.pb(i); if (i > last + c) { bb[i] = bb[max(last, 0)] + 1; last = i; } } } for (auto a : ans) printf("%d\n", a); return 0; }
// Aleksander Łukasiewicz #include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; const int INF = 1000000009; const int MAXN = 2 * 100 * 1000; char tab[MAXN + 3]; int ff[2 * MAXN + 3], bb[2 * MAXN + 3]; int main() { int n, k, c; scanf("%d %d %d", &n, &k, &c); scanf("%s", tab + 1); for (int i = n; i >= 1; i--) if (tab[i] == 'o') ff[i] = 1 + ff[min(n + 1, i + c + 1)]; else ff[i] = ff[i + 1]; vector<int> ans; int last = -c; for (int i = 1; i <= n; i++) { if (tab[i] == 'o') { if (bb[max(last, 0)] + ff[max(i + 1, last + c + 1)] < k) ans.pb(i); if (i > last + c) { bb[i] = bb[max(last, 0)] + 1; last = i; } } } for (auto a : ans) printf("%d\n", a); return 0; }
replace
32
33
32
33
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define LL long long #define pii pair<int, int> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD = 1e9 + 7; int n, t, c, pos, vis[100010], sz = 0; string s; vector<int> v; int main() { cin >> n >> t >> c >> s; pos = 0; while (s[pos] == 'x') pos++; while (pos < n) { sz++; vis[pos] = sz; pos += c + 1; while (pos < n && s[pos] == 'x') pos++; } pos = n - 1; while (s[pos] == 'x') pos--; while (pos >= 0) { v.pb(pos); pos -= c + 1; while (pos >= 0 && s[pos] == 'x') pos--; } reverse(v.begin(), v.end()); rep(i, n) { if (vis[i] == 0) continue; int cur = vis[i] - 1, pos = upper_bound(v.begin(), v.end(), i) - v.begin(); if (cur + v.size() - pos < t) cout << i + 1 << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define LL long long #define pii pair<int, int> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD = 1e9 + 7; int n, t, c, pos, vis[200010], sz = 0; string s; vector<int> v; int main() { cin >> n >> t >> c >> s; pos = 0; while (s[pos] == 'x') pos++; while (pos < n) { sz++; vis[pos] = sz; pos += c + 1; while (pos < n && s[pos] == 'x') pos++; } pos = n - 1; while (s[pos] == 'x') pos--; while (pos >= 0) { v.pb(pos); pos -= c + 1; while (pos >= 0 && s[pos] == 'x') pos--; } reverse(v.begin(), v.end()); rep(i, n) { if (vis[i] == 0) continue; int cur = vis[i] - 1, pos = upper_bound(v.begin(), v.end(), i) - v.begin(); if (cur + v.size() - pos < t) cout << i + 1 << endl; } return 0; }
replace
15
16
15
16
0
p02721
Python
Runtime Error
N, K, C = map(int, input().split()) S = input() L = [] R = [] L_index = 0 L_count = 0 R_index = N - 1 R_count = K - 1 while L_index < N and L_count < K: if S[L_index] == "o": L.append(L_index) L_index += C + 1 L_count += 1 else: L_index += 1 while R_index >= 0 and R_count >= 0: if S[R_index] == "o": R.append(R_index) R_index -= C - 1 R_count -= 1 else: R_index -= 1 work_day = set(L) & set(R) for w_day in work_day: print(w_day + 1)
n, k, c = map(int, input().split()) s = input() l = [-1] * k r = [-1] * k nowl = 0 indl = 0 while nowl < n and indl < k: for i in range(nowl, n): if s[i] == "o": l[indl] = i nowl = i + c + 1 indl += 1 break nowr = n - 1 indr = k - 1 while nowr >= 0 and indr >= 0: for i in range(nowr, -1, -1): if s[i] == "o": r[indr] = i nowr = i - c - 1 indr -= 1 break for i in range(k): if l[i] == r[i]: print(l[i] + 1)
replace
0
27
0
25
0
p02721
Python
Runtime Error
#!/usr/bin/env python3 n, k, c = map(int, input().split()) s = input() if c == 0: if s.cnt("o") == k: print(*range(1, n + 1), sep="\n") exit() left = [] i = 0 while i < n: if s[i] == "o": left.append(i) i += c i += 1 right = [] i = n - 1 while i >= 0: if s[i] == "o": right.append(i) i -= c i -= 1 right.reverse() for i in range(len(left)): if left[i] == right[i]: print(left[i] + 1)
#!/usr/bin/env python3 n, k, c = map(int, input().split()) s = input() if c == 0: if s.count("o") == k: for i in range(n): if s[i] == "o": print(i + 1) exit() left = [] i = 0 while i < n: if s[i] == "o": left.append(i) i += c i += 1 right = [] i = n - 1 while i >= 0: if s[i] == "o": right.append(i) i -= c i -= 1 right.reverse() for i in range(len(left)): if left[i] == right[i]: print(left[i] + 1)
replace
5
7
5
9
0
p02721
C++
Memory Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC omodtimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<long long, long long> ii; typedef complex<long double> com; ll mod = 1e9 + 7; ll k; vector<vector<ll>> graph; vector<vector<ll>> depth; vector<bool> visited; void dfs(ll u = 1, ll d = k, ll p = -1) { if (visited[u]) return; visited[u] = true; if (depth[d].size() <= 1) depth[d].push_back(u); for (ll v : graph[u]) { if (v == p) continue; if (visited[v]) continue; dfs(v, d - 1, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, c; cin >> n >> k >> c; string s; cin >> s; ll current = 0; vector<ll> lol; vector<ll> value(n); graph.resize(n); depth.resize(k + 1); visited.resize(n, false); for (int z = n - 1; z >= 0; z--) { if (z + c + 1 <= n - 1 && s[z + c + 1] != 'x') { if (value[z + c + 1] > current) { current = value[z + c + 1]; lol.clear(); lol.push_back(z + c + 1); } else lol.push_back(z + c + 1); } if (s[z] == 'x') continue; for (int x = 0; x < lol.size(); x++) { graph[z].push_back(lol[x]); } value[z] = current + 1; } for (int z = 0; z < n; z++) { if (value[z] > k) return 0; } for (int z = 0; z < n; z++) { if (visited[z]) continue; if (value[z] == k) { dfs(z); } } set<ll> ans; for (int z = 0; z <= k; z++) { if (depth[z].size() == 1) { ans.insert(depth[z][0]); } } for (ll i : ans) { cout << i + 1 << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC omodtimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<long long, long long> ii; typedef complex<long double> com; ll mod = 1e9 + 7; ll k; vector<vector<ll>> graph; vector<vector<ll>> depth; vector<bool> visited; void dfs(ll u = 1, ll d = k, ll p = -1) { if (visited[u]) return; visited[u] = true; if (depth[d].size() <= 1) depth[d].push_back(u); for (ll v : graph[u]) { if (v == p) continue; if (visited[v]) continue; dfs(v, d - 1, u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, c; cin >> n >> k >> c; string s; cin >> s; ll current = 0; vector<ll> lol; vector<ll> value(n); graph.resize(n); depth.resize(k + 1); visited.resize(n, false); for (int z = n - 1; z >= 0; z--) { if (z + c + 1 <= n - 1 && s[z + c + 1] != 'x') { if (value[z + c + 1] > current) { current = value[z + c + 1]; lol.clear(); lol.push_back(z + c + 1); } else lol.push_back(z + c + 1); } if (s[z] == 'x') continue; for (int x = 0; x < min(10, int(lol.size())); x++) { graph[z].push_back(lol[x]); } value[z] = current + 1; } for (int z = 0; z < n; z++) { if (value[z] > k) return 0; } for (int z = 0; z < n; z++) { if (visited[z]) continue; if (value[z] == k) { dfs(z); } } set<ll> ans; for (int z = 0; z <= k; z++) { if (depth[z].size() == 1) { ans.insert(depth[z][0]); } } for (ll i : ans) { cout << i + 1 << endl; } }
replace
66
67
66
67
MLE
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int a[maxn], b[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); int n, k, c; string s; cin >> n >> k >> c >> s; int num = 0; for (int i = 0; i < n; i++) { if (s[i] == 'o') { a[num++] = i; i += c; } } num = k - 1; for (int i = n - 1; i >= 0; i--) { if (num < 0) break; if (s[i] == 'o') { b[num--] = i; i -= c; } } for (int i = 0; i < k; i++) if (a[i] == b[i]) cout << a[i] + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int inf = 0x3f3f3f3f; int a[maxn], b[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); int n, k, c; string s; cin >> n >> k >> c >> s; int num = 0; for (int i = 0; i < n; i++) { if (s[i] == 'o') { a[num++] = i; i += c; } } num = k - 1; for (int i = n - 1; i >= 0; i--) { if (num < 0) break; if (s[i] == 'o') { b[num--] = i; i -= c; } } for (int i = 0; i < k; i++) if (a[i] == b[i]) cout << a[i] + 1 << endl; return 0; }
replace
2
3
2
3
0
p02721
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <random> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; constexpr ll INF = 1LL << 60; ll n, k, c, l[100010], r[100010]; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> c >> s; for (int i = 0; i < n; ++i) { if (s[i] == 'o') { l[i + 1]++; i += c; } } for (int i = n - 1; i >= 0; --i) { if (s[i] == 'o') { r[i]++; i -= c; } } REP(i, n) l[i + 1] += l[i]; for (int i = n; i >= 1; --i) r[i - 1] += r[i]; // check: for (int i = 0; i < n; ++i) { if (l[i] + r[i + 1] < k) { cout << i + 1 << '\n'; } } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <random> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; constexpr ll INF = 1LL << 60; ll n, k, c, l[200010], r[200010]; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> c >> s; for (int i = 0; i < n; ++i) { if (s[i] == 'o') { l[i + 1]++; i += c; } } for (int i = n - 1; i >= 0; --i) { if (s[i] == 'o') { r[i]++; i -= c; } } REP(i, n) l[i + 1] += l[i]; for (int i = n; i >= 1; --i) r[i - 1] += r[i]; // check: for (int i = 0; i < n; ++i) { if (l[i] + r[i + 1] < k) { cout << i + 1 << '\n'; } } return 0; }
replace
10
11
10
11
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> a, b; for (int i = 0; i < n; i++) { if (s[i] == 'o') { a.push_back(i); i = i + c; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { b.push_back(i); i = i - c; } } for (int i = 0; i < k; i++) { if (a[i] == b[i - k - 1]) cout << i + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> a, b; for (int i = 0; i < n; i++) { if (s[i] == 'o') { a.push_back(i); i = i + c; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { b.push_back(i); i = i - c; } } for (int i = 0; i < k; i++) { if (a[i] == b[k - i - 1]) cout << a[i] + 1 << endl; } return 0; }
replace
27
29
27
29
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> #define RREP(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K, C; string S; cin >> N >> K >> C >> S; vector<int> dp(N + 1); dp[N] = 0; RREP(i, N) { if (S[i] == 'x') { dp[i] = dp[i + 1]; } else { int j = i + C + 1; dp[i] = max(dp[i + 1], 1 + (j < N ? dp[j] : 0)); } } int i = 0; while (i < N) { int first_o = -1; int next_i = -1; while (dp[i] >= K) { if (S[i] == 'o') { if (first_o == -1) { first_o = i; next_i = first_o + C + 1; } else { first_o = -1; break; } } ++i; } if (first_o != -1) { cout << (first_o + 1) << '\n'; // 1-based indexing } i = next_i; --K; } cout << flush; return 0; }
#include <bits/stdc++.h> #define RREP(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K, C; string S; cin >> N >> K >> C >> S; vector<int> dp(N + 1); dp[N] = 0; RREP(i, N) { if (S[i] == 'x') { dp[i] = dp[i + 1]; } else { int j = i + C + 1; dp[i] = max(dp[i + 1], 1 + (j < N ? dp[j] : 0)); } } int i = 0; while (K > 0) { int first_o = -1; int next_i = -1; while (dp[i] >= K) { if (S[i] == 'o') { if (first_o == -1) { first_o = i; next_i = first_o + C + 1; } else { first_o = -1; break; } } ++i; } if (first_o != -1) { cout << (first_o + 1) << '\n'; // 1-based indexing } i = next_i; --K; } cout << flush; return 0; }
replace
27
28
27
28
0
p02721
C++
Runtime Error
// shan61916 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double dll; #define mp make_pair #define pb push_back #define ff first #define ss second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define pll pair<ll, ll> #define all(x) x.begin(), x.end() #define vll vector<ll> const ll inf = (ll)(1e17 + 17); const ll mod = (ll)(1e9 + 7); vll res; string s, p; ll n, k, c; ll dp[100010], dp2[100010]; ll rec1(ll idx) { if (idx >= n) return 0; ll &ans = dp[idx]; if (ans != -1) return ans; ans = 0; if (s[idx] == 'o') ans = 1 + rec1(idx + c + 1); ans = max(ans, rec1(idx + 1)); return ans; } ll rec2(ll idx) { if (idx >= n) return 0; ll &ans = dp2[idx]; if (ans != -1) return ans; ans = 0; if (p[idx] == 'o') ans = 1 + rec2(idx + c + 1); ans = max(ans, rec2(idx + 1)); return ans; } int main() { IOS #ifdef SHAN freopen("input.txt", "r", stdin); #endif cin >> n >> k >> c; cin >> s; reverse(all(s)); p = s; reverse(all(s)); memset(dp, -1, sizeof dp); memset(dp2, -1, sizeof dp2); rec1(0); rec2(0); for (ll i = 0; i < n; i++) { if (s[i] == 'x') continue; ll curr = 0; ll ii = n - 1 - i; curr = rec1(i + 1); curr += rec2(ii + 1); // cout << rec1(i + 1) << " " << rec2(ii + 1) << endl; if (curr < k) res.pb(i + 1); } for (auto it : res) cout << it << endl; return 0; } // good night.
// shan61916 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double dll; #define mp make_pair #define pb push_back #define ff first #define ss second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define pll pair<ll, ll> #define all(x) x.begin(), x.end() #define vll vector<ll> const ll inf = (ll)(1e17 + 17); const ll mod = (ll)(1e9 + 7); vll res; string s, p; ll n, k, c; ll dp[200020], dp2[200020]; ll rec1(ll idx) { if (idx >= n) return 0; ll &ans = dp[idx]; if (ans != -1) return ans; ans = 0; if (s[idx] == 'o') ans = 1 + rec1(idx + c + 1); ans = max(ans, rec1(idx + 1)); return ans; } ll rec2(ll idx) { if (idx >= n) return 0; ll &ans = dp2[idx]; if (ans != -1) return ans; ans = 0; if (p[idx] == 'o') ans = 1 + rec2(idx + c + 1); ans = max(ans, rec2(idx + 1)); return ans; } int main() { IOS #ifdef SHAN freopen("input.txt", "r", stdin); #endif cin >> n >> k >> c; cin >> s; reverse(all(s)); p = s; reverse(all(s)); memset(dp, -1, sizeof dp); memset(dp2, -1, sizeof dp2); rec1(0); rec2(0); for (ll i = 0; i < n; i++) { if (s[i] == 'x') continue; ll curr = 0; ll ii = n - 1 - i; curr = rec1(i + 1); curr += rec2(ii + 1); // cout << rec1(i + 1) << " " << rec2(ii + 1) << endl; if (curr < k) res.pb(i + 1); } for (auto it : res) cout << it << endl; return 0; } // good night.
replace
25
26
25
26
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pl; typedef vector<pl> vp; const ll INF = 1001001001; const ll LINF = 1001001001001001001; const ll D4[] = {0, 1, 0, -1, 0}; const ll D8[] = {0, 1, 1, 0, -1, -1, 1, -1, 0}; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define rep(i, n) fore(i, 0, (n)-1) #define all(x) (x).begin(), (x).end() template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; void solve(long long N, long long K, long long C, std::string S) { vl candL; ll disa = -1; rep(i, N) { if (i > disa && S[i] == 'o') { candL.push_back(i); disa = i + C; } } if (candL[N - 1] > K) return; vl candR; disa = N; rep(ri, N) { ll i = N - 1 - ri; if (i < disa && S[i] == 'o') { candR.push_back(i); disa = i - C; } } reverse(all(candR)); rep(i, candL.size()) { if (candL[i] == candR[i]) { cout << candL[i] + 1 << endl; } } } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); long long C; scanf("%lld", &C); std::string S; std::cin >> S; solve(N, K, C, S); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pl; typedef vector<pl> vp; const ll INF = 1001001001; const ll LINF = 1001001001001001001; const ll D4[] = {0, 1, 0, -1, 0}; const ll D8[] = {0, 1, 1, 0, -1, -1, 1, -1, 0}; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define rep(i, n) fore(i, 0, (n)-1) #define all(x) (x).begin(), (x).end() template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; void solve(long long N, long long K, long long C, std::string S) { vl candL; ll disa = -1; rep(i, N) { if (i > disa && S[i] == 'o') { candL.push_back(i); disa = i + C; } } if (candL.size() > K) return; vl candR; disa = N; rep(ri, N) { ll i = N - 1 - ri; if (i < disa && S[i] == 'o') { candR.push_back(i); disa = i - C; } } reverse(all(candR)); rep(i, candL.size()) { if (candL[i] == candR[i]) { cout << candL[i] + 1 << endl; } } } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); long long C; scanf("%lld", &C); std::string S; std::cin >> S; solve(N, K, C, S); }
replace
136
137
136
137
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define mp make_pair int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); freopen("a.txt", "r", stdin); int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> good; for (int i = 0; i < n; ++i) { if (s[i] == 'o') { good.push_back(i); } } n = good.size(); vector<int> dp(n); for (int i = n - 1; i >= 0; --i) { int it = upper_bound(good.begin(), good.end(), good[i] + c) - good.begin(); if (it < good.size()) { dp[i] = dp[it] + 1; } else { dp[i] = 1; } } int when = -1e9, cnt = 0; for (int i = 0; i < n; ++i) { int L = upper_bound(good.begin(), good.end(), when + c) - good.begin(); L = max(L, i + 1); int add = 0; if (L < good.size()) add = dp[L]; if (add + cnt < k) { cout << good[i] + 1 << "\n"; } if (good[i] > when + c) { when = good[i]; cnt++; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define mp make_pair int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); // freopen("a.txt", "r", stdin); int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> good; for (int i = 0; i < n; ++i) { if (s[i] == 'o') { good.push_back(i); } } n = good.size(); vector<int> dp(n); for (int i = n - 1; i >= 0; --i) { int it = upper_bound(good.begin(), good.end(), good[i] + c) - good.begin(); if (it < good.size()) { dp[i] = dp[it] + 1; } else { dp[i] = 1; } } int when = -1e9, cnt = 0; for (int i = 0; i < n; ++i) { int L = upper_bound(good.begin(), good.end(), when + c) - good.begin(); L = max(L, i + 1); int add = 0; if (L < good.size()) add = dp[L]; if (add + cnt < k) { cout << good[i] + 1 << "\n"; } if (good[i] > when + c) { when = good[i]; cnt++; } } return 0; }
replace
13
14
13
14
-11
p02721
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define zero_pad(num) setfill('0') << std::right << setw(num) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<vector<int>> ans(2, vector<int>(k, -1)); int cnt = 0; rep(i, n) { if (s[i] == 'x') continue; else { ans[0][cnt] = i; i += c; cnt++; if (cnt >= n) break; } } cnt = k - 1; for (int i = n - 1; i >= 0; --i) { if (s[i] == 'x') continue; else { ans[1][cnt] = i; i -= c; cnt--; if (cnt < 0) break; } } rep(i, k) { if (ans[0][i] == ans[1][i]) cout << ans[0][i] + 1 << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define zero_pad(num) setfill('0') << std::right << setw(num) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<vector<int>> ans(2, vector<int>(k, -1)); int cnt = 0; rep(i, n) { if (s[i] == 'x') continue; else { ans[0][cnt] = i; i += c; cnt++; if (cnt >= k) break; } } cnt = k - 1; for (int i = n - 1; i >= 0; --i) { if (s[i] == 'x') continue; else { ans[1][cnt] = i; i -= c; cnt--; if (cnt < 0) break; } } rep(i, k) { if (ans[0][i] == ans[1][i]) cout << ans[0][i] + 1 << endl; } }
replace
22
23
22
23
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define mp make_pair #define pb push_back #define VI vector<int> #define pii pair<int, int> #define INF 0x3f3f3f3f using namespace std; const int MAXN = 1e5; char S[MAXN + 10]; int dp[2][MAXN + 10]; int n, k, x; int main() { scanf("%d %d %d", &n, &k, &x); scanf("%s", S); dp[0][0] = 0; for (int i = 1; i <= n; i++) { if (S[i - 1] == 'x') dp[0][i] = dp[0][i - 1]; else dp[0][i] = 1 + (i - x - 1 >= 0 ? dp[0][i - x - 1] : 0); } dp[1][n + 1] = 0; for (int i = n; i > 0; i--) { if (S[i - 1] == 'x') dp[1][i] = dp[1][i + 1]; else dp[1][i] = 1 + (i + x + 1 <= n + 1 ? dp[1][i + x + 1] : 0); } // for(int i = 1; i <= n; i++) printf("%d ", dp[1][i]); printf("\n"); for (int i = 0; i < n; i++) { if (dp[0][i] + dp[1][i + 2] < k) printf("%d\n", i + 1); } return 0; }
#include <bits/stdc++.h> #define ll long long #define mp make_pair #define pb push_back #define VI vector<int> #define pii pair<int, int> #define INF 0x3f3f3f3f using namespace std; const int MAXN = 2e5; char S[MAXN + 10]; int dp[2][MAXN + 10]; int n, k, x; int main() { scanf("%d %d %d", &n, &k, &x); scanf("%s", S); dp[0][0] = 0; for (int i = 1; i <= n; i++) { if (S[i - 1] == 'x') dp[0][i] = dp[0][i - 1]; else dp[0][i] = 1 + (i - x - 1 >= 0 ? dp[0][i - x - 1] : 0); } dp[1][n + 1] = 0; for (int i = n; i > 0; i--) { if (S[i - 1] == 'x') dp[1][i] = dp[1][i + 1]; else dp[1][i] = 1 + (i + x + 1 <= n + 1 ? dp[1][i + x + 1] : 0); } // for(int i = 1; i <= n; i++) printf("%d ", dp[1][i]); printf("\n"); for (int i = 0; i < n; i++) { if (dp[0][i] + dp[1][i + 2] < k) printf("%d\n", i + 1); } return 0; }
replace
8
9
8
9
0
p02721
C++
Runtime Error
#pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #include <bits/stdc++.h> using namespace std; #define len(x) (int)((x).size()) #define endl '\n' #define int long long #define x first #define y second #define dbg(x) cout << #x << " = " << x << endl; void solve(); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(10); solve(); return 0; } const int MOD = 998244353, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37; void solve() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; if (n == 1) { if (s[0] == 'x') { cout << 0 << endl; } else { cout << 1 << endl; } } vector<int> a; for (int i = 0; i < len(s); ++i) { if (s[i] == 'o') { a.push_back(i); } } vector<int> f1(len(a) + 1, INF), f2(len(a) + 1, -INF); f1[1] = a[0], f2[1] = a[len(a) - 1]; f1[0] = -1, f2[0] = a.back() + 1; int j = 1; for (int i = 1; i < len(a); ++i) { while (j < len(a) && a[j] - f1[i] <= c) { j++; } if (j == len(a)) continue; f1[i + 1] = a[j]; } int ll = 2; j = len(a) - 2; for (int i = 2; i <= len(a); ++i) { while (j >= 0 && f2[i - 1] - a[j] <= c) { j--; } if (j == -1) continue; f2[i] = a[j]; } // for (int i = 0; i <= k; ++i) { // cout << f1[i] << " "; // } // cout << endl; int ans = 0; vector<int> ps(MAXN); for (int i = 0; i <= k; ++i) { int l = f1[i] + 1, r = f2[k - i] - 1; // dbg(l << " " << r) if (i != 0 && i != k) { if (l <= r && l >= 0 && r - l + 1 >= c) { ps[l]++; ps[r + 1]--; } } else { if (l <= r && l >= 0) { ps[l]++; ps[r + 1]--; } } } for (int i = 1; i < MAXN; ++i) { ps[i] = ps[i - 1] + ps[i]; } vector<int> aans; for (auto it : a) { if (!ps[it]) { aans.push_back(it + 1); // cout << it + 1 << endl; } } if (len(aans) == k && len(a) == k) { assert(k != 1); } if (len(aans) <= k) { for (auto it : aans) { cout << it << endl; } } }
#pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #include <bits/stdc++.h> using namespace std; #define len(x) (int)((x).size()) #define endl '\n' #define int long long #define x first #define y second #define dbg(x) cout << #x << " = " << x << endl; void solve(); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(10); solve(); return 0; } const int MOD = 998244353, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37; void solve() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; if (n == 1) { if (s[0] == 'x') { cout << 0 << endl; } else { cout << 1 << endl; } } vector<int> a; for (int i = 0; i < len(s); ++i) { if (s[i] == 'o') { a.push_back(i); } } vector<int> f1(len(a) + 1, INF), f2(len(a) + 1, -INF); f1[1] = a[0], f2[1] = a[len(a) - 1]; f1[0] = -1, f2[0] = a.back() + 1; int j = 1; for (int i = 1; i < len(a); ++i) { while (j < len(a) && a[j] - f1[i] <= c) { j++; } if (j == len(a)) continue; f1[i + 1] = a[j]; } int ll = 2; j = len(a) - 2; for (int i = 2; i <= len(a); ++i) { while (j >= 0 && f2[i - 1] - a[j] <= c) { j--; } if (j == -1) continue; f2[i] = a[j]; } // for (int i = 0; i <= k; ++i) { // cout << f1[i] << " "; // } // cout << endl; int ans = 0; vector<int> ps(MAXN); for (int i = 0; i <= k; ++i) { int l = f1[i] + 1, r = f2[k - i] - 1; // dbg(l << " " << r) if (i != 0 && i != k) { if (l <= r && l >= 0 && r - l + 1 >= c) { ps[l]++; ps[r + 1]--; } } else { if (l <= r && l >= 0) { ps[l]++; ps[r + 1]--; } } } for (int i = 1; i < MAXN; ++i) { ps[i] = ps[i - 1] + ps[i]; } vector<int> aans; for (auto it : a) { if (!ps[it]) { aans.push_back(it + 1); // cout << it + 1 << endl; } } if (len(aans) == k && len(a) == k) { if (k == 1) return; } if (len(aans) <= k) { for (auto it : aans) { cout << it << endl; } } }
replace
117
118
117
119
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> left(k), right(k); int count = 0; for (int i = 0; i < n; i++) { if (s[i] == 'o') { left[count] = i + 1; count += 1; i += c; if (count == k) break; } } count = k - 1; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { right[count] = i + 1; count -= 1; i -= c; if (count == k) break; } } /* for(int i=0; i<k; i++) cout << left[i] << " "; cout << endl; for(int i=0; i<k; i++) cout << right[i] << " "; cout << endl; */ for (int i = 0; i < k; i++) { if (left[i] == right[i]) cout << left[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> left(k), right(k); int count = 0; for (int i = 0; i < n; i++) { if (s[i] == 'o') { left[count] = i + 1; count += 1; i += c; if (count == k) break; } } count = k - 1; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { right[count] = i + 1; count -= 1; i -= c; if (count == -1) break; } } /* for(int i=0; i<k; i++) cout << left[i] << " "; cout << endl; for(int i=0; i<k; i++) cout << right[i] << " "; cout << endl; */ for (int i = 0; i < k; i++) { if (left[i] == right[i]) cout << left[i] << endl; } return 0; }
replace
25
26
25
26
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> // typedef //-------------------------#include <bits/stdc++.h> const double pi = 3.141592653589793238462643383279; using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> P; typedef pair<int, int> pii; typedef vector<int> vi; const double EPS = 1E-8; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) class UnionFind { public: vector<int> par; vector<int> siz; UnionFind(int sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(int sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } int root(int x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; ll modPow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n) { if (n & 1) res = (res * x) % mod; res %= mod; x = x * x % mod; n >>= 1; } return res; } #define SIEVE_SIZE 5000000 + 10 bool sieve[SIEVE_SIZE]; void makeSieve() { for (int i = 0; i < SIEVE_SIZE; ++i) sieve[i] = true; sieve[0] = sieve[1] = false; for (int i = 2; i * i < SIEVE_SIZE; ++i) if (sieve[i]) for (int j = 2; i * j < SIEVE_SIZE; ++j) sieve[i * j] = false; } bool isprime(ll n) { if (n == 0 || n == 1) return false; for (ll i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } const int MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } // 負の数にも対応した mod (a = -11 とかでも OK) inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 逆元計算 (ここでは a と m が互いに素であることが必要) long long modinv(long long a, long long m) { long long x, y; extGCD(a, m, x, y); return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A, mat &B) { mat C(A.size(), vec((int)B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int k = 0; k < B.size(); ++k) { for (int j = 0; j < B[0].size(); ++j) { C[i][j] = (C[i][j] + A[i][k] % MOD * B[k][j] % MOD) % MOD; } } } return C; } mat matPow(mat A, ll n) { mat B(A.size(), vec((int)A.size())); for (int i = 0; i < A.size(); ++i) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(5); int N, K, C; cin >> N >> K >> C; string s; cin >> s; int arr[100010] = {0}; int pos = 0; int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'o') { if (i >= pos) { pos = i + C + 1; cnt++; arr[i]++; } } } if (cnt > K) { cout << endl; return 0; } pos = s.size() - 1; for (int i = s.size() - 1; i >= 0; --i) { if (s[i] == 'o') { if (i <= pos) { pos = i - C - 1; arr[i]++; } } } int mx = 0; for (int i = 0; i < s.size(); i++) { mx = max(mx, arr[i]); } vector<int> ans; for (int i = 0; i < s.size(); i++) { if (arr[i] == mx) { ans.push_back(i + 1); } } for (auto e : ans) { cout << e << endl; } return 0; }
#include <bits/stdc++.h> // typedef //-------------------------#include <bits/stdc++.h> const double pi = 3.141592653589793238462643383279; using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> P; typedef pair<int, int> pii; typedef vector<int> vi; const double EPS = 1E-8; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) class UnionFind { public: vector<int> par; vector<int> siz; UnionFind(int sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(int sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } int root(int x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; ll modPow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n) { if (n & 1) res = (res * x) % mod; res %= mod; x = x * x % mod; n >>= 1; } return res; } #define SIEVE_SIZE 5000000 + 10 bool sieve[SIEVE_SIZE]; void makeSieve() { for (int i = 0; i < SIEVE_SIZE; ++i) sieve[i] = true; sieve[0] = sieve[1] = false; for (int i = 2; i * i < SIEVE_SIZE; ++i) if (sieve[i]) for (int j = 2; i * j < SIEVE_SIZE; ++j) sieve[i * j] = false; } bool isprime(ll n) { if (n == 0 || n == 1) return false; for (ll i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } const int MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } // 負の数にも対応した mod (a = -11 とかでも OK) inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 逆元計算 (ここでは a と m が互いに素であることが必要) long long modinv(long long a, long long m) { long long x, y; extGCD(a, m, x, y); return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A, mat &B) { mat C(A.size(), vec((int)B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int k = 0; k < B.size(); ++k) { for (int j = 0; j < B[0].size(); ++j) { C[i][j] = (C[i][j] + A[i][k] % MOD * B[k][j] % MOD) % MOD; } } } return C; } mat matPow(mat A, ll n) { mat B(A.size(), vec((int)A.size())); for (int i = 0; i < A.size(); ++i) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(5); int N, K, C; cin >> N >> K >> C; string s; cin >> s; int arr[200010] = {0}; int pos = 0; int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'o') { if (i >= pos) { pos = i + C + 1; cnt++; arr[i]++; } } } if (cnt > K) { cout << endl; return 0; } pos = s.size() - 1; for (int i = s.size() - 1; i >= 0; --i) { if (s[i] == 'o') { if (i <= pos) { pos = i - C - 1; arr[i]++; } } } int mx = 0; for (int i = 0; i < s.size(); i++) { mx = max(mx, arr[i]); } vector<int> ans; for (int i = 0; i < s.size(); i++) { if (arr[i] == mx) { ans.push_back(i + 1); } } for (auto e : ans) { cout << e << endl; } return 0; }
replace
238
239
238
239
0
p02721
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 998244353; struct fast_io { fast_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; signed main() { cout << fixed << setprecision(10); int n, K, C; string s; vector<int> con1, con2, sum; vector<int> hoge1, hoge2; cin >> n >> K >> C; cin >> s; con1.resize(n + 1); con2.resize(n + 2); sum.resize(n + 1); hoge1.resize(n + 2, -1); hoge2.resize(n + 2, -1); for (int i = 0; i < n; i++) { sum[i + 1] = sum[i] + (s[i] == 'o'); } for (int i = 1; i <= n; i++) { int b = i - C - 1; int c = 0; if (b >= 0) c = con1[b]; con1[i] = max(con1[i - 1], (int)c + (s[i - 1] == 'o')); if (hoge1[con1[i]] == -1) hoge1[con1[i]] = i - 1; } for (int i = n; i >= 1; i--) { int b = i + C + 1; int c = 0; if (b <= n + 1) c = con2[b]; con2[i] = max(con2[i + 1], (int)c + (s[i - 1] == 'o')); if (hoge2[K - con2[i]] == -1) hoge2[K - con2[i]] = i - 1; } // cout<<"con1 n = "<<con1[n]<<endl; for (int i = 1, x = 0; i <= K; i++) { // cout<<"i = "<<i<<" hoge "<<hoge1[i] <<" "<<hoge2[i-1]<<endl; if (hoge1[i] == hoge2[i - 1] && hoge1[i] != -1) { cout << hoge1[i] + 1 << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 998244353; struct fast_io { fast_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; signed main() { cout << fixed << setprecision(10); int n, K, C; string s; vector<int> con1, con2, sum; vector<int> hoge1, hoge2; cin >> n >> K >> C; cin >> s; con1.resize(n + 1); con2.resize(n + 2); sum.resize(n + 1); hoge1.resize(n + 2, -1); hoge2.resize(n + 2, -1); for (int i = 0; i < n; i++) { sum[i + 1] = sum[i] + (s[i] == 'o'); } for (int i = 1; i <= n; i++) { int b = i - C - 1; int c = 0; if (b >= 0) c = con1[b]; con1[i] = max(con1[i - 1], (int)c + (s[i - 1] == 'o')); if (hoge1[con1[i]] == -1) hoge1[con1[i]] = i - 1; } if (con1[n] > K) { return 0; } for (int i = n; i >= 1; i--) { int b = i + C + 1; int c = 0; if (b <= n + 1) c = con2[b]; con2[i] = max(con2[i + 1], (int)c + (s[i - 1] == 'o')); if (hoge2[K - con2[i]] == -1) hoge2[K - con2[i]] = i - 1; } // cout<<"con1 n = "<<con1[n]<<endl; for (int i = 1, x = 0; i <= K; i++) { // cout<<"i = "<<i<<" hoge "<<hoge1[i] <<" "<<hoge2[i-1]<<endl; if (hoge1[i] == hoge2[i - 1] && hoge1[i] != -1) { cout << hoge1[i] + 1 << endl; } } return 0; }
insert
56
56
56
60
0
p02721
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define fir first #define sec second #define sz(s) (s).size() #define pb push_back #define get(n) scanf("%d", &n); #define gets(s) \ string s; \ cin >> (s); #define prfi(n) printf("%d", &n); #define prfd(n) printf("%lf", &n); #define All(s) (s).begin(), (s).end() #define rep(i, j) for (int(i) = 0; (i) < (j); (i)++) #define For(i, j, k) for (int(i) = (j); (i) < (k); (i)++) #define drep(i, j) for (int(i) = (j); (i) >= 0; (i)--) #define Ford(i, j, k) for (int(i) = (j); i >= (k); i--) #define vfor(c, v) for (auto(c) : (v)) #define lpi(n) for (int i = 0; i < (n); i++) #define lpj(n) for (int j = 0; j < (n); j++) #define lpz(n) for (int z = 0; z < (n); z++) #define mem(a, b) memset(a, b, sizeof(a)); #define dump(x) std::cout << #x << " = " << (x) << std::endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using ll = long long; using ld = long double; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double>; using vvd = std::vector<vd>; using qi = std::queue<int>; using vpii = std::vector<std::pair<int, int>>; using vpll = std::vector<pll>; using namespace std; const int Mod = (1e9) + 7; const int INF = 1e9 + 19; const ll INFL = 1e18 + 19; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const int dx2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; const int dy2[] = {1, 0, -1, 1, 0, -1, 1, 0, -1}; //_____________________________________Templates_________________________________________// template <class T1, class T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <class T> inline void swap(T &a, T &b) { T c = a; a = b; b = c; } template <class T> inline void pri(T a) { cout << a << endl; } template <class Z> using vec = vector<Z>; // mainly use for dynamic prog template <class T1, class T2> void update(T1 &a, T2 b) { a += b; if (a > Mod) a %= Mod; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } inline void OUT(void) { cout << "\n"; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } bool pairsort(pll pl, pll pr) { if (pl.first == pr.first) return pl.second > pr.second; return pl.first < pr.first; } int cntbit(ll a, int n, int j) { int res = 0; For(i, j, n) { if (a >> i & 1) { res++; } } return res; } vector<int> make_bit(int a) { vector<int> res; lpi(32) if (a & (1 << i)) res.pb(i); return res; } bool stdbit(int a, int b) { return a & (1 << b); } int GCD(int a, int b) { if (b > a) return GCD(b, a); if (a % b == 0) return b; else return GCD(b, a % b); } int LCM(int a, int b) { return a * b / GCD(a, b); } int roundup(int a, int b) { if (a % b == 0) return a / b; else return (a + b) / b; } int rounddown(int a, int b) { if (a % b == 0) return a / b; else { return (a - b) / b; } } //_____________________ following sorce code_________________________// const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; int n, m, k; int h, w; vvi dp; string S; int a, b, c; vi v; int main() { cin.tie(0); ios::sync_with_stdio(false); IN(n, k, w); IN(S); vi L(k + 1), R(k + 1); int v = 1; rep(i, n) { if (S[i] == 'o') { L[v] = i + 1; v++; i += w; } } v = k; drep(i, n - 1) { if (S[i] == 'o') { if (v > 0) R[v] = i + 1; v--; i -= w; } } rep(i, k) { if (R[i + 1] == L[i + 1]) cout << R[i + 1] << endl; } // for(auto c : ans){cout << c << endl;} // cout << fixed << setprecision(15) << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define fir first #define sec second #define sz(s) (s).size() #define pb push_back #define get(n) scanf("%d", &n); #define gets(s) \ string s; \ cin >> (s); #define prfi(n) printf("%d", &n); #define prfd(n) printf("%lf", &n); #define All(s) (s).begin(), (s).end() #define rep(i, j) for (int(i) = 0; (i) < (j); (i)++) #define For(i, j, k) for (int(i) = (j); (i) < (k); (i)++) #define drep(i, j) for (int(i) = (j); (i) >= 0; (i)--) #define Ford(i, j, k) for (int(i) = (j); i >= (k); i--) #define vfor(c, v) for (auto(c) : (v)) #define lpi(n) for (int i = 0; i < (n); i++) #define lpj(n) for (int j = 0; j < (n); j++) #define lpz(n) for (int z = 0; z < (n); z++) #define mem(a, b) memset(a, b, sizeof(a)); #define dump(x) std::cout << #x << " = " << (x) << std::endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using ll = long long; using ld = long double; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double>; using vvd = std::vector<vd>; using qi = std::queue<int>; using vpii = std::vector<std::pair<int, int>>; using vpll = std::vector<pll>; using namespace std; const int Mod = (1e9) + 7; const int INF = 1e9 + 19; const ll INFL = 1e18 + 19; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const int dx2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; const int dy2[] = {1, 0, -1, 1, 0, -1, 1, 0, -1}; //_____________________________________Templates_________________________________________// template <class T1, class T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <class T> inline void swap(T &a, T &b) { T c = a; a = b; b = c; } template <class T> inline void pri(T a) { cout << a << endl; } template <class Z> using vec = vector<Z>; // mainly use for dynamic prog template <class T1, class T2> void update(T1 &a, T2 b) { a += b; if (a > Mod) a %= Mod; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } inline void OUT(void) { cout << "\n"; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } bool pairsort(pll pl, pll pr) { if (pl.first == pr.first) return pl.second > pr.second; return pl.first < pr.first; } int cntbit(ll a, int n, int j) { int res = 0; For(i, j, n) { if (a >> i & 1) { res++; } } return res; } vector<int> make_bit(int a) { vector<int> res; lpi(32) if (a & (1 << i)) res.pb(i); return res; } bool stdbit(int a, int b) { return a & (1 << b); } int GCD(int a, int b) { if (b > a) return GCD(b, a); if (a % b == 0) return b; else return GCD(b, a % b); } int LCM(int a, int b) { return a * b / GCD(a, b); } int roundup(int a, int b) { if (a % b == 0) return a / b; else return (a + b) / b; } int rounddown(int a, int b) { if (a % b == 0) return a / b; else { return (a - b) / b; } } //_____________________ following sorce code_________________________// const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; int n, m, k; int h, w; vvi dp; string S; int a, b, c; vi v; int main() { cin.tie(0); ios::sync_with_stdio(false); IN(n, k, w); IN(S); vi L(k + 1), R(k + 1); int v = 1; rep(i, n) { if (S[i] == 'o') { if (v < k + 1) L[v] = i + 1; v++; i += w; } } v = k; drep(i, n - 1) { if (S[i] == 'o') { if (v > 0) R[v] = i + 1; v--; i -= w; } } rep(i, k) { if (R[i + 1] == L[i + 1]) cout << R[i + 1] << endl; } // for(auto c : ans){cout << c << endl;} // cout << fixed << setprecision(15) << ans << endl; return 0; }
replace
166
167
166
168
0
p02721
C++
Runtime Error
/* _____________________$$o____________________o$$$$$o__ ___________________o$o_$$o____oo$$$$$$$oo______o$$$$o ______________$o________o$$$$$o___oo$$$$$$$o______$$$ ______________$$$ooo________o$$$$o______o$$$$$o_____o ____________oo_____oo_____oo___o$$$$$______$$$$$$____ _________ooooo___$$o_$___oooooo___o$$$$o__o__o$$$$___ _______ooo__ooo$$$$o_$$ooooooooooo__o$$$o__oo_oo$$$o_ ______oo_o$$o_$$_o$o_o$o__oooooooooo__o$$$o_oo__o$$$o ____oooooo$$$$o___oo__$$o_ooo_oooooooo__o$$o_ooo_o$$$ ___ooooooo__o___oooo__$$ooooo$_oooooooo__o$$__ooo_$$$ _$$o_ooooo___o$$$$$o__o$o__o_$o__oooooooo_o$$o_oo__$$ _$$$o_ooo_________o$$_$$o____$$o_ooooooooo_$$$o_oo_$$ __oo________o$$o____o_$$o____o$ooooooooooo_o$$o_oo_o$ ___o$$$$$$$$$$$$$o___$$$o____$$o_oooooooooo_$$$o_o_o$ ________o__oo$$$$$o__$$$o____$$o____oooooo__$$$o_o_o$ _________$$$$$$$$$o__$$_____$$$o___________$$$oooooo_ __________o$$$$$$$o_________$$___________o$o___oooooo ___________o$$$$o_______________ooooo__oo$__ooo__oooo ________________________________ooo_$$oo___oooo$o____ ________________________________oooo_$$$$$o___oo$$$o_ ________________________________ooooo_o$$$$$o_____$$$ ________________________________oooooo_o$$$$$$ooo___o ________________________________ooooooo__o$$$$$o_____ */ #include <bits/stdc++.h> #define ll long long #define ft first #define sd second #define HageBaIO_KPOCCbI \ int LOL; \ scanf("%d", &LOL); \ for (int i = 0; i < LOL; i++) #define Terrorist \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; // BY |3 |< const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; // Where I am? const ll N = 1e5 + 5; const ll NN = 1e3 + 3; const ll MOD = (1e9 + 7); const ll MOD1 = 998244353; const double PI = 3.14159265; const int INF32 = 2e9; const ll INF64 = 2e18; // Don`t believe!!!// int n, k, c, dp[N], x, mn; map<int, vector<int>> mp; string s; void KEK() { cin >> n >> k >> c >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'o') { if (i <= c) dp[i] = 1; else dp[i] = max(dp[i - 1], dp[i - c - 1] + 1); if (dp[i] == k + 1) return; } else dp[i] = dp[i - 1]; } x = k; mn = n - 1; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'o') { if (dp[i] > x) mp[dp[i]].push_back(i + 1); else if (dp[i] == x && i <= mn) { mp[dp[i]].push_back(i + 1); mn -= c + 1; x--; } } if (mn == i) mn--; } for (int i = 1; i <= k; i++) if (mp[i].size() == 1) cout << mp[i][0] << endl; } int main() { Terrorist // HageBaIO_KPOCCbI KEK(); } // TAUMAC, 9| BbIWEJI 3A TObOU!!!
/* _____________________$$o____________________o$$$$$o__ ___________________o$o_$$o____oo$$$$$$$oo______o$$$$o ______________$o________o$$$$$o___oo$$$$$$$o______$$$ ______________$$$ooo________o$$$$o______o$$$$$o_____o ____________oo_____oo_____oo___o$$$$$______$$$$$$____ _________ooooo___$$o_$___oooooo___o$$$$o__o__o$$$$___ _______ooo__ooo$$$$o_$$ooooooooooo__o$$$o__oo_oo$$$o_ ______oo_o$$o_$$_o$o_o$o__oooooooooo__o$$$o_oo__o$$$o ____oooooo$$$$o___oo__$$o_ooo_oooooooo__o$$o_ooo_o$$$ ___ooooooo__o___oooo__$$ooooo$_oooooooo__o$$__ooo_$$$ _$$o_ooooo___o$$$$$o__o$o__o_$o__oooooooo_o$$o_oo__$$ _$$$o_ooo_________o$$_$$o____$$o_ooooooooo_$$$o_oo_$$ __oo________o$$o____o_$$o____o$ooooooooooo_o$$o_oo_o$ ___o$$$$$$$$$$$$$o___$$$o____$$o_oooooooooo_$$$o_o_o$ ________o__oo$$$$$o__$$$o____$$o____oooooo__$$$o_o_o$ _________$$$$$$$$$o__$$_____$$$o___________$$$oooooo_ __________o$$$$$$$o_________$$___________o$o___oooooo ___________o$$$$o_______________ooooo__oo$__ooo__oooo ________________________________ooo_$$oo___oooo$o____ ________________________________oooo_$$$$$o___oo$$$o_ ________________________________ooooo_o$$$$$o_____$$$ ________________________________oooooo_o$$$$$$ooo___o ________________________________ooooooo__o$$$$$o_____ */ #include <bits/stdc++.h> #define ll long long #define ft first #define sd second #define HageBaIO_KPOCCbI \ int LOL; \ scanf("%d", &LOL); \ for (int i = 0; i < LOL; i++) #define Terrorist \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; // BY |3 |< const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; // Where I am? const ll N = 2e5 + 5; const ll NN = 1e3 + 3; const ll MOD = (1e9 + 7); const ll MOD1 = 998244353; const double PI = 3.14159265; const int INF32 = 2e9; const ll INF64 = 2e18; // Don`t believe!!!// int n, k, c, dp[N], x, mn; map<int, vector<int>> mp; string s; void KEK() { cin >> n >> k >> c >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'o') { if (i <= c) dp[i] = 1; else dp[i] = max(dp[i - 1], dp[i - c - 1] + 1); if (dp[i] == k + 1) return; } else dp[i] = dp[i - 1]; } x = k; mn = n - 1; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'o') { if (dp[i] > x) mp[dp[i]].push_back(i + 1); else if (dp[i] == x && i <= mn) { mp[dp[i]].push_back(i + 1); mn -= c + 1; x--; } } if (mn == i) mn--; } for (int i = 1; i <= k; i++) if (mp[i].size() == 1) cout << mp[i][0] << endl; } int main() { Terrorist // HageBaIO_KPOCCbI KEK(); } // TAUMAC, 9| BbIWEJI 3A TObOU!!!
replace
42
43
42
43
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; int main() { int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> P, Q, ans; for (int i = 0; i < n; i++) { if (s[i] == 'o') { P.push_back(i + 1); i += c; } } reverse(s.begin(), s.end()); for (int i = 0; i < n; i++) { if (s[i] == 'o') { Q.push_back(n - i); i += c; } } if (P.size() != k || Q.size() != k) { return 0; } else { sort(P.begin(), P.end()); sort(Q.begin(), Q.end()); int i = 0, j = 0; while (i != P.size() || j != Q.size()) { if (P[i] > Q[j]) j++; else if (P[i] == Q[j]) { ans.push_back(P[i]); i++, j++; } else i++; } rep(k, ans.size()) cout << ans[k] << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; int main() { int n, k, c; string s; cin >> n >> k >> c >> s; vector<int> P, Q, ans; for (int i = 0; i < n; i++) { if (s[i] == 'o') { P.push_back(i + 1); i += c; } } reverse(s.begin(), s.end()); for (int i = 0; i < n; i++) { if (s[i] == 'o') { Q.push_back(n - i); i += c; } } if (P.size() != k || Q.size() != k) { return 0; } else { sort(P.begin(), P.end()); sort(Q.begin(), Q.end()); int i = 0, j = 0; while (i != P.size() && j != Q.size()) { if (P[i] > Q[j]) j++; else if (P[i] == Q[j]) { ans.push_back(P[i]); i++, j++; } else i++; } rep(k, ans.size()) cout << ans[k] << endl; } }
replace
32
33
32
33
-11
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll maxs = 2e5 + 5; const ll lmaxs = 20; ll mod = 1e9 + 7; ll oo = 1e15; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define pb push_back #define mp make_pair #define ff first #define ss second #define I insert #define endl '\n' void pre() {} void solve() { ll n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<ll> a, b; for (ll i = 0; i < n; i++) { if (s[i] == 'o') { a.pb(i); i += c; } } for (ll i = n - 1; i >= 0; i--) { if (s[i] == 'o') { b.pb(i); i -= c; } } // reverse(b.begin(),b.end()); vector<ll> ANS; for (ll i = 0; i < k; i++) { if (a[i] == b[k - i - 1]) { ANS.pb(a[i] + 1); } } for (auto it : ANS) cout << it << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input00.txt", "r", stdin); #endif IOS; pre(); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll maxs = 2e5 + 5; const ll lmaxs = 20; ll mod = 1e9 + 7; ll oo = 1e15; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define pb push_back #define mp make_pair #define ff first #define ss second #define I insert #define endl '\n' void pre() {} void solve() { ll n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<ll> a, b; for (ll i = 0; i < n; i++) { if (s[i] == 'o') { a.pb(i); i += c; } } for (ll i = n - 1; i >= 0; i--) { if (s[i] == 'o') { b.pb(i); i -= c; } } // reverse(b.begin(),b.end()); vector<ll> ANS; for (ll i = 0; i < k; i++) { if (a[i] == b[k - i - 1]) { ANS.pb(a[i] + 1); } } for (auto it : ANS) cout << it << endl; } int main() { IOS; pre(); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
replace
53
56
53
54
-11
p02721
C++
Runtime Error
/*Code by Codercjh*/ #include <bits/stdc++.h> #define fr(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, a, b) for (int i = (a); i >= (b); --i) #define min(a, b) (a < b ? a : b) #define max(a, b) (a > b ? a : b) using namespace std; typedef long long ll; template <typename T> inline void read(T &x) { char c = getchar(); T fh = 0; bool f = false; while (!isdigit(c)) f |= (c == '-'), c = getchar(); while (isdigit(c)) fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar(); x = f ? -fh : fh; return; } int n, k, c, cnt, ans; char s[200005]; int l[200005], r[200005]; int main() { read(n), read(k), read(c); cin >> s + 1; fr(i, 1, n) if (s[i] == 'o') l[++cnt] = i, i += c; int cnt1 = k; rf(i, n, 1) if (s[i] == 'o') r[cnt1--] = i, i -= c; fr(i, 1, k) if (l[i] == r[i]) printf("%d\n", l[i]); return 0; }
/*Code by Codercjh*/ #include <bits/stdc++.h> #define fr(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, a, b) for (int i = (a); i >= (b); --i) #define min(a, b) (a < b ? a : b) #define max(a, b) (a > b ? a : b) using namespace std; typedef long long ll; template <typename T> inline void read(T &x) { char c = getchar(); T fh = 0; bool f = false; while (!isdigit(c)) f |= (c == '-'), c = getchar(); while (isdigit(c)) fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar(); x = f ? -fh : fh; return; } int n, k, c, cnt, ans; char s[200005]; int l[200005], r[200005]; int main() { read(n), read(k), read(c); cin >> s + 1; fr(i, 1, n) if (s[i] == 'o') l[++cnt] = i, i += c; int cnt1 = k; rf(i, n, 1) { if (s[i] == 'o') r[cnt1--] = i, i -= c; if (!cnt1) break; } fr(i, 1, k) if (l[i] == r[i]) printf("%d\n", l[i]); return 0; }
replace
27
28
27
33
0
p02721
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<bool> ans(n, false); // 働かなくてもいい日はtrue vector<int> work; int prev = -c - 1; for (int i = 0; i < n; i++) { if (s[i] == 'o') { if (prev + c < i && work.size() < k) { work.push_back(i); prev = i; } else { ans[i] = true; } } } int idx = k - 1; prev = n + c + 1; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'x') continue; if (i > work[idx]) { if (i + c < prev) { ans[work[idx]] = true; prev = i; idx--; } } else if (i == work[idx]) { idx--; prev = i; } } for (int i = 0; i < n; i++) { if (s[i] == 'o' && ans[i] == false) { cout << i + 1 << '\n'; } } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<bool> ans(n, false); // 働かなくてもいい日はtrue vector<int> work; int prev = -c - 1; for (int i = 0; i < n; i++) { if (s[i] == 'o') { if (prev + c < i && work.size() < k) { work.push_back(i); prev = i; } else { ans[i] = true; } } } int idx = k - 1; prev = n + c + 1; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'x') continue; if (i > work[idx]) { if (i + c < prev) { ans[work[idx]] = true; prev = i; idx--; } } else if (i == work[idx]) { idx--; prev = i; } if (idx == -1) break; } for (int i = 0; i < n; i++) { if (s[i] == 'o' && ans[i] == false) { cout << i + 1 << '\n'; } } return 0; }
insert
59
59
59
62
0
p02721
C++
Runtime Error
#include <algorithm> #include <queue> #include <stdio.h> #include <vector> using namespace std; typedef long long LL; const int maxn = 100000 + 10; int L[maxn][2], R[maxn][2]; char str[maxn]; int main() { int i, j, n, K, C; scanf("%d%d%d", &n, &K, &C); scanf("%s", str + 1); for (i = 1; i <= n; i++) { if (str[i] == 'x') { L[i][0] = max(L[i - 1][0], L[i - 1][1]); L[i][1] = L[i][0]; } else { L[i][0] = max(L[i - 1][0], L[i - 1][1]); int v = 0; if (i - C > 1) v = L[i - C - 1][1]; L[i][1] = v + 1; } L[i][0] = max(L[i][0], L[i - 1][0]); L[i][1] = max(L[i][1], L[i - 1][1]); // printf("i=%d L0=%d L1=%d\n",i,L[i][0],L[i][1]); } for (i = n; i >= 1; i--) { if (str[i] == 'x') { R[i][0] = max(R[i + 1][0], R[i + 1][1]); R[i][1] = R[i][0]; } else { R[i][0] = max(R[i + 1][0], R[i + 1][1]); int v = 0; if (i + C + 1 <= n) v = max(R[i + C + 1][1], R[i + C + 1][1]); R[i][1] = v + 1; } R[i][0] = max(R[i][0], R[i + 1][0]); R[i][1] = max(R[i][1], R[i + 1][1]); // printf("i=%d R0=%d R1=%d\n",i,R[i][0],R[i][1]); } for (i = 1; i <= n; i++) { if (str[i] == 'x') continue; if (L[i][0] + R[i][0] == K - 1) printf("%d\n", i); } return 0; }
#include <algorithm> #include <queue> #include <stdio.h> #include <vector> using namespace std; typedef long long LL; const int maxn = 200000 + 10; int L[maxn][2], R[maxn][2]; char str[maxn]; int main() { int i, j, n, K, C; scanf("%d%d%d", &n, &K, &C); scanf("%s", str + 1); for (i = 1; i <= n; i++) { if (str[i] == 'x') { L[i][0] = max(L[i - 1][0], L[i - 1][1]); L[i][1] = L[i][0]; } else { L[i][0] = max(L[i - 1][0], L[i - 1][1]); int v = 0; if (i - C > 1) v = L[i - C - 1][1]; L[i][1] = v + 1; } L[i][0] = max(L[i][0], L[i - 1][0]); L[i][1] = max(L[i][1], L[i - 1][1]); // printf("i=%d L0=%d L1=%d\n",i,L[i][0],L[i][1]); } for (i = n; i >= 1; i--) { if (str[i] == 'x') { R[i][0] = max(R[i + 1][0], R[i + 1][1]); R[i][1] = R[i][0]; } else { R[i][0] = max(R[i + 1][0], R[i + 1][1]); int v = 0; if (i + C + 1 <= n) v = max(R[i + C + 1][1], R[i + C + 1][1]); R[i][1] = v + 1; } R[i][0] = max(R[i][0], R[i + 1][0]); R[i][1] = max(R[i][1], R[i + 1][1]); // printf("i=%d R0=%d R1=%d\n",i,R[i][0],R[i][1]); } for (i = 1; i <= n; i++) { if (str[i] == 'x') continue; if (L[i][0] + R[i][0] == K - 1) printf("%d\n", i); } return 0; }
replace
7
8
7
8
0
p02721
C++
Runtime Error
#include <cstdio> #include <iostream> #include <stack> using namespace std; typedef long long ll; ll n, k, c, lst; bool flag; string s; ll cnt; bool vis[100010]; stack<int> stk; int main() { cin >> n >> k >> c; cin >> s; lst = -1; for (int i = 0; i < (int)(s.length()); i++) { if (s[i] == 'x' || lst >= i) continue; if (cnt >= k) { flag = 1; break; } lst = i + c; vis[i] = 1; cnt++; } if (flag) { return 0; } lst = s.length(); for (int i = (int)s.length() - 1; i >= 0; i--) { if (s[i] == 'x' || lst <= i) continue; lst = i - c; if (vis[i]) { stk.push(i); } } while (!stk.empty()) { cout << stk.top() + 1 << endl; ; stk.pop(); } return 0; }
#include <cstdio> #include <iostream> #include <stack> using namespace std; typedef long long ll; ll n, k, c, lst; bool flag; string s; ll cnt; bool vis[200010]; stack<int> stk; int main() { cin >> n >> k >> c; cin >> s; lst = -1; for (int i = 0; i < (int)(s.length()); i++) { if (s[i] == 'x' || lst >= i) continue; if (cnt >= k) { flag = 1; break; } lst = i + c; vis[i] = 1; cnt++; } if (flag) { return 0; } lst = s.length(); for (int i = (int)s.length() - 1; i >= 0; i--) { if (s[i] == 'x' || lst <= i) continue; lst = i - c; if (vis[i]) { stk.push(i); } } while (!stk.empty()) { cout << stk.top() + 1 << endl; ; stk.pop(); } return 0; }
replace
9
10
9
10
0
p02721
C++
Runtime Error
#include <algorithm> #include <array> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> buf; int main(int argc, char *argv[]) { int N, K, C; string s; cin >> N >> K >> C; cin >> s; buf.resize(K, -1); int num = K; int cur = N - 1; while (cur >= 0) { if (s[cur] == 'x') { --cur; continue; } buf[--num] = cur; if (num == 0) { break; } cur -= C + 1; } cur = 0; num = 0; while (cur < N) { if (s[cur] == 'x') { ++cur; continue; } if (buf[num++] == cur) { cout << cur + 1 << endl; } if (num == N) { break; } cur += C + 1; } }
#include <algorithm> #include <array> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> buf; int main(int argc, char *argv[]) { int N, K, C; string s; cin >> N >> K >> C; cin >> s; buf.resize(K, -1); int num = K; int cur = N - 1; while (cur >= 0) { if (s[cur] == 'x') { --cur; continue; } buf[--num] = cur; if (num == 0) { break; } cur -= C + 1; } cur = 0; num = 0; while (cur < N) { if (s[cur] == 'x') { ++cur; continue; } if (buf[num++] == cur) { cout << cur + 1 << endl; } if (num == K) { break; } cur += C + 1; } }
replace
50
51
50
51
0
p02721
C++
Time Limit Exceeded
/** * author: qodjf * created: 04.21.2020 00:39:18 */ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif #define mst(x, a) memset(x, a, sizeof(x)) using ll = long long; using P = pair<int, int>; using T = tuple<int, int, int>; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const ll MOD = 1e9 + 7; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int main() { int N, K, C; cin >> N >> K >> C; string s; cin >> s; vector<int> dpleft(N + C + 10, 0), dpright(N + C + 10, 0); for (int i = 0; i < N; i++) { if (s[i] == 'x') { dpleft[i + C + 1] = dpleft[i + C]; } else { dpleft[i + C + 1] = max(dpleft[i + C], 1 + dpleft[i]); } } for (int i = N - 1; i >= 0; i--) { if (s[i] == 'x') { dpright[i] = dpright[i + 1]; } else { dpright[i] = max(dpright[i + 1], 1 + dpright[i + C + 1]); } } dbg(dpleft, dpright); vector<bool> ans(N, true); if (C == 0) { for (int i = 0; i < N; i++) { if (dpleft[i] + dpright[i + 1] >= K) { ans[i] = false; } } } else { int rightmost = 0; for (int rb = 1; rb <= N + C; rb++) { if (dpleft[rb] + dpright[rb] >= K) { for (int j = max(rb - C, rightmost); j < min(N, rb); j++) { ans[j] = false; } } } } for (int i = 0; i < N; i++) { if (s[i] == 'o' && ans[i]) { cout << i + 1 << endl; } } }
/** * author: qodjf * created: 04.21.2020 00:39:18 */ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif #define mst(x, a) memset(x, a, sizeof(x)) using ll = long long; using P = pair<int, int>; using T = tuple<int, int, int>; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const ll MOD = 1e9 + 7; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int main() { int N, K, C; cin >> N >> K >> C; string s; cin >> s; vector<int> dpleft(N + C + 10, 0), dpright(N + C + 10, 0); for (int i = 0; i < N; i++) { if (s[i] == 'x') { dpleft[i + C + 1] = dpleft[i + C]; } else { dpleft[i + C + 1] = max(dpleft[i + C], 1 + dpleft[i]); } } for (int i = N - 1; i >= 0; i--) { if (s[i] == 'x') { dpright[i] = dpright[i + 1]; } else { dpright[i] = max(dpright[i + 1], 1 + dpright[i + C + 1]); } } dbg(dpleft, dpright); vector<bool> ans(N, true); if (C == 0) { for (int i = 0; i < N; i++) { if (dpleft[i] + dpright[i + 1] >= K) { ans[i] = false; } } } else { int rightmost = 0; for (int rb = 1; rb <= N + C; rb++) { if (dpleft[rb] + dpright[rb] >= K) { for (int j = max(rb - C, rightmost); j < min(N, rb); j++) { ans[j] = false; } rightmost = rb; } } } for (int i = 0; i < N; i++) { if (s[i] == 'o' && ans[i]) { cout << i + 1 << endl; } } }
insert
92
92
92
93
TLE
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int64_t> memo; int64_t greedy(const string &s, int64_t index, int64_t C) { if (index >= s.size() || memo[index] != -1) { return memo[index]; } for (int64_t i = index; i < s.size(); i++) { if (s[i] == 'o') { return memo[index] = (1 + greedy(s, i + C + 1, C)); } } return memo[index] = 0; } int main() { int64_t N, K, C; string S; cin >> N >> K >> C >> S; memo.resize(N + 1, -1); vector<int64_t> ans; for (int64_t i = 0; i < S.size(); i++) { if (S[i] == 'x') { continue; } // S[i] == 'o' // ここが必須かどうか // S[i] = 'x'として判定してみる // ダメなら必須 int64_t num = greedy(S, i + 1, C); if (num < K) { ans.push_back(i + 1); } // ここをオフにしない場合、絶対に選ぶのが得 K--; i += C; } for (int64_t value : ans) { cout << value << endl; } }
#include <bits/stdc++.h> using namespace std; vector<int64_t> memo; int64_t greedy(const string &s, int64_t index, int64_t C) { if (index >= s.size()) { return 0; } if (memo[index] != -1) { return memo[index]; } for (int64_t i = index; i < s.size(); i++) { if (s[i] == 'o') { return memo[index] = (1 + greedy(s, i + C + 1, C)); } } return memo[index] = 0; } int main() { int64_t N, K, C; string S; cin >> N >> K >> C >> S; memo.resize(N + 1, -1); vector<int64_t> ans; for (int64_t i = 0; i < S.size(); i++) { if (S[i] == 'x') { continue; } // S[i] == 'o' // ここが必須かどうか // S[i] = 'x'として判定してみる // ダメなら必須 int64_t num = greedy(S, i + 1, C); if (num < K) { ans.push_back(i + 1); } // ここをオフにしない場合、絶対に選ぶのが得 K--; i += C; } for (int64_t value : ans) { cout << value << endl; } }
replace
6
7
6
10
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int INF = 100000; int main() { int N, K, C; cin >> N >> K >> C; string S; cin >> S; vector<int> G, G2; int p = -INF; for (int i = 0; i < N; i++) { if (S[i] == 'o' && i > p + C) { G.push_back(i); p = i; } if (G.size() == K) { break; } } p = INF; for (int i = N - 1; i >= 0; i--) { if (S[i] == 'o' && i < p - C) { G2.push_back(i); p = i; } if (G2.size() == K) { break; } } reverse(G2.begin(), G2.end()); for (int i = 0; i < K; i++) { if (G[i] == G2[i]) { cout << G[i] + 1 << endl; } } }
#include <bits/stdc++.h> using namespace std; int INF = 1000000; int main() { int N, K, C; cin >> N >> K >> C; string S; cin >> S; vector<int> G, G2; int p = -INF; for (int i = 0; i < N; i++) { if (S[i] == 'o' && i > p + C) { G.push_back(i); p = i; } if (G.size() == K) { break; } } p = INF; for (int i = N - 1; i >= 0; i--) { if (S[i] == 'o' && i < p - C) { G2.push_back(i); p = i; } if (G2.size() == K) { break; } } reverse(G2.begin(), G2.end()); for (int i = 0; i < K; i++) { if (G[i] == G2[i]) { cout << G[i] + 1 << endl; } } }
replace
2
3
2
3
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; int l[101010], r[101010]; int main() { int N, K, C; cin >> N >> K >> C; string S; cin >> S; int cur = 1; for (int i = 0; i < N; ++i) { if (S[i] == 'o') { l[i] = cur++; i += C; } if (cur > K) break; } cur = K; for (int i = N - 1; i >= 0; --i) { if (S[i] == 'o') { r[i] = cur--; i -= C; } if (cur < 0) break; } for (int i = 0; i < N; ++i) { // cout << l[i] << ", " << r[i] << endl; if (l[i] > 0 and l[i] == r[i]) { cout << i + 1 << endl; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; int l[201010], r[201010]; int main() { int N, K, C; cin >> N >> K >> C; string S; cin >> S; int cur = 1; for (int i = 0; i < N; ++i) { if (S[i] == 'o') { l[i] = cur++; i += C; } if (cur > K) break; } cur = K; for (int i = N - 1; i >= 0; --i) { if (S[i] == 'o') { r[i] = cur--; i -= C; } if (cur < 0) break; } for (int i = 0; i < N; ++i) { // cout << l[i] << ", " << r[i] << endl; if (l[i] > 0 and l[i] == r[i]) { cout << i + 1 << endl; } } }
replace
6
7
6
7
0
p02721
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define REP(i, n) FOR(i, 0, n - 1) #define NREP(i, n) FOR(i, 1, n) using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const ll dx[4] = {0, -1, 1, 0}; const ll dy[4] = {-1, 0, 0, 1}; const ll INF = 1e9 + 7; int gcd(int x, int y) { if (x < y) swap(x, y); if (y == 0) return x; return gcd(y, x % y); } void mul(ll a, ll b) { a = a * b % INF; } using Graph = vector<vector<int>>; ll mypow(ll x, ll n, ll m) { if (n == 0) { return 1; } if (n % 2 == 0) { return mypow(x * x % m, n / 2, m); } else { return x * mypow(x, n - 1, m) % m; } } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } const int MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルをつくる前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; // mod pにおける1,2,,,nの逆元 for (int i = 2; i < MAX; ++i) { fac[i] = fac[i - 1] * i % INF; inv[i] = INF - inv[INF % i] * (INF / i) % INF; finv[i] = finv[i - 1] * inv[i] % INF; } } ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % INF) % INF; } /////////////////////////////////////// // 期間内に働く日数を最大化するには前から貪欲に働く日を決めるのが最適 // したがって前から貪欲に働く日を決めた場合を考えることでx回目に働く日はL[x]日目以降 // という配列Lを求めることができる // 同様に後ろから貪欲に働く日を決めた場合を考えることでx回目に働く日はR[x]日目以前 // という配列を作ることができる // i日目に必ず働くのはL[x]=R[x]=iとなるxが存在するときに限る int L[200010]; int R[200010]; int main() { int N, K, C; string S; cin >> N >> K >> C; cin >> S; int cnt = 1; int now = 0; while (cnt <= K) { if (S[now] == 'o') { L[cnt] = now; cnt++; now += C + 1; } else { now++; } } int cnt2 = K; int now2 = N - 1; while (cnt2 > 0) { if (S[now2] == 'o') { R[cnt2] = now2; now2 -= (C + 1); cnt2--; } else { now2--; } } vector<int> ans; for (int i = 1; i <= K; ++i) { if (L[i] == R[i]) { ans.push_back(L[i] + 1); } } REP(i, ans.size()) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define REP(i, n) FOR(i, 0, n - 1) #define NREP(i, n) FOR(i, 1, n) using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const ll dx[4] = {0, -1, 1, 0}; const ll dy[4] = {-1, 0, 0, 1}; const ll INF = 1e9 + 7; int gcd(int x, int y) { if (x < y) swap(x, y); if (y == 0) return x; return gcd(y, x % y); } void mul(ll a, ll b) { a = a * b % INF; } using Graph = vector<vector<int>>; ll mypow(ll x, ll n, ll m) { if (n == 0) { return 1; } if (n % 2 == 0) { return mypow(x * x % m, n / 2, m); } else { return x * mypow(x, n - 1, m) % m; } } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } const int MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルをつくる前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; // mod pにおける1,2,,,nの逆元 for (int i = 2; i < MAX; ++i) { fac[i] = fac[i - 1] * i % INF; inv[i] = INF - inv[INF % i] * (INF / i) % INF; finv[i] = finv[i - 1] * inv[i] % INF; } } ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % INF) % INF; } /////////////////////////////////////// // 期間内に働く日数を最大化するには前から貪欲に働く日を決めるのが最適 // したがって前から貪欲に働く日を決めた場合を考えることでx回目に働く日はL[x]日目以降 // という配列Lを求めることができる // 同様に後ろから貪欲に働く日を決めた場合を考えることでx回目に働く日はR[x]日目以前 // という配列を作ることができる // i日目に必ず働くのはL[x]=R[x]=iとなるxが存在するときに限る int L[200010]; int R[200010]; int main() { int N, K, C; string S; cin >> N >> K >> C; cin >> S; int cnt = 1; int now = 0; while (cnt <= K) { if (S[now] == 'o') { L[cnt] = now; cnt++; now += C + 1; } else { now++; } } int cnt2 = K; int now2 = N - 1; while (cnt2 > 0) { if (S[now2] == 'o') { R[cnt2] = now2; now2 -= (C + 1); cnt2--; } else { now2--; } } vector<int> ans; for (int i = 1; i <= K; ++i) { if (L[i] == R[i]) { ans.push_back(L[i] + 1); } } if (ans.size() != 0) { REP(i, ans.size()) { cout << ans[i] << endl; } } return 0; }
replace
126
127
126
129
0
p02721
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using ll = long long int; using namespace std; int main() { // read problem ll N, K, C; string S; cin >> N >> K >> C >> S; // calculate dp1, dp2 vector<ll> dp1(N), dp2(N); ll tmp_pos, tmp_count; tmp_pos = -C - 1; tmp_count = 0; for (ll i = 0; i < N; i++) { if (S[i] == 'o' && i > tmp_pos + C) { tmp_count++; tmp_pos = i; } dp1[i] = tmp_count; } cerr << "dp1:" << endl; for (ll i = 0; i < N; i++) { cerr << dp1[i] << " "; } cerr << endl; tmp_pos = N + C; tmp_count = 0; for (ll i = N - 1; i >= 0; i--) { if (S[i] == 'o' && i < tmp_pos - C) { tmp_count++; tmp_pos = i; } dp2[i] = tmp_count; } cerr << "dp2: " << endl; for (ll i = 0; i < N; i++) { cerr << dp2[i] << " "; } cerr << endl; // solve problem if (C == 0) { ll count_o = 0; for (ll i = 0; i < N; i++) { if (S[i] == 'o') { count_o++; } } if (count_o <= K) { for (ll i = 0; i < N; i++) { if (S[i] == 'o') { cout << i + 1 << endl; } } return 0; } else { return 0; } } vector<ll> vac_list; if (N > C && dp2[C] >= K) { vac_list.push_back(0); } for (ll i = 1; i < N - C; i++) { if (dp1[i - 1] + dp2[i + C] >= K) { vac_list.push_back(i); } } if (N > C && dp1[N - C - 1] >= K) { vac_list.push_back(N - C); } ll nvac = vac_list.size(); ll l, r, mid; cerr << "nvac: " << nvac << endl; for (ll i = 0; i < nvac; i++) { cerr << vac_list[i] << " "; } cerr << endl; cerr << "Answer:" << endl; for (ll i = 0; i < N; i++) { if (S[i] == 'x') { continue; } if (vac_list[0] > i) { l = 0; } else if (vac_list[nvac - 1] <= i) { l = nvac - 1; } else { l = 0; r = nvac - 1; while (r - l > 1) { mid = (l + r) / 2; if (vac_list[mid] <= i) { l = mid; } else { r = mid; } } } l = vac_list[l]; if (l <= i && l > i - C) { continue; } if (i < N - 1 && dp2[i + 1] >= K) { continue; } if (i != 0 && dp1[i - 1] >= K) { continue; } cout << i + 1 << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using ll = long long int; using namespace std; int main() { // read problem ll N, K, C; string S; cin >> N >> K >> C >> S; // calculate dp1, dp2 vector<ll> dp1(N), dp2(N); ll tmp_pos, tmp_count; tmp_pos = -C - 1; tmp_count = 0; for (ll i = 0; i < N; i++) { if (S[i] == 'o' && i > tmp_pos + C) { tmp_count++; tmp_pos = i; } dp1[i] = tmp_count; } cerr << "dp1:" << endl; for (ll i = 0; i < N; i++) { cerr << dp1[i] << " "; } cerr << endl; tmp_pos = N + C; tmp_count = 0; for (ll i = N - 1; i >= 0; i--) { if (S[i] == 'o' && i < tmp_pos - C) { tmp_count++; tmp_pos = i; } dp2[i] = tmp_count; } cerr << "dp2: " << endl; for (ll i = 0; i < N; i++) { cerr << dp2[i] << " "; } cerr << endl; // solve problem if (C == 0) { ll count_o = 0; for (ll i = 0; i < N; i++) { if (S[i] == 'o') { count_o++; } } if (count_o <= K) { for (ll i = 0; i < N; i++) { if (S[i] == 'o') { cout << i + 1 << endl; } } return 0; } else { return 0; } } vector<ll> vac_list; if (N > C && dp2[C] >= K) { vac_list.push_back(0); } for (ll i = 1; i < N - C; i++) { if (dp1[i - 1] + dp2[i + C] >= K) { vac_list.push_back(i); } } if (N > C && dp1[N - C - 1] >= K) { vac_list.push_back(N - C); } ll nvac = vac_list.size(); ll l, r, mid; cerr << "nvac: " << nvac << endl; for (ll i = 0; i < nvac; i++) { cerr << vac_list[i] << " "; } cerr << endl; cerr << "Answer:" << endl; if (nvac == 0) { for (long long int i = 0; i < N; i++) { if (i != N - 1 && dp2[i + 1] >= K) { continue; } if (i != 0 && dp1[i - 1] >= K) { continue; } cout << i + 1 << endl; } return 0; } for (ll i = 0; i < N; i++) { if (S[i] == 'x') { continue; } if (vac_list[0] > i) { l = 0; } else if (vac_list[nvac - 1] <= i) { l = nvac - 1; } else { l = 0; r = nvac - 1; while (r - l > 1) { mid = (l + r) / 2; if (vac_list[mid] <= i) { l = mid; } else { r = mid; } } } l = vac_list[l]; if (l <= i && l > i - C) { continue; } if (i < N - 1 && dp2[i + 1] >= K) { continue; } if (i != 0 && dp1[i - 1] >= K) { continue; } cout << i + 1 << endl; } return 0; }
insert
102
102
102
114
0
dp1: 1 1 1 1 1 2 2 2 2 3 3 dp2: 3 3 2 2 2 2 1 1 1 1 1 nvac: 6 1 2 3 6 7 8 Answer:
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; vector<int> a, b; cin >> n >> k >> c; string s; cin >> s; for (int i = 0; i < n; i++) if (s[i] == 'o') { a.push_back(i); i += c; }; for (int i = n - 1; i > 0; i--) if (s[i] == 'o') { b.push_back(i); i -= c; }; for (int i = 0; i < k; i++) if (a[i] == b[k - i - 1]) { cout << a[i] + 1 << '\n'; }; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; vector<int> a, b; cin >> n >> k >> c; string s; cin >> s; for (int i = 0; i < n; i++) if (s[i] == 'o') { a.push_back(i); i += c; }; for (int i = n - 1; i >= 0; i--) if (s[i] == 'o') { b.push_back(i); i -= c; }; for (int i = 0; i < k; i++) if (a[i] == b[k - i - 1]) { cout << a[i] + 1 << '\n'; }; return 0; }
replace
13
14
13
14
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; // const int mod=1e9+7; const int mod = 998244353; const double eps = 1e-10; const double pi = acos(-1.0); const int maxn = 2e5 + 10; const ll inf = 0x3f3f3f3f; const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int l[maxn], r[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int n, k, c; cin >> n >> k >> c; string s; cin >> s; int cnt = k - 1, mx = n; for (int i = s.length() - 1; i >= 0; i--) if (s[i] == 'o' && i < mx) r[cnt] = i, mx = i - c, cnt--; cnt = 0, mx = -1; for (int i = 0; i < s.length(); i++) if (s[i] == 'o' && i > mx) l[cnt] = i, mx = i + c, cnt++; for (int i = 0; i < k; i++) if (l[i] == r[i]) cout << l[i] + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; // const int mod=1e9+7; const int mod = 998244353; const double eps = 1e-10; const double pi = acos(-1.0); const int maxn = 2e5 + 10; const ll inf = 0x3f3f3f3f; const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int l[maxn], r[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int n, k, c; cin >> n >> k >> c; string s; cin >> s; int cnt = k - 1, mx = n; for (int i = s.length() - 1; i >= 0; i--) if (s[i] == 'o' && i < mx && cnt >= 0) r[cnt] = i, mx = i - c, cnt--; cnt = 0, mx = -1; for (int i = 0; i < s.length(); i++) if (s[i] == 'o' && i > mx) l[cnt] = i, mx = i + c, cnt++; for (int i = 0; i < k; i++) if (l[i] == r[i]) cout << l[i] + 1 << endl; return 0; }
replace
32
33
32
33
0
p02721
C++
Time Limit Exceeded
// abc161_e2.cc #include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> ans1, ans2; for (int i = 0; i < n; i++) { if (s[i] == 'o') { ans1.push_back(i); i += c; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { ans2.push_back(i); i -= c; } } if (ans1.size() == k) { for (auto n : ans1) { if (find(ans2.begin(), ans2.end(), n) != ans2.end()) { cout << n + 1 << endl; } } } return 0; }
// abc161_e2.cc #include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; string s; cin >> s; vector<int> ans1, ans2; for (int i = 0; i < n; i++) { if (s[i] == 'o') { ans1.push_back(i); i += c; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'o') { ans2.push_back(i); i -= c; } } if (ans1.size() == k) { for (auto n : ans1) { if (binary_search(ans2.rbegin(), ans2.rend(), n)) { cout << n + 1 << endl; } } } return 0; }
replace
29
30
29
30
TLE
p02721
C++
Runtime Error
// AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // // AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #define _USE_MATH_DEFINES #include <math.h> // #include<cmath> #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> // #include "Ants.h" using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < n; i++) #define show(s) cout << s << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define LINF (1000000000000000000ll) // typedef pair < int, int> P; ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b) if (b == 0) return a; return gcd(b, a % b); } ll lcd(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す if (b == 0) return a; return (a / gcd(a, b)) * b; } vector<int> divnum(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } int digiter(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); rep(i, n) { d.push_back(s[i] - '0'); } return d; } map<int64_t, int> prime_factor(int64_t n) { map<int64_t, int> ret; for (int64_t i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; res.push_back(i); if (i * i != n) res.push_back(n / i); } return res; } int N, K, C; int F[100000], B[100000]; int szf[10000], szb[100000]; string S; int main() { cin >> N >> K >> C; cin >> S; F[1] = 1; int res = 1; for (int i = 1; i < N + 1; i++) { F[i] = F[res]; if (i - res > C && S[i - 1] == 'o') { F[i] = F[res] + 1; res = i; } szf[i] = res; } res = N; B[res] = 1; for (int i = N; i > 0; --i) { B[i] = B[res]; if (res - i > C && S[i - 1] == 'o') { B[i] = B[res] + 1; res = i; } szb[i] = res; } szf[0] = -INF; szb[N + 1] = INF; int ans = 0; for (int i = 1; i < N + 1; i++) { int sum = F[i - 1] + B[i + 1]; if (abs(szf[i - 1] - szb[i + 1]) <= C) { sum--; } // cout << i<<" "<<sum << endl; if (sum < K && S[i - 1] == 'o') { cout << i << endl; } } }
// AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // // AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #define _USE_MATH_DEFINES #include <math.h> // #include<cmath> #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> // #include "Ants.h" using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < n; i++) #define show(s) cout << s << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define LINF (1000000000000000000ll) // typedef pair < int, int> P; ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b) if (b == 0) return a; return gcd(b, a % b); } ll lcd(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す if (b == 0) return a; return (a / gcd(a, b)) * b; } vector<int> divnum(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } int digiter(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); rep(i, n) { d.push_back(s[i] - '0'); } return d; } map<int64_t, int> prime_factor(int64_t n) { map<int64_t, int> ret; for (int64_t i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; res.push_back(i); if (i * i != n) res.push_back(n / i); } return res; } int N, K, C; int F[200100], B[200100]; int szf[200100], szb[200100]; string S; int main() { cin >> N >> K >> C; cin >> S; F[1] = 1; int res = 1; for (int i = 1; i < N + 1; i++) { F[i] = F[res]; if (i - res > C && S[i - 1] == 'o') { F[i] = F[res] + 1; res = i; } szf[i] = res; } res = N; B[res] = 1; for (int i = N; i > 0; --i) { B[i] = B[res]; if (res - i > C && S[i - 1] == 'o') { B[i] = B[res] + 1; res = i; } szb[i] = res; } szf[0] = -INF; szb[N + 1] = INF; int ans = 0; for (int i = 1; i < N + 1; i++) { int sum = F[i - 1] + B[i + 1]; if (abs(szf[i - 1] - szb[i + 1]) <= C) { sum--; } // cout << i<<" "<<sum << endl; if (sum < K && S[i - 1] == 'o') { cout << i << endl; } } }
replace
109
111
109
111
0
p02721
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 110000; char s[N]; int l[N], r[N]; int n, k, c; int main() { scanf("%d%d%d%s", &n, &k, &c, s + 1); int i = 1, kk = 1; while (kk <= k) { if (s[i] == 'o') l[kk++] = i, i += c; ++i; } i = n, kk = k; while (kk) { if (s[i] == 'o') r[kk--] = i, i -= c; --i; } for (i = 1; i <= k; ++i) if (l[i] == r[i]) printf("%d\n", l[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 220000; char s[N]; int l[N], r[N]; int n, k, c; int main() { scanf("%d%d%d%s", &n, &k, &c, s + 1); int i = 1, kk = 1; while (kk <= k) { if (s[i] == 'o') l[kk++] = i, i += c; ++i; } i = n, kk = k; while (kk) { if (s[i] == 'o') r[kk--] = i, i -= c; --i; } for (i = 1; i <= k; ++i) if (l[i] == r[i]) printf("%d\n", l[i]); return 0; }
replace
2
3
2
3
0
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> &a, int b) { auto c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> &a, int b) { auto c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; for (int i = 3; i <= sqrt(a) + 1; i += 2) { if (a % i == 0) return false; } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int lcm(int a, int b) { int c = modinv(gcm(a, b), INF); return ((a * c) % INF) * (b % INF) % INF; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } // 各頂点ごとにどこに辺が出てるかの表がc // 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する // aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ V<int> color(200005); bool nibu_hantei(int a, int b, V<V<int>> c) { color[a] = b; fo(i, c[a].sz) { if (b == color[c[a][i]]) return false; if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c)) return false; } return true; } // aは頂点数 // nibu_hanteiの上にcolorを用意する // 各頂点ごとにどこに辺が出てるかの表がc bool renketujanai_nibu_hantei(int a, V<V<int>> c) { fo(i, a) { if (color[i] == 0) { if (!nibu_hantei(i, 1, c)) return false; } } return true; } struct segmin { vector<int> seg; int b; segmin(V<int> a) { b = 1; while (b < a.sz) b *= 2; seg = vector<int>(2 * b - 1, inf); fo(i, a.sz) { seg[i + b - 1] = a[i]; } for (int i = b - 2; i >= 0; i--) { seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]); } } void update(int i, int a) { i += b - 1; seg[i] = a; while (i) { i = (i - 1) / 2; seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]); } } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ int getmin(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return INF; if (x <= l && r <= y) return seg[a]; int a1 = getmin(x, y, 2 * a + 1, l, (l + r) / 2); int a2 = getmin(x, y, 2 * a + 2, (l + r) / 2, r); return min(a1, a2); } }; struct segadd { vector<int> seg; int b; segadd(V<int> a) { b = 1; while (b < a.sz) b *= 2; seg = vector<int>(2 * b - 1, 0); fo(i, a.sz) { seg[i + b - 1] = a[i]; } for (int i = b - 2; i >= 0; i--) { seg[i] = seg[2 * i + 1] + seg[2 * i + 2]; } } void update(int i, int a) { i += b - 1; seg[i] = a; while (i) { i = (i - 1) / 2; seg[i] = seg[2 * i + 1] + seg[2 * i + 2]; } } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ int getadd(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return 0; if (x <= l && r <= y) return seg[a]; int a1 = getadd(x, y, 2 * a + 1, l, (l + r) / 2); int a2 = getadd(x, y, 2 * a + 2, (l + r) / 2, r); return a1 + a2; } }; struct sege { vector<P<int, V<int>>> seg; int b; sege(string a) { b = 1; while (b < a.sz) b *= 2; seg = vector<P<int, V<int>>>(2 * b - 1); fo(i, a.sz) { seg[i + b - 1].fi = 1; seg[i + b - 1].se.pb(a[i] - 'a'); } for (int i = b - 2; i >= 0; i--) { V<int> d = seg[2 * i + 1].se; fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); } Sort(d); uni(d); seg[i].se = d; seg[i].fi = d.sz; } } V<int> mu; void update(int i, char a) { i += b - 1; seg[i].se = mu; seg[i].se.pb(a - 'a'); seg[i].fi = 1; while (i) { i = (i - 1) / 2; V<int> d = seg[2 * i + 1].se; fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); } Sort(d); uni(d); seg[i].se = d; seg[i].fi = d.sz; } } void unko() { fo(i, 2 * b - 1) cout << seg[i].fi << ' '; } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ P<int, V<int>> gete(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return {0, mu}; if (x <= l && r <= y) return seg[a]; P<int, V<int>> a1 = gete(x, y, 2 * a + 1, l, (l + r) / 2); P<int, V<int>> a2 = gete(x, y, 2 * a + 2, (l + r) / 2, r); fo(i, a2.se.sz) a1.se.pb(a2.se[i]); Sort(a1.se); uni(a1.se); return {a1.se.sz, a1.se}; } }; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ signed main() { int a; cin >> a; a--; int a1 = a; int b = 0; V<int> d; for (int i = 2; i < sqrt(a) + 1; i++) { if (a % i == 0) { if (a == i * i) b--; b += 2; } } a++; V<int> c; for (int i = 2; i < sqrt(a) + 1; i++) { if (a % i == 0) { if (a != i * i) c.pb(a / i); c.pb(i); } } c.pb(a); Sort(c); uni(c); fo(i, c.sz) { int d = a; while (d % c[i] == 0) { d /= c[i]; } if (d % c[i] == 1) { b++; } } cout << b + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> &a, int b) { auto c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> &a, int b) { auto c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; for (int i = 3; i <= sqrt(a) + 1; i += 2) { if (a % i == 0) return false; } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int lcm(int a, int b) { int c = modinv(gcm(a, b), INF); return ((a * c) % INF) * (b % INF) % INF; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } // 各頂点ごとにどこに辺が出てるかの表がc // 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する // aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ V<int> color(200005); bool nibu_hantei(int a, int b, V<V<int>> c) { color[a] = b; fo(i, c[a].sz) { if (b == color[c[a][i]]) return false; if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c)) return false; } return true; } // aは頂点数 // nibu_hanteiの上にcolorを用意する // 各頂点ごとにどこに辺が出てるかの表がc bool renketujanai_nibu_hantei(int a, V<V<int>> c) { fo(i, a) { if (color[i] == 0) { if (!nibu_hantei(i, 1, c)) return false; } } return true; } struct segmin { vector<int> seg; int b; segmin(V<int> a) { b = 1; while (b < a.sz) b *= 2; seg = vector<int>(2 * b - 1, inf); fo(i, a.sz) { seg[i + b - 1] = a[i]; } for (int i = b - 2; i >= 0; i--) { seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]); } } void update(int i, int a) { i += b - 1; seg[i] = a; while (i) { i = (i - 1) / 2; seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]); } } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ int getmin(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return INF; if (x <= l && r <= y) return seg[a]; int a1 = getmin(x, y, 2 * a + 1, l, (l + r) / 2); int a2 = getmin(x, y, 2 * a + 2, (l + r) / 2, r); return min(a1, a2); } }; struct segadd { vector<int> seg; int b; segadd(V<int> a) { b = 1; while (b < a.sz) b *= 2; seg = vector<int>(2 * b - 1, 0); fo(i, a.sz) { seg[i + b - 1] = a[i]; } for (int i = b - 2; i >= 0; i--) { seg[i] = seg[2 * i + 1] + seg[2 * i + 2]; } } void update(int i, int a) { i += b - 1; seg[i] = a; while (i) { i = (i - 1) / 2; seg[i] = seg[2 * i + 1] + seg[2 * i + 2]; } } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ int getadd(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return 0; if (x <= l && r <= y) return seg[a]; int a1 = getadd(x, y, 2 * a + 1, l, (l + r) / 2); int a2 = getadd(x, y, 2 * a + 2, (l + r) / 2, r); return a1 + a2; } }; struct sege { vector<P<int, V<int>>> seg; int b; sege(string a) { b = 1; while (b < a.sz) b *= 2; seg = vector<P<int, V<int>>>(2 * b - 1); fo(i, a.sz) { seg[i + b - 1].fi = 1; seg[i + b - 1].se.pb(a[i] - 'a'); } for (int i = b - 2; i >= 0; i--) { V<int> d = seg[2 * i + 1].se; fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); } Sort(d); uni(d); seg[i].se = d; seg[i].fi = d.sz; } } V<int> mu; void update(int i, char a) { i += b - 1; seg[i].se = mu; seg[i].se.pb(a - 'a'); seg[i].fi = 1; while (i) { i = (i - 1) / 2; V<int> d = seg[2 * i + 1].se; fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); } Sort(d); uni(d); seg[i].se = d; seg[i].fi = d.sz; } } void unko() { fo(i, 2 * b - 1) cout << seg[i].fi << ' '; } // 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで // l,rは探すところ P<int, V<int>> gete(int x, int y, int a, int l, int r) { if (r == INF) r = b; if (r <= x || y <= l) return {0, mu}; if (x <= l && r <= y) return seg[a]; P<int, V<int>> a1 = gete(x, y, 2 * a + 1, l, (l + r) / 2); P<int, V<int>> a2 = gete(x, y, 2 * a + 2, (l + r) / 2, r); fo(i, a2.se.sz) a1.se.pb(a2.se[i]); Sort(a1.se); uni(a1.se); return {a1.se.sz, a1.se}; } }; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ signed main() { int a; cin >> a; a--; int a1 = a; int b = 0; V<int> d; for (int i = 2; i < sqrt(a) + 1; i++) { if (a % i == 0) { if (a == i * i) b--; b += 2; } } a++; V<int> c; for (int i = 2; i < sqrt(a) + 1; i++) { if (a % i == 0) { if (a != i * i) c.pb(a / i); c.pb(i); } } if (a == 2) { cout << 1 << endl; return 0; } c.pb(a); Sort(c); uni(c); fo(i, c.sz) { int d = a; while (d % c[i] == 0) { d /= c[i]; } if (d % c[i] == 1) { b++; } } cout << b + 1 << endl; }
insert
508
508
508
512
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> // typedef //-------------------------#include <bits/stdc++.h> const double pi = 3.141592653589793238462643383279; using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> P; typedef pair<int, int> pii; typedef vector<int> vi; const double EPS = 1E-8; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) class UnionFind { public: vector<int> par; vector<int> siz; UnionFind(int sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(int sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } int root(int x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; ll modPow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n) { if (n & 1) res = (res * x) % mod; res %= mod; x = x * x % mod; n >>= 1; } return res; } #define SIEVE_SIZE 5000000 + 10 bool sieve[SIEVE_SIZE]; void makeSieve() { for (int i = 0; i < SIEVE_SIZE; ++i) sieve[i] = true; sieve[0] = sieve[1] = false; for (int i = 2; i * i < SIEVE_SIZE; ++i) if (sieve[i]) for (int j = 2; i * j < SIEVE_SIZE; ++j) sieve[i * j] = false; } bool isprime(ll n) { if (n == 0 || n == 1) return false; for (ll i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } const int MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } // 負の数にも対応した mod (a = -11 とかでも OK) inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 逆元計算 (ここでは a と m が互いに素であることが必要) long long modinv(long long a, long long m) { long long x, y; extGCD(a, m, x, y); return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A, mat &B) { mat C(A.size(), vec((int)B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int k = 0; k < B.size(); ++k) { for (int j = 0; j < B[0].size(); ++j) { C[i][j] = (C[i][j] + A[i][k] % MOD * B[k][j] % MOD) % MOD; } } } return C; } mat matPow(mat A, ll n) { mat B(A.size(), vec((int)A.size())); for (int i = 0; i < A.size(); ++i) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } template <class TYPE> struct Fenwick { int N; vector<ll> bit; Fenwick() : N(0) {} Fenwick(int n) : N(n), bit(N + 1, 0) {} void add(int i, ll x) { ++i; // 0-indexedを避けるために加算 while (i <= N) { bit[i] += x; i += (i & -i); } } ll sum(int i) { ll res = 0; while (i > 0) { res += bit[i]; i -= (i & -i); } return res; } ll range(int i, int j) { return sum(j) - sum(i); } ll get(int i) { return sum(i) - sum(i - 1); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(5); ll N; cin >> N; set<ll> st; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ll a = i; ll b = N / i; if (a != 1) { ll tmp = N; while (tmp % a == 0) { tmp = tmp / a; } if (tmp % a == 1) st.insert(a); } { ll tmp = N; while (tmp % b == 0) { tmp = tmp / b; } if (tmp % b == 1) st.insert(b); } } } N--; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ll a = i; ll b = N / i; if (a != 1) { ll tmp = N + 1; while (tmp % a == 0) { tmp = tmp / a; } if (tmp % a == 1) st.insert(a); } { ll tmp = N + 1; while (tmp % b == 0) { tmp = tmp / b; } if (tmp % b == 1) st.insert(b); } } } cout << st.size() << endl; return 0; }
#include <bits/stdc++.h> // typedef //-------------------------#include <bits/stdc++.h> const double pi = 3.141592653589793238462643383279; using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> P; typedef pair<int, int> pii; typedef vector<int> vi; const double EPS = 1E-8; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) class UnionFind { public: vector<int> par; vector<int> siz; UnionFind(int sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(int sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } int root(int x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; ll modPow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n) { if (n & 1) res = (res * x) % mod; res %= mod; x = x * x % mod; n >>= 1; } return res; } #define SIEVE_SIZE 5000000 + 10 bool sieve[SIEVE_SIZE]; void makeSieve() { for (int i = 0; i < SIEVE_SIZE; ++i) sieve[i] = true; sieve[0] = sieve[1] = false; for (int i = 2; i * i < SIEVE_SIZE; ++i) if (sieve[i]) for (int j = 2; i * j < SIEVE_SIZE; ++j) sieve[i * j] = false; } bool isprime(ll n) { if (n == 0 || n == 1) return false; for (ll i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } const int MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } // 負の数にも対応した mod (a = -11 とかでも OK) inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 逆元計算 (ここでは a と m が互いに素であることが必要) long long modinv(long long a, long long m) { long long x, y; extGCD(a, m, x, y); return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A, mat &B) { mat C(A.size(), vec((int)B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int k = 0; k < B.size(); ++k) { for (int j = 0; j < B[0].size(); ++j) { C[i][j] = (C[i][j] + A[i][k] % MOD * B[k][j] % MOD) % MOD; } } } return C; } mat matPow(mat A, ll n) { mat B(A.size(), vec((int)A.size())); for (int i = 0; i < A.size(); ++i) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } template <class TYPE> struct Fenwick { int N; vector<ll> bit; Fenwick() : N(0) {} Fenwick(int n) : N(n), bit(N + 1, 0) {} void add(int i, ll x) { ++i; // 0-indexedを避けるために加算 while (i <= N) { bit[i] += x; i += (i & -i); } } ll sum(int i) { ll res = 0; while (i > 0) { res += bit[i]; i -= (i & -i); } return res; } ll range(int i, int j) { return sum(j) - sum(i); } ll get(int i) { return sum(i) - sum(i - 1); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(5); ll N; cin >> N; if (N == 2) { cout << 1 << endl; return 0; } set<ll> st; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ll a = i; ll b = N / i; if (a != 1) { ll tmp = N; while (tmp % a == 0) { tmp = tmp / a; } if (tmp % a == 1) st.insert(a); } { ll tmp = N; while (tmp % b == 0) { tmp = tmp / b; } if (tmp % b == 1) st.insert(b); } } } N--; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ll a = i; ll b = N / i; if (a != 1) { ll tmp = N + 1; while (tmp % a == 0) { tmp = tmp / a; } if (tmp % a == 1) st.insert(a); } { ll tmp = N + 1; while (tmp % b == 0) { tmp = tmp / b; } if (tmp % b == 1) st.insert(b); } } } cout << st.size() << endl; return 0; }
replace
264
265
264
268
TLE
p02722
C++
Runtime Error
/******************************** * AUTHOR: ARNAB SEN * * NICK : arnab1729 * * INSTITUTION: IIEST, SHIBPUR * ********************************/ #include <bits/stdc++.h> using namespace std; typedef string STR; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef vector<int> VI; typedef priority_queue<int> PQI; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<STR> VS; typedef vector<char> VC; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<STR, int> PSI; typedef pair<int, STR> PIS; typedef vector<PII> VII; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<STR, int> MSI; typedef map<char, int> MCI; typedef map<int, STR> MIS; typedef set<STR> SS; typedef set<int> SI; typedef set<LL> SLL; #define FF first #define SS second #define PB push_back #define PF push_front #define MP make_pair #define all(a) (a).begin(), (a).end() #define dec(n) cout << fixed << setprecision(n); #define f(i, n) for (LL i = 0; i < n; i++) #define fr(i, n) for (LL i = n - 1; i >= 0; i--) #define fsort(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)) template <class T> T maxT(T a, T b) { return (a > b ? a : b); } template <class T> T minT(T a, T b) { return (a < b ? a : b); } template <class T> void setmin(T &a, T b) { a = (a > b ? a : b); } template <class T> void setmax(T &a, T b) { a = (a < b ? a : b); } void fileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); } void ofileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void clock_out() { cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define fio() fileio() #define ofio ofileio() #define clock() clock_out() #else #define debug(...) 1 #define fio() 1 #define ofio() ofileio() #define clock() 1 #endif const LL MOD = 1000000007; const LL SIZE = 100000; const int INF = 0x3f3f3f3f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LD PI = acos(-1); const LL MAXN = numeric_limits<LL>::max(); LL cnt = 0; void modVal(LL k, LL n) { if (k == 1) return; while (n % k == 0) n /= k; if (n % k == 1) { cnt++; } } void solve() { LL n; cin >> n; set<LL> div; for (LL i = 2; i * i <= n; i++) { if (n % i == 0) { div.insert(i); modVal(i, n); if (n != i * i) { div.insert(n / i); modVal(n / i, n); } } } n--; for (LL i = 1; i * i <= n; i++) { if (n % i == 0) { if (div.find(i) == div.end()) { cnt++; } if (n != i * i) { if (div.find(n / i) == div.end()) { cnt++; } } } } cout << cnt; } int main() { fast; fio(); LL t = 1; // cin>>t; while (t--) { solve(); } clock(); return 0; }
/******************************** * AUTHOR: ARNAB SEN * * NICK : arnab1729 * * INSTITUTION: IIEST, SHIBPUR * ********************************/ #include <bits/stdc++.h> using namespace std; typedef string STR; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef vector<int> VI; typedef priority_queue<int> PQI; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<STR> VS; typedef vector<char> VC; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<STR, int> PSI; typedef pair<int, STR> PIS; typedef vector<PII> VII; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<STR, int> MSI; typedef map<char, int> MCI; typedef map<int, STR> MIS; typedef set<STR> SS; typedef set<int> SI; typedef set<LL> SLL; #define FF first #define SS second #define PB push_back #define PF push_front #define MP make_pair #define all(a) (a).begin(), (a).end() #define dec(n) cout << fixed << setprecision(n); #define f(i, n) for (LL i = 0; i < n; i++) #define fr(i, n) for (LL i = n - 1; i >= 0; i--) #define fsort(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)) template <class T> T maxT(T a, T b) { return (a > b ? a : b); } template <class T> T minT(T a, T b) { return (a < b ? a : b); } template <class T> void setmin(T &a, T b) { a = (a > b ? a : b); } template <class T> void setmax(T &a, T b) { a = (a < b ? a : b); } void fileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); } void ofileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void clock_out() { cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define fio() fileio() #define ofio ofileio() #define clock() clock_out() #else #define debug(...) 1 #define fio() 1 #define ofio() ofileio() #define clock() 1 #endif const LL MOD = 1000000007; const LL SIZE = 100000; const int INF = 0x3f3f3f3f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LD PI = acos(-1); const LL MAXN = numeric_limits<LL>::max(); LL cnt = 0; void modVal(LL k, LL n) { if (k == 1) return; while (n % k == 0) n /= k; if (n % k == 1) { cnt++; } } void solve() { LL n; cin >> n; set<LL> div; for (LL i = 2; i * i <= n; i++) { if (n % i == 0) { div.insert(i); modVal(i, n); if (n != i * i) { div.insert(n / i); modVal(n / i, n); } } } n--; for (LL i = 1; i * i <= n; i++) { if (n % i == 0) { if (div.find(i) == div.end()) { cnt++; } if (n != i * i) { if (div.find(n / i) == div.end()) { cnt++; } } } } cout << cnt; } int main() { fast; // fio(); LL t = 1; // cin>>t; while (t--) { solve(); } clock(); return 0; }
replace
144
145
144
145
0
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool check(ll n, ll k) { if (n == 1) return true; if (n < k) return false; if (n % k == 0) { return check(n / k, k); } else { return check(n % k, k); } } vector<ll> get_div(ll n) { vector<ll> res; for (ll d = 2; d * d <= n; d++) { if (n % d == 0) { res.push_back(d); if (d < n / d) { res.push_back(n / d); } } } return res; } int main(void) { ll n; cin >> n; set<ll> res; auto divs = get_div(n); for (ll d : divs) { if (check(n, d)) res.insert(d); } auto divs2 = get_div(n - 1); for (ll d : divs2) { if (check(n, d)) res.insert(d); } if (check(n, n)) res.insert(n); if (check(n, n - 1)) res.insert(n - 1); cout << res.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool check(ll n, ll k) { if (n == 1) return true; if (n < k) return false; if (n % k == 0) { return check(n / k, k); } else { return check(n % k, k); } } vector<ll> get_div(ll n) { vector<ll> res; for (ll d = 2; d * d <= n; d++) { if (n % d == 0) { res.push_back(d); if (d < n / d) { res.push_back(n / d); } } } return res; } int main(void) { ll n; cin >> n; if (n == 2) { cout << 1 << endl; return 0; } set<ll> res; auto divs = get_div(n); for (ll d : divs) { if (check(n, d)) res.insert(d); } auto divs2 = get_div(n - 1); for (ll d : divs2) { if (check(n, d)) res.insert(d); } if (check(n, n)) res.insert(n); if (check(n, n - 1)) res.insert(n - 1); cout << res.size() << endl; return 0; }
insert
32
32
32
36
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long int; vector<ll> enumDivisor(ll x) { vector<ll> res; for (int i = 1; i * i <= x; ++i) { if (x % i) continue; res.push_back(i); if (i * i != x) res.push_back(x / i); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); ll n; cin >> n; int ans = 0; for (auto x : enumDivisor(n)) { if (x == 1) continue; ll tmp = n; while (tmp % x == 0) tmp /= x; if (tmp % x == 1) ++ans; } ans += enumDivisor(n - 1).size() - 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; vector<ll> enumDivisor(ll x) { vector<ll> res; for (ll i = 1; i * i <= x; ++i) { if (x % i) continue; res.push_back(i); if (i * i != x) res.push_back(x / i); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); ll n; cin >> n; int ans = 0; for (auto x : enumDivisor(n)) { if (x == 1) continue; ll tmp = n; while (tmp % x == 0) tmp /= x; if (tmp % x == 1) ++ans; } ans += enumDivisor(n - 1).size() - 1; cout << ans << endl; }
replace
5
6
5
6
TLE
p02722
C++
Time Limit Exceeded
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define FOR(i, j, k) for (ll i = j; i < k; i++) #define debug_print(i) cerr << #i << "=" << i << endl; #define DUMP(i, v) \ for (ll i = 0; i < v.size(); i++) \ cerr << v[i] << " " using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge { ll x, c; }; ll mod(ll a, ll mod) { ll res = a % mod; if (res < 0) res = res + mod; return res; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } ll gcd(ll a, ll b) { ll r = a % b; if (r == 0) return b; else return gcd(b, a % b); } bool is_prime(ll n) { ll i = 2; if (n == 1) return false; if (n == 2) return true; bool res = true; while (i * i < n) { if (n % i == 0) { res = false; } i = i + 1; } // if(i==1)res = false; if (n % i == 0) res = false; return res; } struct UnionFind { ll N; llvec p; llvec cnt; UnionFind(ll n) { N = n; p = llvec(N); cnt = llvec(N, 0); rep(i, N) { p[i] = i; cnt[i] = 1; } } void con(ll a, ll b) { P at = root(a); P bt = root(b); if (at.second != bt.second) { if (at.first > bt.first) { swap(at, bt); swap(a, b); } p[at.second] = bt.second; cnt[bt.second] += cnt[at.second]; p[a] = bt.second; } } P root(ll a) { ll atmp = a; ll c = 0; while (atmp != p[atmp]) { atmp = p[atmp]; c++; } p[a] = atmp; return {c, atmp}; } bool is_con(ll a, ll b) { P at = root(a); P bt = root(b); return at.second == bt.second; } }; struct dijkstra { ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n) { N = n; // d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); } void run(ll start) { priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start] = 0; while (!que.empty()) { P q = que.top(); que.pop(); ll dc = q.first; ll x = q.second; if (dc > d[x]) { continue; } else { for (auto ip : e[x]) { if (d[ip.x] <= d[x] + ip.c) { continue; } else { d[ip.x] = d[x] + ip.c; que.push({d[ip.x], ip.x}); } } } } } }; ll chk(ll n, ll k) { if (n < k) return n; if (n % k == 0) return chk(n / k, k); else return n % k; } /************************************** ** A main function starts from here ** ***************************************/ int main() { ll N; cin >> N; ll a = N - 1; set<ll> fs; FOR(i, 2, sqrt(N) + 1) { if (a % i == 0) { fs.insert(i); fs.insert(a / i); } } a = N; FOR(i, 2, sqrt(N) + 1) { if (a % i == 0) { fs.insert(i); fs.insert(a / i); } } ll ans = 0; fs.insert(N); fs.insert(N - 1); for (auto fi : fs) { if (chk(N, fi) == 1) { debug_print(fi); ans++; } } cout << ans; return 0; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define FOR(i, j, k) for (ll i = j; i < k; i++) #define debug_print(i) cerr << #i << "=" << i << endl; #define DUMP(i, v) \ for (ll i = 0; i < v.size(); i++) \ cerr << v[i] << " " using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge { ll x, c; }; ll mod(ll a, ll mod) { ll res = a % mod; if (res < 0) res = res + mod; return res; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } ll gcd(ll a, ll b) { ll r = a % b; if (r == 0) return b; else return gcd(b, a % b); } bool is_prime(ll n) { ll i = 2; if (n == 1) return false; if (n == 2) return true; bool res = true; while (i * i < n) { if (n % i == 0) { res = false; } i = i + 1; } // if(i==1)res = false; if (n % i == 0) res = false; return res; } struct UnionFind { ll N; llvec p; llvec cnt; UnionFind(ll n) { N = n; p = llvec(N); cnt = llvec(N, 0); rep(i, N) { p[i] = i; cnt[i] = 1; } } void con(ll a, ll b) { P at = root(a); P bt = root(b); if (at.second != bt.second) { if (at.first > bt.first) { swap(at, bt); swap(a, b); } p[at.second] = bt.second; cnt[bt.second] += cnt[at.second]; p[a] = bt.second; } } P root(ll a) { ll atmp = a; ll c = 0; while (atmp != p[atmp]) { atmp = p[atmp]; c++; } p[a] = atmp; return {c, atmp}; } bool is_con(ll a, ll b) { P at = root(a); P bt = root(b); return at.second == bt.second; } }; struct dijkstra { ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n) { N = n; // d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); } void run(ll start) { priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start] = 0; while (!que.empty()) { P q = que.top(); que.pop(); ll dc = q.first; ll x = q.second; if (dc > d[x]) { continue; } else { for (auto ip : e[x]) { if (d[ip.x] <= d[x] + ip.c) { continue; } else { d[ip.x] = d[x] + ip.c; que.push({d[ip.x], ip.x}); } } } } } }; ll chk(ll n, ll k) { if (n < k) return n; if (n % k == 0) return chk(n / k, k); else return n % k; } /************************************** ** A main function starts from here ** ***************************************/ int main() { ll N; cin >> N; ll a = N - 1; set<ll> fs; FOR(i, 2, sqrt(N) + 1) { if (a % i == 0) { fs.insert(i); fs.insert(a / i); } } a = N; FOR(i, 2, sqrt(N) + 1) { if (a % i == 0) { fs.insert(i); fs.insert(a / i); } } ll ans = 0; fs.insert(N); fs.insert(N - 1); for (auto fi : fs) { if (fi == 1) continue; if (chk(N, fi) == 1) { debug_print(fi); ans++; } } cout << ans; return 0; }
insert
189
189
189
191
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<pll> vpl; typedef vector<vll> vvll; #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define REP1(i, n) for (int i = 1; i < ((int)n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; set<ll> s; for (ll i = 2; i * i <= n; i++) { ll x = n; while (x % i == 0) x /= i; if ((x - 1) % i == 0) { if (n % i != 0) s.insert((x - 1) / i); s.insert(i); } } for (ll i = n - 1; i <= n; i++) { ll x = n; while (x % i == 0) x /= i; if (x % i == 1) s.insert(i); } cout << s.size() << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<pll> vpl; typedef vector<vll> vvll; #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define REP1(i, n) for (int i = 1; i < ((int)n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; set<ll> s; for (ll i = 2; i * i <= n; i++) { ll x = n; while (x % i == 0) x /= i; if ((x - 1) % i == 0) { if (n % i != 0) s.insert((x - 1) / i); s.insert(i); } } for (ll i = n - 1; i <= n; i++) { if (i == 1) continue; ll x = n; while (x % i == 0) x /= i; if (x % i == 1) s.insert(i); } cout << s.size() << endl; }
insert
63
63
63
65
TLE
p02722
C++
Runtime Error
// cout << "Case #" << k << ": "; #include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main() { ll n; cin >> n; if (n == 2) { cout << 1 << endl; return 0; } ll ans = 0; auto res = divisor(n - 1); ans += res.size() - 1; res = divisor(n); for (auto e : res) { if (e == 1) { continue; } ll a = 1; while (n % (a * e) == 0) { a *= e; } ll m = n / a; if (m % e == 1) { ans++; } } cout << ans << endl; }
// cout << "Case #" << k << ": "; #include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main() { ll n; cin >> n; if (n == 2) { cout << 1 << endl; return 0; } ll ans = 0; auto res = divisor(n - 1); ans += res.size() - 1; res = divisor(n); for (auto e : res) { if (e == 1) { continue; } ll a = 1; while (n % (a * e) == 0) { a *= e; if (a * e == 0) { break; } } ll m = n / a; if (m % e == 1) { ans++; } } cout << ans << endl; }
insert
36
36
36
39
0
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i, s, n) for (int i = s; i < n; i++) #define MOD 1000000007 #define NUM 2520 #define INF (1LL << 50) #define DEBUG 0 #define mp(a, b) make_pair(a, b) #define SORT(V) sort(V.begin(), V.end()) #define PI (3.141592653589794) set<lli> yaku(lli num) { set<lli> rtn; for (lli i = 1; i * i <= num; i++) { rtn.insert(i); rtn.insert(num / i); } return rtn; } bool ok(lli n, lli k) { if (n == 1) return true; if (n < k) return false; if (n % k == 0) return ok(n / k, k); else return ok(n % k, k); } void func(long long N) { set<lli> y = yaku(N); set<lli> yy = yaku(N - 1); lli cnt = 0; for (auto e : y) { if (e == 1) continue; if (ok(N, e)) cnt++; } for (auto e : yy) { if (y.find(e) != y.end()) continue; if (ok(N, e)) cnt++; } cout << cnt << endl; } int main() { // cout << fixed << setprecision(5); long long N; scanf("%lld", &N); func(N); return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i, s, n) for (int i = s; i < n; i++) #define MOD 1000000007 #define NUM 2520 #define INF (1LL << 50) #define DEBUG 0 #define mp(a, b) make_pair(a, b) #define SORT(V) sort(V.begin(), V.end()) #define PI (3.141592653589794) set<lli> yaku(lli num) { set<lli> rtn; for (lli i = 1; i * i <= num; i++) { if (num % i == 0) { rtn.insert(i); rtn.insert(num / i); } } return rtn; } bool ok(lli n, lli k) { if (n == 1) return true; if (n < k) return false; if (n % k == 0) return ok(n / k, k); else return ok(n % k, k); } void func(long long N) { set<lli> y = yaku(N); set<lli> yy = yaku(N - 1); lli cnt = 0; for (auto e : y) { if (e == 1) continue; if (ok(N, e)) cnt++; } for (auto e : yy) { if (y.find(e) != y.end()) continue; if (ok(N, e)) cnt++; } cout << cnt << endl; } int main() { // cout << fixed << setprecision(5); long long N; scanf("%lld", &N); func(N); return 0; }
replace
16
18
16
20
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<ll> g; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (i != 1) g.push_back(i); if (n / i != i) g.push_back(n / i); } } for (ll i = 1; i * i <= n - 1; i++) { if ((n - 1) % i == 0) { if (i != 1) g.push_back(i); if ((n - 1) / i != i) g.push_back((n - 1) / i); } } int ans = 0; for (ll x : g) { ll dn = n; while (dn >= x) { if (dn % x == 0) dn /= x; else dn -= x; } if (dn == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<ll> g; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (i != 1) g.push_back(i); if (n / i != i) g.push_back(n / i); } } for (ll i = 1; i * i <= n - 1; i++) { if ((n - 1) % i == 0) { if (i != 1) g.push_back(i); if ((n - 1) / i != i) g.push_back((n - 1) / i); } } int ans = 0; for (ll x : g) { ll dn = n; while (dn >= x) { if (dn % x == 0) dn /= x; else dn %= x; } if (dn == 1) ans++; } cout << ans << endl; return 0; }
replace
35
36
35
36
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4; #define REP(i, stop) FOR(i, 0, stop) #define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i) #define RREP(i, n) for (ll i = n; i-- > 0;) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define COMP(key) [](const auto &a, const auto &b) { return a.key < b.key; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &a) { return is >> a.first >> a.second; } template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &x : a) is >> x; return is; } template <typename T> using pop_max = std::priority_queue<T>; template <typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> void LOG(const T &x) { cerr << x << "\n"; } template <typename T> void LOG(const vector<T> &a) { for (const T &x : a) cerr << x << " "; cerr << "\n"; } template <typename T> void LOG(const vector<vector<T>> &a) { for (const auto &x : a) LOG(x); } template <typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; } template <typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } } ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; } ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll gcd(const vector<ll> &v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll (*)(ll, ll)>(gcd)); } ll lcm(const vector<ll> &v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll (*)(ll, ll)>(lcm)); } ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; } ll inv(ll x, ll m) { return pow(x, m - 2, m); } template <typename T> bool chmax(T &x, const T &y) { return x < y ? x = y, true : false; } template <typename T> bool chmin(T &x, const T &y) { return x > y ? x = y, true : false; } struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp; const ll INF = inf<ll>; using P = pair<ll, ll>; const ll M = 1000000007; signed main() { ll n; cin >> n; auto divs = [&](ll n) -> vector<ll> { ll i = 2; vector<ll> ret; while (i * i <= n) { if (n % i == 0) { ret.push_back(i); if (i != n / i) ret.push_back(n / i); } i += 1; } ret.push_back(n); return ret; }; ll ans = 0; for (ll k : divs(n - 1)) { ll m = n; while (m >= k) { if (m % k == 0) m /= k; else m %= k; } if (m == 1) ans++; } for (ll k : divs(n)) { ll m = n; while (m >= k) { if (m % k == 0) m /= k; else m %= k; } if (m == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4; #define REP(i, stop) FOR(i, 0, stop) #define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i) #define RREP(i, n) for (ll i = n; i-- > 0;) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define COMP(key) [](const auto &a, const auto &b) { return a.key < b.key; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &a) { return is >> a.first >> a.second; } template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &x : a) is >> x; return is; } template <typename T> using pop_max = std::priority_queue<T>; template <typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> void LOG(const T &x) { cerr << x << "\n"; } template <typename T> void LOG(const vector<T> &a) { for (const T &x : a) cerr << x << " "; cerr << "\n"; } template <typename T> void LOG(const vector<vector<T>> &a) { for (const auto &x : a) LOG(x); } template <typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; } template <typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } } ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; } ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll gcd(const vector<ll> &v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll (*)(ll, ll)>(gcd)); } ll lcm(const vector<ll> &v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll (*)(ll, ll)>(lcm)); } ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; } ll inv(ll x, ll m) { return pow(x, m - 2, m); } template <typename T> bool chmax(T &x, const T &y) { return x < y ? x = y, true : false; } template <typename T> bool chmin(T &x, const T &y) { return x > y ? x = y, true : false; } struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp; const ll INF = inf<ll>; using P = pair<ll, ll>; const ll M = 1000000007; signed main() { ll n; cin >> n; if (n == 2) { cout << 1 << endl; exit(0); } auto divs = [&](ll n) -> vector<ll> { ll i = 2; vector<ll> ret; while (i * i <= n) { if (n % i == 0) { ret.push_back(i); if (i != n / i) ret.push_back(n / i); } i += 1; } ret.push_back(n); return ret; }; ll ans = 0; for (ll k : divs(n - 1)) { ll m = n; while (m >= k) { if (m % k == 0) m /= k; else m %= k; } if (m == 1) ans++; } for (ll k : divs(n)) { ll m = n; while (m >= k) { if (m % k == 0) m /= k; else m %= k; } if (m == 1) ans++; } cout << ans << endl; }
insert
103
103
103
107
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) typedef long long ll; vector<pair<ll, ll>> factorize(ll n) { vector<pair<ll, ll>> res; for (int i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } int main() { ll n; cin >> n; ll ans = 0; for (ll i = 2; i * i <= n; ++i) { ll temp = n; if (temp % i) continue; while (temp % i == 0) { temp /= i; } if (temp % i == 1) ans++; } auto v = factorize(n - 1); ll yakusuu = 1; rep(i, v.size()) { yakusuu *= v[i].second + 1; } yakusuu--; ans += yakusuu + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) typedef long long ll; vector<pair<ll, ll>> factorize(ll n) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } int main() { ll n; cin >> n; ll ans = 0; for (ll i = 2; i * i <= n; ++i) { ll temp = n; if (temp % i) continue; while (temp % i == 0) { temp /= i; } if (temp % i == 1) ans++; } auto v = factorize(n - 1); ll yakusuu = 1; rep(i, v.size()) { yakusuu *= v[i].second + 1; } yakusuu--; ans += yakusuu + 1; cout << ans << endl; return 0; }
replace
9
10
9
10
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; int main() { ll n, ans = 0; cin >> n; vector<ll> num; rep(k, 2) { n -= (ll)k; num.push_back(n); for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { num.push_back(i); if (i * i != n) num.push_back(n / i); } } n += k; } for (ll i : num) { ll a = n; while (a % i == 0) a /= i; if (a % i == 1) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; int main() { ll n, ans = 0; cin >> n; vector<ll> num; rep(k, 2) { n -= (ll)k; if (n != 1) num.push_back(n); for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { num.push_back(i); if (i * i != n) num.push_back(n / i); } } n += k; } for (ll i : num) { ll a = n; while (a % i == 0) a /= i; if (a % i == 1) { ans++; } } cout << ans << endl; return 0; }
replace
12
13
12
14
TLE
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; ll mod = 1000000007; int main() { source: ll n; cin >> n; set<ll> m; ll sq = sqrt(n); repd(i, 2, sq + 1) { if (n % i == 0) { m.insert(i); m.insert(n / i); } if ((n - 1) % i == 0) { m.insert(i); m.insert((n - 1) / i); } } m.insert(n - 1); m.insert(n); ll ans = 0; for (auto num : m) { ll temp = n; while (temp > 0) { if (temp % num == 0) { temp /= num; } else { temp %= num; } if (temp == 1) { ans++; break; } else if (temp < num) { if (temp < num) { break; } } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; ll mod = 1000000007; int main() { source: ll n; cin >> n; set<ll> m; ll sq = sqrt(n); repd(i, 2, sq + 1) { if (n % i == 0) { m.insert(i); m.insert(n / i); } if ((n - 1) % i == 0) { m.insert(i); m.insert((n - 1) / i); } } m.insert(n - 1); m.insert(n); ll ans = 0; for (auto iter = m.begin(); iter != m.end(); iter++) { ll num = *iter; if (num == 1) { continue; } ll temp = n; while (temp > 0) { if (temp % num == 0) { temp /= num; } else { temp %= num; } if (temp == 1) { ans++; break; } else if (temp < num) { if (temp < num) { break; } } } } cout << ans << endl; return 0; }
replace
33
34
33
38
TLE
p02722
C++
Time Limit Exceeded
/* _ _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||_ \ | | \\\ - /'| | | | \_| `\`---'// |_/ | \ .-\__ `-. -'__/-. / ___`. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' _> \"". | | : `- \`. ;`. _/; .'/ / .' ; | \ \ `-. \_\_`. _.'_/_/ -' _.' / ===========`-.`___`-.__\ \___ /__.-'_.'_.-'================ Please give me AC. */ #include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using int64 = long long; using uint64 = unsigned long long; using vi = vector<int>; using vl = vector<int64>; using pii = pair<int, int>; using pll = pair<int64, int64>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) (v).begin(), (v).end() #define print(x) cout << (x) << '\n' #define print2(x, y) cout << (x) << ' ' << (y) << '\n' #define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n' #define printn(v) \ rep(i, (v).size() - 1) cout << (v)[i] << ' '; \ cout << (v)[n - 1] << '\n'; #define debug(x) cerr << #x << ": " << (x) << '\n' #define debug2(x, y) \ cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n' #define debug3(x, y, z) \ cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \ << (z) << '\n' #define dbg(v) \ for (size_t _ = 0; _ < v.size(); ++_) { \ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \ } // constant const int INF = (1 << 30) - 1; const int64 INF64 = (1LL << 62) - 1; template <typename T> T gcd(T a, T b) { if (a < b) return gcd(b, a); T r; while ((r = a % b)) { a = b; b = r; } return b; } template <typename T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) return a = b, true; else return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) return a = b, true; else return false; } // End of template. bool test(int64 n, int64 x) { while (n % x == 0 && n > 0) n /= x; return n % x == 1; } int main() { cout << fixed << setprecision(15); ios::sync_with_stdio(false); cin.tie(nullptr); // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out // で入力すること int64 n; cin >> n; int64 ans = 0; int64 i; for (i = 2; i * i < n; ++i) if (n % i == 0) { ans += test(n, i); ans += test(n, n / i); } if (i * i == n) ans += test(n, i); ans += test(n, n); for (i = 2; i * i < n - 1; ++i) if ((n - 1) % i == 0) { ans += test(n, i); ans += test(n, (n - 1) / i); } if (i * i == n - 1) ans += test(n, i); ans += test(n, n - 1); print(ans); return 0; }
/* _ _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||_ \ | | \\\ - /'| | | | \_| `\`---'// |_/ | \ .-\__ `-. -'__/-. / ___`. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' _> \"". | | : `- \`. ;`. _/; .'/ / .' ; | \ \ `-. \_\_`. _.'_/_/ -' _.' / ===========`-.`___`-.__\ \___ /__.-'_.'_.-'================ Please give me AC. */ #include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using int64 = long long; using uint64 = unsigned long long; using vi = vector<int>; using vl = vector<int64>; using pii = pair<int, int>; using pll = pair<int64, int64>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) (v).begin(), (v).end() #define print(x) cout << (x) << '\n' #define print2(x, y) cout << (x) << ' ' << (y) << '\n' #define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n' #define printn(v) \ rep(i, (v).size() - 1) cout << (v)[i] << ' '; \ cout << (v)[n - 1] << '\n'; #define debug(x) cerr << #x << ": " << (x) << '\n' #define debug2(x, y) \ cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n' #define debug3(x, y, z) \ cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \ << (z) << '\n' #define dbg(v) \ for (size_t _ = 0; _ < v.size(); ++_) { \ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \ } // constant const int INF = (1 << 30) - 1; const int64 INF64 = (1LL << 62) - 1; template <typename T> T gcd(T a, T b) { if (a < b) return gcd(b, a); T r; while ((r = a % b)) { a = b; b = r; } return b; } template <typename T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) return a = b, true; else return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) return a = b, true; else return false; } // End of template. bool test(int64 n, int64 x) { if (x == 1) return false; while (n % x == 0) n /= x; return n % x == 1; } int main() { cout << fixed << setprecision(15); ios::sync_with_stdio(false); cin.tie(nullptr); // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out // で入力すること int64 n; cin >> n; int64 ans = 0; int64 i; for (i = 2; i * i < n; ++i) if (n % i == 0) { ans += test(n, i); ans += test(n, n / i); } if (i * i == n) ans += test(n, i); ans += test(n, n); for (i = 2; i * i < n - 1; ++i) if ((n - 1) % i == 0) { ans += test(n, i); ans += test(n, (n - 1) / i); } if (i * i == n - 1) ans += test(n, i); ans += test(n, n - 1); print(ans); return 0; }
replace
108
109
108
111
TLE
p02722
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iostream> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> using namespace std; typedef long long ll; typedef double db; ll mod = 1e9 + 7; ll a[500][2]; int main() { ll n; int count = 0; cin >> n; ll s = 0; if (n == 2) s--; for (ll i = 2; i * i <= n; i++) { if (n % i == 1) { if ((n - 1) / i == i) s++; else s += 2; } else if (n % i == 0) { a[count][0] = i; a[count][1] = n / i; count++; } } for (int j = 0; j < count; j++) { while (a[j][1] >= a[j][0]) { if (a[j][1] % a[j][0] == 1) { s++; break; } else if (a[j][1] % a[j][0] == 0) a[j][1] = a[j][1] / a[j][0]; else break; } if (a[j][1] == 1) s++; } cout << s + 2; return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> using namespace std; typedef long long ll; typedef double db; ll mod = 1e9 + 7; ll a[10000][2]; int main() { ll n; int count = 0; cin >> n; ll s = 0; if (n == 2) s--; for (ll i = 2; i * i <= n; i++) { if (n % i == 1) { if ((n - 1) / i == i) s++; else s += 2; } else if (n % i == 0) { a[count][0] = i; a[count][1] = n / i; count++; } } for (int j = 0; j < count; j++) { while (a[j][1] >= a[j][0]) { if (a[j][1] % a[j][0] == 1) { s++; break; } else if (a[j][1] % a[j][0] == 0) a[j][1] = a[j][1] / a[j][0]; else break; } if (a[j][1] == 1) s++; } cout << s + 2; return 0; }
replace
16
17
16
17
0
p02722
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG // これつけるとA[N]でもいいらしい // for文のマクロ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define big 1000000007 #define all(a) sort((a).begin(), (a).end()) // ソートのマクロ #define Re(a) reverse((a).begin(), (a).end()) #define YN(a) \ if (a) { \ cout << "Yes" << endl; \ } else \ cout << "No" << endl; // 条件によってYes、Noを出力する int main() { int64_t n; cin >> n; int64_t count = 0; set<int64_t> s; s.insert(n); s.insert(n - 1); for (int64_t i = 2; i * i <= n; i++) { if (n % i == 0) { s.insert(i); s.insert(n / i); } } for (int64_t i = 2; i * i <= n; i++) { if ((n - 1) % i == 0) { s.insert(i); s.insert((n - 1) / i); } } for (auto c : s) { // cout<<c<<endl; int64_t k = c; int64_t N = n; if (N % k == 0) { while (N % k == 0) { N = N / k; } if (N % k == 1) { count++; } } else if (N % k == 1) { count++; } } // cout<<count<<endl; cout << count << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG // これつけるとA[N]でもいいらしい // for文のマクロ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define big 1000000007 #define all(a) sort((a).begin(), (a).end()) // ソートのマクロ #define Re(a) reverse((a).begin(), (a).end()) #define YN(a) \ if (a) { \ cout << "Yes" << endl; \ } else \ cout << "No" << endl; // 条件によってYes、Noを出力する int main() { int64_t n; cin >> n; int64_t count = 0; set<int64_t> s; s.insert(n); if (n >= 3) { s.insert(n - 1); } for (int64_t i = 2; i * i <= n; i++) { if (n % i == 0) { s.insert(i); s.insert(n / i); } } for (int64_t i = 2; i * i <= n; i++) { if ((n - 1) % i == 0) { s.insert(i); s.insert((n - 1) / i); } } for (auto c : s) { // cout<<c<<endl; int64_t k = c; int64_t N = n; if (N % k == 0) { while (N % k == 0) { N = N / k; } if (N % k == 1) { count++; } } else if (N % k == 1) { count++; } } // cout<<count<<endl; cout << count << endl; }
replace
20
21
20
23
TLE