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
p02647
C++
Runtime Error
/** * created: 13.06.2020 21:08:42 **/ #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[k]; rep(ki, k) { vector<int> b(n + 1); rep(i, n) { int l = max(0, i - a[i]); int r = min(i + a[i] + 1, n); b[l]++; b[r]--; } rep(i, n) b[i + 1] += b[i]; b.pop_back(); if (a == b) break; a = b; } rep(i, n) cout << a[i] << endl; return 0; }
/** * created: 13.06.2020 21:08:42 **/ #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(ki, k) { vector<int> b(n + 1); rep(i, n) { int l = max(0, i - a[i]); int r = min(i + a[i] + 1, n); b[l]++; b[r]--; } rep(i, n) b[i + 1] += b[i]; b.pop_back(); if (a == b) break; a = b; } rep(i, n) cout << a[i] << endl; return 0; }
replace
16
17
16
17
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> inp(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> inp.at(i); // inp.at(i) = 0; } vector<int> data(n + 2, 0); if (k >= 3000) { k = 3000; } for (int j = 0; j < k; j++) { for (int i = 1; i <= n; i++) { int left = max(i - inp.at(i), 1); int right = min(i + inp.at(i) + 1, n + 1); data.at(left)++; data.at(right)--; } int temp = 0; for (int i = 1; i <= n; i++) { temp += data.at(i); data.at(i) = 0; inp.at(i) = temp; } } // 確認用 for (int i = 1; i <= n; i++) { cout << inp.at(i); if (i != n) { cout << " "; } } // cout << " " << j+1 << endl; cout << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> inp(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> inp.at(i); // inp.at(i) = 0; } vector<int> data(n + 2, 0); if (k >= 2000) { k = 2000; } for (int j = 0; j < k; j++) { for (int i = 1; i <= n; i++) { int left = max(i - inp.at(i), 1); int right = min(i + inp.at(i) + 1, n + 1); data.at(left)++; data.at(right)--; } int temp = 0; for (int i = 1; i <= n; i++) { temp += data.at(i); data.at(i) = 0; inp.at(i) = temp; } } // 確認用 for (int i = 1; i <= n; i++) { cout << inp.at(i); if (i != n) { cout << " "; } } // cout << " " << j+1 << endl; cout << endl; }
replace
15
17
15
17
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; bool done(vector<int> &A, int N) { for (auto x : A) if (x != N) return false; return true; } vector<int> eval(vector<int> &A, int N) { map<int, int> cumul; for (int i = 0; i < N; i++) cumul[max(0, i - A[i])]++, cumul[i + A[i] + 1]--; vector<int> ret(N, 0); ret[0] = cumul[0]; for (int i = 1; i < N; i++) ret[i] = ret[i - 1] + cumul[i]; return ret; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < K; i++) { if (done(A, N)) break; A = eval(A, N); } for (int i = 0; i < N; i++) cout << A[i] << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; bool done(vector<int> &A, int N) { for (auto x : A) if (x != N) return false; return true; } vector<int> eval(vector<int> &A, int N) { vector<int> cumul(2 * N, 0); for (int i = 0; i < N; i++) cumul[max(0, i - A[i])]++, cumul[i + A[i] + 1]--; vector<int> ret(N, 0); ret[0] = cumul[0]; for (int i = 1; i < N; i++) ret[i] = ret[i - 1] + cumul[i]; return ret; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < K; i++) { if (done(A, N)) break; A = eval(A, N); } for (int i = 0; i < N; i++) cout << A[i] << " "; cout << "\n"; return 0; }
replace
19
20
19
20
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define li long long int #define rep(i, to) for (li i = 0; i < ((li)(to)); i++) #define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++) #define pb push_back #define sz(v) ((li)(v).size()) #define bgn(v) ((v).begin()) #define eend(v) ((v).end()) #define allof(v) (v).begin(), (v).end() #define dodp(v, n) memset(v, (li)n, sizeof(v)) #define bit(n) (1ll << (li)(n)) #define mp(a, b) make_pair(a, b) #define rin rep(i, n) #define EPS 1e-12 #define ETOL 1e-8 #define MOD 1000000007 typedef pair<li, li> PI; #define INF bit(60) #define DBGP 1 #define idp if (DBGP) #define F first #define S second #define p2(a, b) idp cout << a << "\t" << b << endl #define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl #define p4(a, b, c, d) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl #define p5(a, b, c, d, e) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl #define p6(a, b, c, d, e, f) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << endl #define p7(a, b, c, d, e, f, g) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << endl #define p8(a, b, c, d, e, f, g, h) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << endl #define p9(a, b, c, d, e, f, g, h, i) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << "\t" << i << endl #define p10(a, b, c, d, e, f, g, h, i, j) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl #define foreach(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) #define p2p(x) idp p2((x).F, (x).S) #define dump(x, n) \ idp { \ rep(i, n) { cout << x[i] << " "; } \ puts(""); \ } #define dump2(x, n) \ idp { \ rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \ puts(""); \ } #define dumpi(x) \ idp { \ foreach (it, x) { \ cout << (*it) << " "; \ } \ puts(""); \ } #define dumpi2(x) \ idp { \ foreach (it, x) { \ cout << "[" << (it)->F << " , " << (it)->S << "] "; \ } \ puts(""); \ } #define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j] #define dump2d(a, w, h) \ rep(i, h) { \ rep(j, w) cout << a[i][j] << " "; \ puts(""); \ } typedef pair<li, li> PI; li n, k; li a[200200]; li imos[200200]; int main() { cin >> n >> k; rin { cin >> a[i]; } rep(i, k) { // dump(a, n); rep(j, n + 1) { imos[j] = 0; } rep(j, n) { // p4(i, j, max(0ll, j - a[j]), min(n, j + a[j] + 1)); imos[max(0ll, j - a[j])]++; imos[min(n, j + a[j] + 1)]--; } // dump(imos, n + 1); a[0] = imos[0]; rep(j, n) { a[j + 1] = a[j] + imos[j + 1]; } } rin { cout << a[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define li long long int #define rep(i, to) for (li i = 0; i < ((li)(to)); i++) #define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++) #define pb push_back #define sz(v) ((li)(v).size()) #define bgn(v) ((v).begin()) #define eend(v) ((v).end()) #define allof(v) (v).begin(), (v).end() #define dodp(v, n) memset(v, (li)n, sizeof(v)) #define bit(n) (1ll << (li)(n)) #define mp(a, b) make_pair(a, b) #define rin rep(i, n) #define EPS 1e-12 #define ETOL 1e-8 #define MOD 1000000007 typedef pair<li, li> PI; #define INF bit(60) #define DBGP 1 #define idp if (DBGP) #define F first #define S second #define p2(a, b) idp cout << a << "\t" << b << endl #define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl #define p4(a, b, c, d) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl #define p5(a, b, c, d, e) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl #define p6(a, b, c, d, e, f) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << endl #define p7(a, b, c, d, e, f, g) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << endl #define p8(a, b, c, d, e, f, g, h) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << endl #define p9(a, b, c, d, e, f, g, h, i) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << "\t" << i << endl #define p10(a, b, c, d, e, f, g, h, i, j) \ idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \ << f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl #define foreach(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) #define p2p(x) idp p2((x).F, (x).S) #define dump(x, n) \ idp { \ rep(i, n) { cout << x[i] << " "; } \ puts(""); \ } #define dump2(x, n) \ idp { \ rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \ puts(""); \ } #define dumpi(x) \ idp { \ foreach (it, x) { \ cout << (*it) << " "; \ } \ puts(""); \ } #define dumpi2(x) \ idp { \ foreach (it, x) { \ cout << "[" << (it)->F << " , " << (it)->S << "] "; \ } \ puts(""); \ } #define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j] #define dump2d(a, w, h) \ rep(i, h) { \ rep(j, w) cout << a[i][j] << " "; \ puts(""); \ } typedef pair<li, li> PI; li n, k; li a[200200]; li imos[200200]; int main() { cin >> n >> k; rin { cin >> a[i]; } rep(i, k) { // dump(a, n); rep(j, n + 1) { imos[j] = 0; } rep(j, n) { // p4(i, j, max(0ll, j - a[j]), min(n, j + a[j] + 1)); imos[max(0ll, j - a[j])]++; imos[min(n, j + a[j] + 1)]--; } // dump(imos, n + 1); a[0] = imos[0]; rep(j, n) { a[j + 1] = a[j] + imos[j + 1]; } bool all_max = true; rep(j, n) { if (a[j] != n) { all_max = false; break; } } if (all_max) { break; } } rin { cout << a[i] << " "; } cout << endl; return 0; }
insert
103
103
103
113
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> inline void chkmax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void chkmin(T &x, T y) { if (x > y) x = y; } inline int read() { #define nc getchar() int x = 0; char c = nc; while (c < 48) c = nc; while (c > 47) x = x * 10 + (c ^ 48), c = nc; return x; #undef nc } typedef long long ll; const int maxn = 2e5 + 10; int n, k, A[maxn], tmp[maxn]; void solve() { cin >> n >> k; rep(i, 1, n) A[i] = read(); rep(T, 1, k) { memset(tmp, 0, (n + 1) << 2); rep(i, 1, n) { int l = i - A[i], r = i + A[i]; tmp[l]++, tmp[r + 1]--; } bool flg = 1; rep(i, 1, n) { tmp[i] += tmp[i - 1]; A[i] = tmp[i]; flg &= A[i] == n; } if (flg) break; } rep(i, 1, n) printf("%d ", A[i]); } int main() { // int T = read(); // while (T--) solve(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> inline void chkmax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void chkmin(T &x, T y) { if (x > y) x = y; } inline int read() { #define nc getchar() int x = 0; char c = nc; while (c < 48) c = nc; while (c > 47) x = x * 10 + (c ^ 48), c = nc; return x; #undef nc } typedef long long ll; const int maxn = 2e5 + 10; int n, k, A[maxn], tmp[maxn]; void solve() { cin >> n >> k; rep(i, 1, n) A[i] = read(); rep(T, 1, k) { memset(tmp, 0, (n + 1) << 2); rep(i, 1, n) { int l = i - A[i], r = i + A[i]; chkmax(l, 1), chkmin(r, n); tmp[l]++, tmp[r + 1]--; } bool flg = 1; rep(i, 1, n) { tmp[i] += tmp[i - 1]; A[i] = tmp[i]; flg &= A[i] == n; } if (flg) break; } rep(i, 1, n) printf("%d ", A[i]); } int main() { // int T = read(); // while (T--) solve(); solve(); return 0; }
insert
41
41
41
42
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) // #define int long long #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; 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; } void solve() { LL n, k; cin >> n >> k; VLL a(n); REP(i, 0, n) cin >> a[i]; VI imos(n + 1); REP(j, 0, k) { REP(i, 0, n + 1) imos[i] = 0; REP(i, 0, n) { imos[max(0LL, i - a[i])]++; imos[min(n, i + a[i] + 1)]--; } REP(i, 1, n + 1) imos[i] += imos[i - 1]; REP(i, 0, n) a[i] = imos[i]; } REP(i, 0, n) cout << a[i] << " "; cout << endl; } signed main() { solve(); return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) // #define int long long #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; 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; } void solve() { LL n, k; cin >> n >> k; VLL a(n); REP(i, 0, n) cin >> a[i]; VI imos(n + 1); REP(j, 0, k) { REP(i, 0, n + 1) imos[i] = 0; REP(i, 0, n) { imos[max(0LL, i - a[i])]++; imos[min(n, i + a[i] + 1)]--; } REP(i, 1, n + 1) imos[i] += imos[i - 1]; REP(i, 0, n) a[i] = imos[i]; bool done = true; REP(i, 0, n) if (a[i] < n) { done = false; break; } if (done) break; } REP(i, 0, n) cout << a[i] << " "; cout << endl; } signed main() { solve(); return 0; }
insert
83
83
83
90
TLE
p02647
Python
Time Limit Exceeded
from itertools import accumulate def main(): number, operations = [int(x) for x in input().split()] dists = [int(x) for x in input().split()] for ope_count in range(operations): temp = [0] * (number + 1) for i, v in enumerate(dists): left = max(i - v, 0) right = min(i + v + 1, number) temp[left] += 1 temp[right] -= 1 templi = list(accumulate(temp)) if templi == dists: dists = templi break else: dists = templi print(*list(dists)[:-1]) if __name__ == "__main__": main()
from itertools import accumulate def main(): number, operations = [int(x) for x in input().split()] dists = [int(x) for x in input().split()] for ope_count in range(operations): temp = [0] * (number + 1) for i, v in enumerate(dists): left = max(i - v, 0) right = min(i + v + 1, number) temp[left] += 1 temp[right] -= 1 templi = list(accumulate(temp)) if templi == dists: break else: dists = templi print(*list(dists)[:-1]) if __name__ == "__main__": main()
delete
16
17
16
16
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int x = (fr); x < (to); x++) #define rep(x, to) for (int x = 0; x < (to); x++) #define repr(x, fr, to) for (int x = (fr); x >= (to); x--) #define all(c) c.begin(), c.end() #define sz(v) (int)v.size() using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; VL a(n + 1); rep(i, n) cin >> a[i]; if (k > n) { rep(i, n) cout << n << " "; cout << "\n"; return 0; } VL sk(n + 1); rep(q, k) { fill(all(sk), 0); rep(i, n) { int st = max<ll>(0, i - a[i]); int ed = min<ll>(n, i + a[i] + 1); sk[st] += 1; sk[ed] -= 1; } rep(i, n) sk[i + 1] += sk[i]; // rep(i, n) cout << sk[i] << " "; dbg("q=",q); a = sk; if (count(sk.begin(), sk.begin() + k, n) == n) break; } rep(i, n) cout << sk[i] << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int x = (fr); x < (to); x++) #define rep(x, to) for (int x = 0; x < (to); x++) #define repr(x, fr, to) for (int x = (fr); x >= (to); x--) #define all(c) c.begin(), c.end() #define sz(v) (int)v.size() using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; VL a(n + 1); rep(i, n) cin >> a[i]; if (k > n) { rep(i, n) cout << n << " "; cout << "\n"; return 0; } VL sk(n + 1); rep(q, k) { fill(all(sk), 0); rep(i, n) { int st = max<ll>(0, i - a[i]); int ed = min<ll>(n, i + a[i] + 1); sk[st] += 1; sk[ed] -= 1; } rep(i, n) sk[i + 1] += sk[i]; // rep(i, n) cout << sk[i] << " "; dbg("q=",q); a = sk; if (count(sk.begin(), sk.begin() + k, n) == n) break; if (q * n > 20000000) break; } rep(i, n) cout << sk[i] << " "; cout << "\n"; return 0; }
insert
46
46
46
48
TLE
p02647
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; 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 ll INF = 1e18; const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> cur(n + 1), next(n + 1); rep(i, n) { cin >> cur[i]; } rep(i, k) { bool all = true; rep(j, n) { ll pos1 = max(j - cur[j], 0LL); ll pos2 = min(j + cur[j] + 1, n); next[pos1]++; next[pos2]--; } rep(j, n + 1) { if (j) { next[j] += next[j - 1]; } } rep(j, n + 1) { if (cur[j] != next[j]) all = false; } cur = next; next = vector<ll>(n); if (all) break; } rep(i, n) { if (i) cout << " "; cout << cur[i]; } cout << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; 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 ll INF = 1e18; const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> cur(n + 1), next(n + 1); rep(i, n) { cin >> cur[i]; } rep(i, k) { bool all = true; rep(j, n) { ll pos1 = max(j - cur[j], 0LL); ll pos2 = min(j + cur[j] + 1, n); next[pos1]++; next[pos2]--; } rep(j, n + 1) { if (j) { next[j] += next[j - 1]; } } rep(j, n) { if (cur[j] != next[j]) all = false; } cur = next; next = vector<ll>(n); if (all) break; } rep(i, n) { if (i) cout << " "; cout << cur[i]; } cout << endl; return 0; }
replace
52
53
52
53
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <iostream> #include <queue> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; constexpr int64_t MOD = 1e9 + 7; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int32_t N, K; cin >> N >> K; vector<int32_t> A(N, 0); for (auto &a : A) { cin >> a; } for (int k = 0; k < K; k++) { vector<int> begin(N, 0); vector<int> end(N, 0); for (int i = 0; i < N; i++) { int b = max(0, i - A[i]); int e = min(N - 1, i + A[i]); begin[b]++; end[e]++; } int cum_beg = begin[0]; int cum_end = 0; A[0] = cum_beg; for (int i = 1; i < N; i++) { cum_beg += begin[i]; cum_end += end[i - 1]; A[i] = cum_beg - cum_end; } } for (int i = 0; i < N; i++) { cout << A[i] << " "; } cout << endl; return 0; }
#include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <iostream> #include <queue> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; constexpr int64_t MOD = 1e9 + 7; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int32_t N, K; cin >> N >> K; vector<int32_t> A(N, 0); for (auto &a : A) { cin >> a; } for (int k = 0; k < K; k++) { vector<int> begin(N, 0); vector<int> end(N, 0); for (int i = 0; i < N; i++) { int b = max(0, i - A[i]); int e = min(N - 1, i + A[i]); begin[b]++; end[e]++; } int cum_beg = begin[0]; int cum_end = 0; A[0] = cum_beg; for (int i = 1; i < N; i++) { cum_beg += begin[i]; cum_end += end[i - 1]; A[i] = cum_beg - cum_end; } if (begin[0] == N && end[N - 1] == N) break; } for (int i = 0; i < N; i++) { cout << A[i] << " "; } cout << endl; return 0; }
insert
39
39
39
41
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define forn(i, a, b) for (int i = a; i < b; i++) #define fi first #define se second #define fast ios_base::sync_with_stdio(false); using namespace std; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; void solve() { int n, k; cin >> n >> k; vi a(n); forn(i, 0, n) cin >> a[i]; while (k--) { vi b(n); for (int i = 0; i < n; i++) { int from = max(i - a[i], 0); int to = min(n - 1, i + a[i]); b[from] += 1; if (to < n - 1) b[to + 1] -= 1; } vi cpya = a; for (int i = 0; i < n; i++) { a[i] = b[i]; b[i + 1] += b[i]; } if (cpya == a) break; // for(int i =0;i<n;i+) } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t;cin >> t;while(t--) solve(); }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define forn(i, a, b) for (int i = a; i < b; i++) #define fi first #define se second #define fast ios_base::sync_with_stdio(false); using namespace std; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; void solve() { int n, k; cin >> n >> k; vi a(n); forn(i, 0, n) cin >> a[i]; while (k--) { vi b(n + 1); for (int i = 0; i < n; i++) { int from = max(i - a[i], 0); int to = min(n - 1, i + a[i]); b[from] += 1; if (to < n - 1) b[to + 1] -= 1; } vi cpya = a; for (int i = 0; i < n; i++) { a[i] = b[i]; b[i + 1] += b[i]; } if (cpya == a) break; // for(int i =0;i<n;i+) } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t;cin >> t;while(t--) solve(); }
replace
21
22
21
22
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <utility> #include <vector> #define INF 1e16 #define N (1000000007) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, P> Q; ll sum[200010]; int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n + 1); for (int i = 0; i < n; i++) cin >> a[i + 1]; for (int q = 0; q < k; q++) { for (int i = 1; i <= n; i++) { sum[max(1LL, i - a[i])]++; sum[min(n + 1, i + a[i] + 1)]--; } for (int i = 1; i <= n + 1; i++) { sum[i] += sum[i - 1]; } for (int i = 1; i <= n; i++) { a[i] = sum[i]; } for (int i = 0; i <= n + 1; i++) sum[i] = 0; } for (int i = 1; i <= n; i++) { if (i == n) cout << a[i] << endl; else cout << a[i] << " "; } return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <utility> #include <vector> #define INF 1e16 #define N (1000000007) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, P> Q; ll sum[200010]; int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n + 1); for (int i = 0; i < n; i++) cin >> a[i + 1]; for (int q = 0; q < k; q++) { for (int i = 1; i <= n; i++) { sum[max(1LL, i - a[i])]++; sum[min(n + 1, i + a[i] + 1)]--; } for (int i = 1; i <= n + 1; i++) { sum[i] += sum[i - 1]; } for (int i = 1; i <= n; i++) { a[i] = sum[i]; } bool flag = true; for (int i = 1; i <= n; i++) { if (a[i] != n) flag = false; } if (flag) break; for (int i = 0; i <= n + 1; i++) sum[i] = 0; } for (int i = 1; i <= n; i++) { if (i == n) cout << a[i] << endl; else cout << a[i] << " "; } return 0; }
insert
36
36
36
43
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 200005; int n, k; int a[N]; int b[N]; int q[N]; void solv() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= k; ++i) { for (int i = 1; i <= n; ++i) q[i] = 0; for (int i = 1; i <= n; ++i) { q[max(1, i - a[i])]++; q[min(n + 1, i + a[i] + 1)]--; } for (int i = 1; i <= n; ++i) q[i] += q[i - 1]; for (int i = 1; i <= n; ++i) a[i] = q[i]; bool z = true; for (int i = 1; i <= n; ++i) { if (a[i] != n) { z = false; break; } } } for (int i = 1; i <= n; ++i) printf("%d ", a[i]); printf("\n"); } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // SOMETHING // ios_base::sync_with_stdio(false), cin.tie(0); solv(); return 0; } // while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 200005; int n, k; int a[N]; int b[N]; int q[N]; void solv() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= k; ++i) { for (int i = 1; i <= n; ++i) q[i] = 0; for (int i = 1; i <= n; ++i) { q[max(1, i - a[i])]++; q[min(n + 1, i + a[i] + 1)]--; } for (int i = 1; i <= n; ++i) q[i] += q[i - 1]; for (int i = 1; i <= n; ++i) a[i] = q[i]; bool z = true; for (int i = 1; i <= n; ++i) { if (a[i] != n) { z = false; break; } } if (z) break; } for (int i = 1; i <= n; ++i) printf("%d ", a[i]); printf("\n"); } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // SOMETHING // ios_base::sync_with_stdio(false), cin.tie(0); solv(); return 0; } // while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
insert
41
41
41
43
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200005; ll n, k; array<ll, N> old, nw; bitset<N> used; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n >> k; vector<ll> a(n); for (auto &i : a) cin >> i; for (int i = 0; i < n; ++i) { old[max(0ll, i - a[i])]++; old[min(n, i + a[i] + 1)]--; } for (int i = 1; i < k; ++i) { ll psum = 0; used.reset(); for (int j = 0; j < n; ++j) { if (i % 2) { psum += old[j]; // cout << i << ' ' << j << ' ' << psum << '\n'; ll mn = max(0ll, j - psum), mx = min(n, j + psum + 1); if (!used[mn]) { used[mn] = 1; nw[mn] = 0; } if (!used[mx]) { used[mx] = 1; nw[mx] = 0; } // cout << j << ' ' << mn << ' ' << mx << '\n'; nw[mn]++; nw[mx]--; } else { psum += nw[j]; // cout << i << ' ' << j << ' ' << psum << '\n'; ll mn = max(0ll, j - psum), mx = min(n, j + psum + 1); if (!used[j]) { used[j] = 1; old[j] = 0; } if (!used[mn]) { used[mn] = 1; old[mn] = 0; } if (!used[mx]) { used[mx] = 1; old[mx] = 0; } // cout << j << ' ' << mn << ' ' << mx << '\n'; // cout << old[mn] << ' ' << old[mx] << '\n'; old[mn]++; old[mx]--; } } if (nw == old) break; } if (k % 2) { ll psum = 0; for (int i = 0; i < n; ++i) { psum += old[i]; cout << psum << ' '; } } else { ll psum = 0; for (int i = 0; i < n; ++i) { psum += nw[i]; cout << psum << ' '; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200005; ll n, k; array<ll, N> old, nw; bitset<N> used; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n >> k; vector<ll> a(n); for (auto &i : a) cin >> i; for (int i = 0; i < n; ++i) { old[max(0ll, i - a[i])]++; old[min(n, i + a[i] + 1)]--; } for (int i = 1; i < k; ++i) { ll psum = 0; used.reset(); for (int j = 0; j < n; ++j) { if (i % 2) { psum += old[j]; // cout << i << ' ' << j << ' ' << psum << '\n'; ll mn = max(0ll, j - psum), mx = min(n, j + psum + 1); if (!used[j]) { used[j] = 1; nw[j] = 0; } if (!used[mn]) { used[mn] = 1; nw[mn] = 0; } if (!used[mx]) { used[mx] = 1; nw[mx] = 0; } // cout << j << ' ' << mn << ' ' << mx << '\n'; nw[mn]++; nw[mx]--; } else { psum += nw[j]; // cout << i << ' ' << j << ' ' << psum << '\n'; ll mn = max(0ll, j - psum), mx = min(n, j + psum + 1); if (!used[j]) { used[j] = 1; old[j] = 0; } if (!used[mn]) { used[mn] = 1; old[mn] = 0; } if (!used[mx]) { used[mx] = 1; old[mx] = 0; } // cout << j << ' ' << mn << ' ' << mx << '\n'; // cout << old[mn] << ' ' << old[mx] << '\n'; old[mn]++; old[mx]--; } } if (nw == old) break; } if (k % 2) { ll psum = 0; for (int i = 0; i < n; ++i) { psum += old[i]; cout << psum << ' '; } } else { ll psum = 0; for (int i = 0; i < n; ++i) { psum += nw[i]; cout << psum << ' '; } } }
insert
30
30
30
34
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define repr(e, x) for (auto &e : x) using namespace std; typedef long long ll; typedef long double ld; ll N, K; ll A[200000]; ll sum[200001]; ll ans[200001]; int main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(j, K) { rep(i, N) { sum[max((ll)0, i - A[i])]++; sum[min(i + A[i] + 1, N)]--; } repn(i, N - 1) { sum[i] += sum[i - 1]; } rep(i, N) { A[i] = sum[i]; } fill(sum, sum + N, 0); } rep(i, N) cout << A[i] << ' '; cout << endl; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define repr(e, x) for (auto &e : x) using namespace std; typedef long long ll; typedef long double ld; ll N, K; ll A[200000]; ll sum[200001]; ll ans[200001]; int main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(j, K) { rep(i, N) { sum[max((ll)0, i - A[i])]++; sum[min(i + A[i] + 1, N)]--; } repn(i, N - 1) { sum[i] += sum[i - 1]; } rep(i, N) { A[i] = sum[i]; } fill(sum, sum + N, 0); bool flag = true; rep(i, N) { flag &= (A[i] == N); } if (flag) break; } rep(i, N) cout << A[i] << ' '; cout << endl; }
insert
35
35
35
39
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, k; int a[200010]; int cf[200010]; int fir; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] >= i - 1) { fir++; } if (i - a[i] >= 2) { cf[i - a[i]]++; } if (i + a[i] + 1 <= n) { cf[i + a[i] + 1]--; } } while (k--) { a[1] = fir; int cnt = 0; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + cf[i]; cf[i] = 0; cnt += (a[i] >= n); } fir = 0; if (cnt >= n) { break; } for (int i = 1; i <= n; i++) { if (a[i] >= i - 1) { fir++; } if (i - a[i] >= 2) { cf[i - a[i]]++; } if (i + a[i] + 1 <= n) { cf[i + a[i] + 1]--; } } } for (int i = 1; i <= n; i++) { cout << a[i] << ' '; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[200010]; int cf[200010]; int fir; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] >= i - 1) { fir++; } if (i - a[i] >= 2) { cf[i - a[i]]++; } if (i + a[i] + 1 <= n) { cf[i + a[i] + 1]--; } } while (k--) { a[1] = fir; int cnt = 0; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + cf[i]; cf[i] = 0; cnt += (a[i] >= n); } cnt += (a[1] >= n); fir = 0; if (cnt >= n) { break; } for (int i = 1; i <= n; i++) { if (a[i] >= i - 1) { fir++; } if (i - a[i] >= 2) { cf[i - a[i]]++; } if (i + a[i] + 1 <= n) { cf[i + a[i] + 1]--; } } } for (int i = 1; i <= n; i++) { cout << a[i] << ' '; } return 0; }
insert
28
28
28
29
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; ll a[212345], b[212345]; int main() { ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { for (int m = 0; m < n + 1; m++) { b[m] = 0; } for (int m = 0; m < n; m++) { b[max((ll)0, m - a[m])]++; b[min(n - 1, m + a[m]) + 1]--; } ll count = 0; for (int m = 0; m < n; m++) { count += b[m]; a[m] = count; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; ll a[212345], b[212345]; int main() { ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } if (pow(2, k - 50) > n) { for (int i = 0; i < n; i++) { cout << n << " "; } return 0; } for (int i = 0; i < k; i++) { for (int m = 0; m < n + 1; m++) { b[m] = 0; } for (int m = 0; m < n; m++) { b[max((ll)0, m - a[m])]++; b[min(n - 1, m + a[m]) + 1]--; } ll count = 0; for (int m = 0; m < n; m++) { count += b[m]; a[m] = count; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } return 0; }
replace
14
15
14
20
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); // naive for (int i = 1; i <= k; i++) { vector<int> imos(n + 1, 0); for (int j = 0; j < n; j++) { int pp = max(0, j - a.at(j)); int mp = min(n, j + a.at(j) + 1); imos.at(pp)++; imos.at(mp)--; } for (int j = 1; j < n; j++) imos.at(j) += imos.at(j - 1); for (int j = 0; j < n; j++) a.at(j) = imos.at(j); } for (int i = 0; i < n; i++) { if (i == 0) cout << a.at(i); else cout << " " << a.at(i); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); // naive for (int i = 1; i <= k; i++) { vector<int> imos(n + 1, 0); for (int j = 0; j < n; j++) { int pp = max(0, j - a.at(j)); int mp = min(n, j + a.at(j) + 1); imos.at(pp)++; imos.at(mp)--; } for (int j = 1; j < n; j++) imos.at(j) += imos.at(j - 1); bool x = false; for (int j = 0; j < n; j++) { if (a.at(j) != imos.at(j)) { x = true; break; } } if (!x) break; for (int j = 0; j < n; j++) a.at(j) = imos.at(j); } for (int i = 0; i < n; i++) { if (i == 0) cout << a.at(i); else cout << " " << a.at(i); } }
insert
21
21
21
30
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 1e5 + 5; int a[sz], b[sz]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) scanf("%d", &a[i]); while (k--) { for (int i = 0; i < n; i++) { int x = max(0, i - a[i]); int y = min(n, i + a[i] + 1); b[x]++, b[y]--; } for (int i = 0, j = 0; i < n; i++) { j += b[i]; a[i] = j, b[i] = 0; } bool no = 1; for (int i = 0; i < n; i++) if (a[i] < n) no = 0; if (no) break; } for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", a[i]); } puts(""); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 2e5 + 5; int a[sz], b[sz]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) scanf("%d", &a[i]); while (k--) { for (int i = 0; i < n; i++) { int x = max(0, i - a[i]); int y = min(n, i + a[i] + 1); b[x]++, b[y]--; } for (int i = 0, j = 0; i < n; i++) { j += b[i]; a[i] = j, b[i] = 0; } bool no = 1; for (int i = 0; i < n; i++) if (a[i] < n) no = 0; if (no) break; } for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", a[i]); } puts(""); }
replace
3
4
3
4
0
p02647
C++
Time Limit Exceeded
/* * Since g++10 is released, some characters is not valid inside #if 0 :( * So, why not using clang++? :D * Date: echo -n ' ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim). * Solution: To be updated after "Accept". * Digression: * CopyRight: ▁▃▄▄▄▃▃▃▃▄▶ ▗▇▀▔ ▔▔▔▔ ▄▛ ▃▅━━■▄▂ ▟▊ ▐▘ ▀▙ ▟▜▌ ▐▖ ▋ ▐▍ ▟▘ ▜ ▝▀▇▆●▘ ▐▌ ▗▟▘ ▜▃ ▁▅▛ ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔ ▔▔▔▔▔▔ */ #include <algorithm> #include <cstdio> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; struct { inline operator int() { int x; return scanf("%d", &x), x; } inline operator ll() { ll x; return scanf("%lld", &x), x; } template <class T> inline void operator()(T &x) { x = *this; } template <class T, class... A> inline void operator()(T &x, A &...a) { x = *this; this->operator()(a...); } } read; const int maxn = 200005; int a[maxn], b[maxn]; int main() { int n = read, m = read; for (int i = 1; i <= n; i++) read(a[i]); while (m--) { for (int i = 1; i <= n; i++) { int l = std::max(1, i - a[i]), r = std::min(i + a[i], n); ++b[l]; --b[r + 1]; } bool full = 0; for (int i = 1; i <= n; i++) { a[i] = b[i] + a[i - 1]; b[i] = 0; full &= a[i] == n; } if (full) break; } for (int i = 1; i <= n; i++) printf("%d ", a[i]); puts(""); }
/* * Since g++10 is released, some characters is not valid inside #if 0 :( * So, why not using clang++? :D * Date: echo -n ' ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim). * Solution: To be updated after "Accept". * Digression: * CopyRight: ▁▃▄▄▄▃▃▃▃▄▶ ▗▇▀▔ ▔▔▔▔ ▄▛ ▃▅━━■▄▂ ▟▊ ▐▘ ▀▙ ▟▜▌ ▐▖ ▋ ▐▍ ▟▘ ▜ ▝▀▇▆●▘ ▐▌ ▗▟▘ ▜▃ ▁▅▛ ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔ ▔▔▔▔▔▔ */ #include <algorithm> #include <cstdio> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; struct { inline operator int() { int x; return scanf("%d", &x), x; } inline operator ll() { ll x; return scanf("%lld", &x), x; } template <class T> inline void operator()(T &x) { x = *this; } template <class T, class... A> inline void operator()(T &x, A &...a) { x = *this; this->operator()(a...); } } read; const int maxn = 200005; int a[maxn], b[maxn]; int main() { int n = read, m = read; for (int i = 1; i <= n; i++) read(a[i]); while (m--) { for (int i = 1; i <= n; i++) { int l = std::max(1, i - a[i]), r = std::min(i + a[i], n); ++b[l]; --b[r + 1]; } bool full = 1; for (int i = 1; i <= n; i++) { a[i] = b[i] + a[i - 1]; b[i] = 0; full &= a[i] == n; } if (full) break; } for (int i = 1; i <= n; i++) printf("%d ", a[i]); puts(""); }
replace
59
60
59
60
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { int n, k; cin >> n >> k; vint a(n); rep(i, n) cin >> a[i]; rep(i, k) { vint c(n + 1, 0); rep(j, n) { c[max(j - a[j], 0)]++; c[min(j + a[j] + 1, n)]--; } vint a_tmp(n); a_tmp[0] = c[0]; REP(i, n) a_tmp[i] = a_tmp[i - 1] + c[i]; swap(a_tmp, a); bool ok = true; // rep(i,n-1) { // if (a[i] != a[i+1]) ok = false; // } // if (ok) break; } rep(i, n) cout << a[i] << " "; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { int n, k; cin >> n >> k; vint a(n); rep(i, n) cin >> a[i]; rep(i, k) { vint c(n + 1, 0); rep(j, n) { c[max(j - a[j], 0)]++; c[min(j + a[j] + 1, n)]--; } vint a_tmp(n); a_tmp[0] = c[0]; REP(i, n) a_tmp[i] = a_tmp[i - 1] + c[i]; swap(a_tmp, a); bool ok = true; rep(i, n - 1) { if (a[i] != a[i + 1]) ok = false; } if (ok && a[0] == n) break; } rep(i, n) cout << a[i] << " "; }
replace
47
51
47
53
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint gcd(lint x, lint y) { if (x == 0) { return y; } else { return gcd(y % x, x); } } lint lcm(lint x, lint y) { return x / gcd(x, y) * y; } lint C(lint n, lint k) { if (n == k) { return 1; } else if (n < k) { return 0; } else if (k == 0) { return 1; } else if (k == 1) { return n; } else return C(n - 1, k - 1) + C(n - 1, k); } lint P(lint n, lint k) { if (k == 1) { return n; } return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007); } int main() { lint n, k; cin >> n >> k; vector<lint> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<lint> c(n + 1, 0); for (int j = 0; j < n; j++) { c[max(0LL, j - a[j])]++; c[min(j + a[j] + 1, n)]--; } a[0] = c[0]; for (int j = 1; j < n; j++) { a[j] = c[j] + a[j - 1]; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint gcd(lint x, lint y) { if (x == 0) { return y; } else { return gcd(y % x, x); } } lint lcm(lint x, lint y) { return x / gcd(x, y) * y; } lint C(lint n, lint k) { if (n == k) { return 1; } else if (n < k) { return 0; } else if (k == 0) { return 1; } else if (k == 1) { return n; } else return C(n - 1, k - 1) + C(n - 1, k); } lint P(lint n, lint k) { if (k == 1) { return n; } return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007); } int main() { lint n, k; cin >> n >> k; vector<lint> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<lint> c(n + 1, 0); for (int j = 0; j < n; j++) { c[max(0LL, j - a[j])]++; c[min(j + a[j] + 1, n)]--; } a[0] = c[0]; for (int j = 1; j < n; j++) { a[j] = c[j] + a[j - 1]; } int check = 1; for (int j = 0; j < n; j++) { if (a[j] != n) { check *= 0; } } if (check == 1) { break; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; return 0; }
insert
53
53
53
63
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define F first #define S second using namespace std; typedef pair<int, int> P; const int MOD = 1000000007; int INF = 100100100100100; int a[100010]; int imos[100010]; signed main() { int n, k; cin >> n >> k; rep(i, n) cin >> a[i]; rep(ima, k) { rep(i, n) { if (i - a[i] >= 0) imos[i - a[i]]++; else imos[0]++; if (i + a[i] <= n - 1) imos[i + a[i] + 1]--; else imos[n]--; } int cnt = 0; rep(i, n) { if (i == 0) a[0] = imos[0]; else a[i] = a[i - 1] + imos[i]; if (a[i] == n) cnt++; imos[i] = 0; } if (cnt == n) { break; } } rep(i, n) cout << a[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define F first #define S second using namespace std; typedef pair<int, int> P; const int MOD = 1000000007; int INF = 100100100100100; int a[200010]; int imos[200010]; signed main() { int n, k; cin >> n >> k; rep(i, n) cin >> a[i]; rep(ima, k) { rep(i, n) { if (i - a[i] >= 0) imos[i - a[i]]++; else imos[0]++; if (i + a[i] <= n - 1) imos[i + a[i] + 1]--; else imos[n]--; } int cnt = 0; rep(i, n) { if (i == 0) a[0] = imos[0]; else a[i] = a[i - 1] + imos[i]; if (a[i] == n) cnt++; imos[i] = 0; } if (cnt == n) { break; } } rep(i, n) cout << a[i] << " "; cout << endl; return 0; }
replace
13
15
13
15
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; vi sum(n + 1); rep(i, n) { sum[max(0, i - a[i])]++; sum[min(n, i + a[i] + 1)]--; } rep(h, k - 1) { vi sum2(n + 1); int val = sum[0]; sum2[0]++; sum2[min(n, val + 1)]--; bool full = (val == n); rep1(i, n - 1) { val += sum[i]; sum2[max(0, i - val)]++; sum2[min(n, i + val + 1)]--; if (i < n - 1 && val != 0) full = false; } swap(sum, sum2); if (full) break; } vi ans(n); ans[0] = sum[0]; rep1(i, n - 1) ans[i] = ans[i - 1] + sum[i]; rep(i, n) printf("%d%c", ans[i], (i < n - 1 ? ' ' : '\n')); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; vi sum(n + 1); rep(i, n) { sum[max(0, i - a[i])]++; sum[min(n, i + a[i] + 1)]--; } rep(h, k - 1) { vi sum2(n + 1); int val = sum[0]; sum2[0]++; sum2[min(n, val + 1)]--; bool full = (val == n); rep1(i, n - 1) { val += sum[i]; sum2[max(0, i - val)]++; sum2[min(n, i + val + 1)]--; if (i <= n - 1 && val != n) full = false; } swap(sum, sum2); if (full) break; } vi ans(n); ans[0] = sum[0]; rep1(i, n - 1) ans[i] = ans[i - 1] + sum[i]; rep(i, n) printf("%d%c", ans[i], (i < n - 1 ? ' ' : '\n')); return 0; }
replace
59
60
59
60
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T1, typename T2> bool chmin(T1 &a, T2 b) { if (a <= b) return 0; a = b; return 1; } template <typename T1, typename T2> bool chmax(T1 &a, T2 b) { if (a >= b) return 0; a = b; return 1; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; long double eps = 1e-9; long double pi = acos(-1); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } while (k--) { vector<int> sum(n); for (int i = 0; i < n; i++) { sum[max(0, i - a[i])]++; if (i + a[i] + 1 < n) sum[i + 1 + a[i]]--; } bool ok = 1; if (sum[0] != 0) ok = false; for (int i = 1; i < n; i++) { sum[i] += sum[i - 1]; if (sum[i] != n) ok = false; } swap(a, sum); if (ok) break; } for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T1, typename T2> bool chmin(T1 &a, T2 b) { if (a <= b) return 0; a = b; return 1; } template <typename T1, typename T2> bool chmax(T1 &a, T2 b) { if (a >= b) return 0; a = b; return 1; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; long double eps = 1e-9; long double pi = acos(-1); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } while (k--) { vector<int> sum(n); for (int i = 0; i < n; i++) { sum[max(0, i - a[i])]++; if (i + a[i] + 1 < n) sum[i + 1 + a[i]]--; } bool ok = 1; if (sum[0] != n) ok = false; for (int i = 1; i < n; i++) { sum[i] += sum[i - 1]; if (sum[i] != n) ok = false; } swap(a, sum); if (ok) break; } for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; }
replace
39
40
39
40
TLE
p02647
C++
Time Limit Exceeded
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N; cin >> K; vector<int> A(N); vector<int> flash; for (int i = 0; i < N; i++) { cin >> A.at(i); } rep(iterate, K) { flash = vector<int>(N, 0); rep(i, N) { int on = i - A[i]; int off = i + A[i] + 1; if (on < 0) { flash[0] += 1; } else { flash[on] += 1; } if (off < N) { flash[off] -= 1; } } A[0] = flash[0]; rep(i, N - 1) { A[i + 1] = A[i]; A[i + 1] += flash[i + 1]; } } for (int i = 0; i < N - 1; i++) { cout << A.at(i) << " "; } cout << A.at(A.size() - 1) << endl; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N; cin >> K; vector<int> A(N); vector<int> flash; for (int i = 0; i < N; i++) { cin >> A.at(i); } rep(iterate, K) { flash = vector<int>(N, 0); rep(i, N) { int on = i - A[i]; int off = i + A[i] + 1; if (on < 0) { flash[0] += 1; } else { flash[on] += 1; } if (off < N) { flash[off] -= 1; } } A[0] = flash[0]; rep(i, N - 1) { A[i + 1] = A[i]; A[i + 1] += flash[i + 1]; } if (accumulate(A.begin(), A.end(), 0) == N * N) { break; } } for (int i = 0; i < N - 1; i++) { cout << A.at(i) << " "; } cout << A.at(A.size() - 1) << endl; }
insert
32
32
32
35
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) #define PI 3.14159265358979 using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; // using Graph = vector<vector<Edge>>; using Graph = vector<vector<int>>; 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 N, K; cin >> N >> K; vector<ll> A(N); for (auto &it : A) { cin >> it; } vector<ll> ans = A; for (int k = 0; k < K; k++) { vector<ll> imos(N + 1, 0); for (int i = 0; i < N; i++) { ll l = max(0LL, i - ans[i]); ll r = min((ll)(N - 1), i + ans[i]); imos[l]++; imos[r + 1]--; } bool ok = true; int MAX = N; if (ans[0] != MAX) ok = false; ans[0] = imos[0]; for (int i = 1; i < N; i++) { imos[i] += imos[i - 1]; ans[i] = imos[i]; if (ans[i] == MAX) ok = false; } if (ok) { for (auto it : ans) cout << it << " "; cout << endl; return 0; } } for (auto it : ans) cout << it << " "; cout << endl; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) #define PI 3.14159265358979 using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; // using Graph = vector<vector<Edge>>; using Graph = vector<vector<int>>; 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 N, K; cin >> N >> K; vector<ll> A(N); for (auto &it : A) { cin >> it; } vector<ll> ans = A; for (int k = 0; k < K; k++) { vector<ll> imos(N + 1, 0); for (int i = 0; i < N; i++) { ll l = max(0LL, i - ans[i]); ll r = min((ll)(N - 1), i + ans[i]); imos[l]++; imos[r + 1]--; } bool ok = true; int MAX = N; if (ans[0] != MAX) ok = false; ans[0] = imos[0]; for (int i = 1; i < N; i++) { imos[i] += imos[i - 1]; ans[i] = imos[i]; if (ans[i] != MAX) ok = false; } if (ok) { for (auto it : ans) cout << it << " "; cout << endl; return 0; } } for (auto it : ans) cout << it << " "; cout << endl; return 0; }
replace
47
48
47
48
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> #define ll long long using namespace std; long long MOD = 1000000007; template <typename T> void cout_vec(vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { if (i != 0) { cout << ' '; } cout << vec[i]; } cout << endl; } int main() { int N, K; cin >> N >> K; vector<int> vec(N + 1); for (int i = 0; i < N; i++) { cin >> vec[i]; } for (int i = 0; i < K; i++) { vector<int> nw(N + 1, 0); for (int j = 0; j < N; j++) { nw[max(0, j - vec[j])]++; nw[min(N, j + vec[j] + 1)]--; } ll sum_ = 0; for (int k = 0; k < N; k++) { nw[k + 1] += nw[k]; sum_ += (ll)nw[k]; } vec.swap(nw); if (sum_ == (ll)N * K) { break; } // cout << vec[0] << endl; } vec.pop_back(); cout_vec(vec); }
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> #define ll long long using namespace std; long long MOD = 1000000007; template <typename T> void cout_vec(vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { if (i != 0) { cout << ' '; } cout << vec[i]; } cout << endl; } int main() { int N, K; cin >> N >> K; vector<int> vec(N + 1); for (int i = 0; i < N; i++) { cin >> vec[i]; } for (int i = 0; i < K; i++) { vector<int> nw(N + 1, 0); for (int j = 0; j < N; j++) { nw[max(0, j - vec[j])]++; nw[min(N, j + vec[j] + 1)]--; } ll sum_ = 0; for (int k = 0; k < N; k++) { nw[k + 1] += nw[k]; sum_ += (ll)nw[k]; } vec.swap(nw); if (sum_ == (ll)N * N) { // cout << i << endl; break; } // cout << vec[0] << endl; } vec.pop_back(); cout_vec(vec); }
replace
48
49
48
50
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, n) for (int i = s; i < (int)(n); i++) int main() { int n, k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, k) { vector<ll> imos(n, 0); rep(j, 0, n) { if (j - a[j] >= 0) imos[j - a[j]]++; else imos[0]++; if (j + a[j] + 1 < n) imos[j + a[j] + 1]--; } a[0] = imos[0]; rep(j, 1, n) a[j] = a[j - 1] + imos[j]; } rep(i, 0, n) { cout << a[i]; if (i != n - 1) cout << " "; else cout << "" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, n) for (int i = s; i < (int)(n); i++) int main() { int n, k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, k) { vector<ll> imos(n, 0); rep(j, 0, n) { if (j - a[j] >= 0) imos[j - a[j]]++; else imos[0]++; if (j + a[j] + 1 < n) imos[j + a[j] + 1]--; } a[0] = imos[0]; int c = 0; if (a[0] == n) c++; rep(j, 1, n) { a[j] = a[j - 1] + imos[j]; if (a[j] == n) c++; } if (c == n) break; } rep(i, 0, n) { cout << a[i]; if (i != n - 1) cout << " "; else cout << "" << endl; } }
replace
21
22
21
31
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; const long long INF = 1LL << 60; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) { cin >> A[i]; } vector<int> minimum(N), maximum(N); vector<int> ans(N + 5); rep(i, K) { rep(i, N) { minimum[i] = i - A[i]; if (minimum[i] < 0) minimum[i] = 0; maximum[i] = i + A[i]; if (maximum[i] > N - 1) maximum[i] = N - 1; } for (int i = 0; i < N; i++) { ans[minimum[i]]++; ans[maximum[i] + 1]--; } for (int i = 0; i < N; i++) { if (i > 0) ans[i] += ans[i - 1]; } rep(i, N) { A[i] = ans[i]; ans[i] = 0; } if (ans[0] == N && ans[N - 1] == N) { break; } } rep(i, N) { if (i != N - 1) cout << A[i] << " "; else cout << A[i] << endl; } return 0; }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; const long long INF = 1LL << 60; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) { cin >> A[i]; } vector<int> minimum(N), maximum(N); vector<int> ans(N + 5); rep(i, K) { rep(i, N) { minimum[i] = i - A[i]; if (minimum[i] < 0) minimum[i] = 0; maximum[i] = i + A[i]; if (maximum[i] > N - 1) maximum[i] = N - 1; } for (int i = 0; i < N; i++) { ans[minimum[i]]++; ans[maximum[i] + 1]--; } for (int i = 0; i < N; i++) { if (i > 0) ans[i] += ans[i - 1]; } rep(i, N) { A[i] = ans[i]; ans[i] = 0; } if (A[0] == N && A[N - 1] == N) { break; } } rep(i, N) { if (i != N - 1) cout << A[i] << " "; else cout << A[i] << endl; } return 0; }
replace
43
44
43
44
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k, pos; cin >> n >> k; lvector A(n); rep(i, n) cin >> A[i]; ll lim = min(50ll, k); lvector B(n, 0); rep(i, n) { pos = max(0ll, i - A[i]); B[pos]++; if (i + A[i] + 1 < n) B[i + A[i] + 1]--; } rep(i, n - 1) B[i + 1] += B[i]; rep(i, lim - 1) { lvector tmp(n, 0); rep(j, n) { pos = max(0ll, j - B[j]); tmp[pos]++; if (i + B[j] + 1 < n) tmp[j + B[j] + 1]--; } rep(j, n - 1) tmp[j + 1] += tmp[j]; rep(j, n) B[j] = tmp[j]; } rep(i, n - 1) cout << B[i] << ' '; print(B[n - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k, pos; cin >> n >> k; lvector A(n); rep(i, n) cin >> A[i]; ll lim = min(50ll, k); lvector B(n, 0); rep(i, n) { pos = max(0ll, i - A[i]); B[pos]++; if (i + A[i] + 1 < n) B[i + A[i] + 1]--; } rep(i, n - 1) B[i + 1] += B[i]; rep(i, lim - 1) { lvector tmp(n, 0); rep(j, n) { pos = max(0ll, j - B[j]); tmp[pos]++; if (j + B[j] + 1 < n) tmp[j + B[j] + 1]--; } rep(j, n - 1) tmp[j + 1] += tmp[j]; rep(j, n) B[j] = tmp[j]; } rep(i, n - 1) cout << B[i] << ' '; print(B[n - 1]); return 0; }
replace
36
37
36
37
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // typedef // ----------------------------------------------------------------------------- typedef long long ll; typedef long double ld; // container util // ----------------------------------------------------------------------------- #define ALL(c) (c).begin(), (c).end() #define SZ(c) ((ll)(c).size()) #define MAX(c) *max_element(ALL(c)) #define MIN(c) *min_element(ALL(c)) #define SORT(c) sort((c).begin(), (c).end()) // repetition // ----------------------------------------------------------------------------- #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant // ----------------------------------------------------------------------------- const int INF = 1e9; const int MOD = 1e9 + 7; const double EPS = 1e-9; const double PI = acos(-1.0); // debug // ----------------------------------------------------------------------------- #define DUMP(x) cerr << #x << " = " << (x) << endl int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, K; cin >> N >> K; vector<int> A(N + 1, 0); FOR(i, 1, N + 1) cin >> A[i]; REP(i, K) { vector<int> tmp(N + 1, 0); FOR(i, 1, N + 1) { int d = A[i]; int b = (i - d < 0) ? 0 : i - d; tmp[b]++; if (i + d + 1 <= N) { int e = i + d + 1; tmp[e]--; } } A[0] = tmp[0]; FOR(i, 1, N + 1) { A[i] = A[i - 1] + tmp[i]; } } FOR(i, 1, N + 1) { cout << A[i] << " "; } cout << "\n"; }
#include <bits/stdc++.h> using namespace std; // typedef // ----------------------------------------------------------------------------- typedef long long ll; typedef long double ld; // container util // ----------------------------------------------------------------------------- #define ALL(c) (c).begin(), (c).end() #define SZ(c) ((ll)(c).size()) #define MAX(c) *max_element(ALL(c)) #define MIN(c) *min_element(ALL(c)) #define SORT(c) sort((c).begin(), (c).end()) // repetition // ----------------------------------------------------------------------------- #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant // ----------------------------------------------------------------------------- const int INF = 1e9; const int MOD = 1e9 + 7; const double EPS = 1e-9; const double PI = acos(-1.0); // debug // ----------------------------------------------------------------------------- #define DUMP(x) cerr << #x << " = " << (x) << endl int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, K; cin >> N >> K; K = min(K, 100); vector<int> A(N + 1, 0); FOR(i, 1, N + 1) cin >> A[i]; REP(i, K) { vector<int> tmp(N + 1, 0); FOR(i, 1, N + 1) { int d = A[i]; int b = (i - d < 0) ? 0 : i - d; tmp[b]++; if (i + d + 1 <= N) { int e = i + d + 1; tmp[e]--; } } A[0] = tmp[0]; FOR(i, 1, N + 1) { A[i] = A[i - 1] + tmp[i]; } } FOR(i, 1, N + 1) { cout << A[i] << " "; } cout << "\n"; }
insert
38
38
38
39
TLE
p02647
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; auto upd = [](const vector<int> &v) { vector<int> imos((int)v.size() + 2); for (int i = 1; i <= (int)v.size(); i++) { int l = max(0, i - v[i - 1]); int r = min((int)v.size() + 2, i + v[i - 1] + 1); imos[l]++; imos[r]--; } for (int i = 1; i < (int)imos.size(); i++) { imos[i] += imos[i - 1]; } vector<int> res((int)v.size()); for (int i = 1; i <= (int)v.size(); i++) { res[i - 1] = imos[i]; } return res; }; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < min(50, k); i++) { a = upd(a); } for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << a[i]; } cout << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; auto upd = [](const vector<int> &v) { vector<int> imos((int)v.size() + 2); for (int i = 1; i <= (int)v.size(); i++) { int l = max(0, i - v[i - 1]); int r = min((int)v.size() + 1, i + v[i - 1] + 1); imos[l]++; imos[r]--; } for (int i = 1; i < (int)imos.size(); i++) { imos[i] += imos[i - 1]; } vector<int> res((int)v.size()); for (int i = 1; i <= (int)v.size(); i++) { res[i - 1] = imos[i]; } return res; }; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < min(50, k); i++) { a = upd(a); } for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << a[i]; } cout << endl; return 0; }
replace
12
13
12
13
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <memory.h> using namespace std; typedef long long ll; ll bulb[300010]; ll bkt[300010]; ll operate(int n) { memset(bkt, 0, sizeof bkt); for (int i = 0; i < n; ++i) { ll op1 = i - bulb[i]; ll op2 = i + bulb[i]; if (op1 < 0) op1 = 0; ++bkt[op1]; if (op2 >= n) op2 = n - 1; --bkt[op2 + 1]; } bulb[0] = bkt[0]; for (int i = 1; i < n; ++i) bulb[i] = bulb[i - 1] + bkt[i]; return *min_element(bulb, bulb + n); } int main() { int n, k, i; scanf("%d%d", &n, &k); for (i = 0; i < n; ++i) scanf("%lld", bulb + i); for (i = 0; i < k; ++i) if (operate(n) > n) break; for (int i = 0; i < n; ++i) printf("%lld%c", bulb[i], " \n"[i == n - 1]); return 0; }
#include <algorithm> #include <cstdio> #include <memory.h> using namespace std; typedef long long ll; ll bulb[300010]; ll bkt[300010]; ll operate(int n) { memset(bkt, 0, sizeof bkt); for (int i = 0; i < n; ++i) { ll op1 = i - bulb[i]; ll op2 = i + bulb[i]; if (op1 < 0) op1 = 0; ++bkt[op1]; if (op2 >= n) op2 = n - 1; --bkt[op2 + 1]; } bulb[0] = bkt[0]; for (int i = 1; i < n; ++i) bulb[i] = bulb[i - 1] + bkt[i]; return *min_element(bulb, bulb + n); } int main() { int n, k, i; scanf("%d%d", &n, &k); for (i = 0; i < n; ++i) scanf("%lld", bulb + i); for (i = 0; i < k; ++i) if (operate(n) >= n) break; for (int i = 0; i < n; ++i) printf("%lld%c", bulb[i], " \n"[i == n - 1]); return 0; }
replace
33
34
33
34
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define ls p << 1 #define rs p << 1 | 1 #define rgi register int #define ll long long #define pii pair<int, int> #define mkp make_pair #define fi first #define se second #define pb push_back using namespace std; const int maxn = 100005; int n, m, a[maxn], b[maxn]; struct sgt { int p, l, r; ll val, add; } t[maxn << 2]; void build(int p, int l, int r) { t[p].l = l, t[p].r = r; if (l == r) { t[p].val = a[l]; return; } int mid = (l + r) >> 1; build(ls, l, mid); build(rs, mid + 1, r); t[p].val = t[ls].val + t[rs].val; } inline void spread(int p) { if (t[p].add) { t[ls].val += t[p].add * (t[ls].r - t[ls].l + 1); t[rs].val += t[p].add * (t[rs].r - t[rs].l + 1); t[ls].add += t[p].add; t[rs].add += t[p].add; t[p].add = 0; } } void change(int p, int l, int r, ll x) { if (l <= t[p].l && t[p].r <= r) { t[p].add += x; t[p].val += x * (t[p].r - t[p].l + 1); return; } spread(p); int mid = (t[p].l + t[p].r) >> 1; if (mid >= l) change(ls, l, r, x); if (mid < r) change(rs, l, r, x); t[p].val = t[ls].val + t[rs].val; } ll sum(int p, int l, int r) { if (l <= t[p].l && t[p].r <= r) return t[p].val; spread(p); int mid = (t[p].l + t[p].r) >> 1; ll ret = 0; if (mid >= l) ret += sum(ls, l, r); if (mid < r) ret += sum(rs, l, r); return ret; } bool check() { for (int i = 1; i <= n; ++i) if (b[i] != n) return 0; return 1; } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; build(1, 1, n); memset(a, 0, sizeof(a)); for (int i = 1; i <= m; ++i) { for (int i = 1; i <= n; ++i) b[i] = sum(1, i, i); if (check()) break; build(1, 1, n); for (int i = 1; i <= n; ++i) { int l = max(i - b[i], 1), r = min(i + b[i], n); change(1, l, r, 1); } } for (int i = 1; i <= n; ++i) cout << sum(1, i, i) << " "; cout << endl; return 0; }
#include <bits/stdc++.h> #define ls p << 1 #define rs p << 1 | 1 #define rgi register int #define ll long long #define pii pair<int, int> #define mkp make_pair #define fi first #define se second #define pb push_back using namespace std; const int maxn = 200005; int n, m, a[maxn], b[maxn]; struct sgt { int p, l, r; ll val, add; } t[maxn << 2]; void build(int p, int l, int r) { t[p].l = l, t[p].r = r; if (l == r) { t[p].val = a[l]; return; } int mid = (l + r) >> 1; build(ls, l, mid); build(rs, mid + 1, r); t[p].val = t[ls].val + t[rs].val; } inline void spread(int p) { if (t[p].add) { t[ls].val += t[p].add * (t[ls].r - t[ls].l + 1); t[rs].val += t[p].add * (t[rs].r - t[rs].l + 1); t[ls].add += t[p].add; t[rs].add += t[p].add; t[p].add = 0; } } void change(int p, int l, int r, ll x) { if (l <= t[p].l && t[p].r <= r) { t[p].add += x; t[p].val += x * (t[p].r - t[p].l + 1); return; } spread(p); int mid = (t[p].l + t[p].r) >> 1; if (mid >= l) change(ls, l, r, x); if (mid < r) change(rs, l, r, x); t[p].val = t[ls].val + t[rs].val; } ll sum(int p, int l, int r) { if (l <= t[p].l && t[p].r <= r) return t[p].val; spread(p); int mid = (t[p].l + t[p].r) >> 1; ll ret = 0; if (mid >= l) ret += sum(ls, l, r); if (mid < r) ret += sum(rs, l, r); return ret; } bool check() { for (int i = 1; i <= n; ++i) if (b[i] != n) return 0; return 1; } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; build(1, 1, n); memset(a, 0, sizeof(a)); for (int i = 1; i <= m; ++i) { for (int i = 1; i <= n; ++i) b[i] = sum(1, i, i); if (check()) break; build(1, 1, n); for (int i = 1; i <= n; ++i) { int l = max(i - b[i], 1), r = min(i + b[i], n); change(1, l, r, 1); } } for (int i = 1; i <= n; ++i) cout << sum(1, i, i) << " "; cout << endl; return 0; }
replace
11
12
11
12
0
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repA(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(a) (ll)(a.size()) typedef long long ll; typedef long double ld; const ll mod = 998244353; // 1e9+7 int solve() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; while (k--) { vector<int> b(n + 1, 0); rep(i, n) { int from = max(0, i - a[i]); int to = min(n - 1, i + a[i]); b[from]++; b[to + 1]--; } bool changed = false; rep(i, n) { changed |= (a[i] != b[i]); a[i] = b[i]; b[i + 1] += b[i]; } if (!changed) break; } rep(i, n) cout << a[i] << ' '; cout << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif ll t = 1; // cin>>t; rep(i, t) { solve(); // cout<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repA(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(a) (ll)(a.size()) typedef long long ll; typedef long double ld; const ll mod = 998244353; // 1e9+7 void solve() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; while (k--) { vector<int> b(n + 1, 0); rep(i, n) { int from = max(0, i - a[i]); int to = min(n - 1, i + a[i]); b[from]++; b[to + 1]--; } bool changed = false; rep(i, n) { changed |= (a[i] != b[i]); a[i] = b[i]; b[i + 1] += b[i]; } if (!changed) break; } rep(i, n) cout << a[i] << ' '; cout << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif ll t = 1; // cin>>t; rep(i, t) { solve(); // cout<<'\n'; } return 0; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vi = vector<int>; #define _GLIBCXX_DEBUG #define IO_STREAM \ cin.tie(0); \ ios::sync_with_stdio(false) #define all(x) x.begin(), x.end() #define rep(i, sta, end) for (ll i = sta; i < end; ++i) #define lcm(a, b) (a) / __gcd((a), (b)) * (b) #define pb push_back #define INF 1000000000000000LL const ll MOD = 1000000007; const double PI = acos(-1); //|| #define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl // DBG("","","",""); signed main() { IO_STREAM; int N, K; cin >> N >> K; vi A(N); rep(i, 0, N) { cin >> A[i]; } rep(cnt, 0, K) { vi B(N + 1); rep(i, 0, N) { int st, ed; st = max((int)(i - A[i]), 0); ed = min((int)(i + A[i] + 1), N); B[st]++; B[ed]--; } rep(i, 0, N) { B[i + 1] += B[i]; } // if(A==B) break; A = B; B[N] = 0; } rep(i, 0, N) { cout << A[i] << ' '; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vi = vector<int>; #define _GLIBCXX_DEBUG #define IO_STREAM \ cin.tie(0); \ ios::sync_with_stdio(false) #define all(x) x.begin(), x.end() #define rep(i, sta, end) for (ll i = sta; i < end; ++i) #define lcm(a, b) (a) / __gcd((a), (b)) * (b) #define pb push_back #define INF 1000000000000000LL const ll MOD = 1000000007; const double PI = acos(-1); //|| #define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl // DBG("","","",""); signed main() { IO_STREAM; int N, K; cin >> N >> K; vi A(N); rep(i, 0, N) { cin >> A[i]; } rep(cnt, 0, K) { vi B(N + 1); rep(i, 0, N) { int st, ed; st = max((int)(i - A[i]), 0); ed = min((int)(i + A[i] + 1), N); B[st]++; B[ed]--; } rep(i, 0, N) { B[i + 1] += B[i]; } if (A == B) break; A = B; B[N] = 0; } rep(i, 0, N) { cout << A[i] << ' '; } return 0; }
replace
36
37
36
38
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int, int> P; int n, k; int a[200005]; int sum[200005]; int main(void) { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (int i = 0; i < k; i++) { memset(sum, 0, sizeof(sum)); bool flag = true; for (int j = 0; j < n; j++) { if (a[j] != n) { flag = false; } } for (int j = 0; j < n; j++) { sum[max(0, j - a[j])]++; sum[min(n, j + a[j] + 1)]--; } for (int j = 0; j < n; j++) { sum[j + 1] += sum[j]; a[j] = sum[j]; } } for (int i = 0; i < n; i++) { printf("%d%c", a[i], i + 1 == n ? '\n' : ' '); } return 0; }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int, int> P; int n, k; int a[200005]; int sum[200005]; int main(void) { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (int i = 0; i < k; i++) { memset(sum, 0, sizeof(sum)); bool flag = true; for (int j = 0; j < n; j++) { if (a[j] != n) { flag = false; } } if (flag) break; for (int j = 0; j < n; j++) { sum[max(0, j - a[j])]++; sum[min(n, j + a[j] + 1)]--; } for (int j = 0; j < n; j++) { sum[j + 1] += sum[j]; a[j] = sum[j]; } } for (int i = 0; i < n; i++) { printf("%d%c", a[i], i + 1 == n ? '\n' : ' '); } return 0; }
insert
23
23
23
25
TLE
p02647
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> #include <ctime> #include <iostream> #define re register const int MAXN = 2e5 + 10; int n, K, s[MAXN], a[MAXN], timee; char fin[10010], *p1 = fin, *p2 = fin; char getc() { return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2) ? EOF : *p1++; } int read() { re int x = 0; re char ch = 0; while (ch < '0' || ch > '9') ch = getc(); while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc(); return x; } inline void insert(int x, int w) { for (; x <= n; x += x & -x) s[x] += w; } inline int query(int x) { re int res = 0; for (; x; x -= x & -x) res += s[x]; return res; } int main() { freopen("t2.in", "r", stdin); // freopen("t2.out","w",stdout); n = read(); K = read(); for (re int i = 1; i <= n; i++) a[i] = read(); while (K--) { re bool flag = 1; memset(s, 0, (n + 5) * sizeof(int)); for (re int i = 1; i <= n; i++) insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1); for (re int i = 1; i <= n; i++) a[i] = query(i), flag &= (a[i] == n); if (flag) break; } for (re int i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n"); return 0; } /* 5 1 1 0 0 1 0 */
#include <cstdio> #include <cstring> #include <ctime> #include <iostream> #define re register const int MAXN = 2e5 + 10; int n, K, s[MAXN], a[MAXN], timee; char fin[10010], *p1 = fin, *p2 = fin; char getc() { return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2) ? EOF : *p1++; } int read() { re int x = 0; re char ch = 0; while (ch < '0' || ch > '9') ch = getc(); while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc(); return x; } inline void insert(int x, int w) { for (; x <= n; x += x & -x) s[x] += w; } inline int query(int x) { re int res = 0; for (; x; x -= x & -x) res += s[x]; return res; } int main() { // freopen("t2.out","w",stdout); n = read(); K = read(); for (re int i = 1; i <= n; i++) a[i] = read(); while (K--) { re bool flag = 1; memset(s, 0, (n + 5) * sizeof(int)); for (re int i = 1; i <= n; i++) insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1); for (re int i = 1; i <= n; i++) a[i] = query(i), flag &= (a[i] == n); if (flag) break; } for (re int i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n"); return 0; } /* 5 1 1 0 0 1 0 */
delete
33
34
33
33
TLE
p02647
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> #include <ctime> #include <iostream> #define re register const int MAXN = 2e5 + 10; int n, K, s[MAXN], a[MAXN], timee; char fin[10010], *p1 = fin, *p2 = fin; char getc() { return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2) ? EOF : *p1++; } int read() { re int x = 0; re char ch = 0; while (ch < '0' || ch > '9') ch = getc(); while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc(); return x; } inline void insert(int x, int w) { for (; x <= n; x += x & -x) s[x] += w; } inline int query(int x) { re int res = 0; for (; x; x -= x & -x) res += s[x]; return res; } int main() { freopen("t2.in", "r", stdin); // freopen("t2.out","w",stdout); n = read(); K = read(); for (re int i = 1; i <= n; i++) a[i] = read(); if (K >= 41) { for (re int i = 1; i <= n; i++) printf("%d ", n); return 0; } while (K--) { re bool flag = 1; memset(s, 0, (n + 5) * sizeof(int)); for (re int i = 1; i <= n; i++) insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1); for (re int i = 1; i <= n; i++) a[i] = query(i), flag &= (a[i] == n); if (flag) break; } for (re int i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n"); return 0; } /* 5 1 1 0 0 1 0 */
#include <cstdio> #include <cstring> #include <ctime> #include <iostream> #define re register const int MAXN = 2e5 + 10; int n, K, s[MAXN], a[MAXN], timee; char fin[10010], *p1 = fin, *p2 = fin; char getc() { return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2) ? EOF : *p1++; } int read() { re int x = 0; re char ch = 0; while (ch < '0' || ch > '9') ch = getc(); while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc(); return x; } inline void insert(int x, int w) { for (; x <= n; x += x & -x) s[x] += w; } inline int query(int x) { re int res = 0; for (; x; x -= x & -x) res += s[x]; return res; } int main() { // freopen("t2.out","w",stdout); n = read(); K = read(); for (re int i = 1; i <= n; i++) a[i] = read(); if (K >= 41) { for (re int i = 1; i <= n; i++) printf("%d ", n); return 0; } while (K--) { re bool flag = 1; memset(s, 0, (n + 5) * sizeof(int)); for (re int i = 1; i <= n; i++) insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1); for (re int i = 1; i <= n; i++) a[i] = query(i), flag &= (a[i] == n); if (flag) break; } for (re int i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n"); return 0; } /* 5 1 1 0 0 1 0 */
delete
33
34
33
33
TLE
p02647
C++
Runtime Error
// #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> /* #include <boost/multiprecision/cpp_dec_float.hpp> #include<boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> namespace mp = boost::multiprecision; using Real = mp::number<mp::cpp_dec_float<1024>>; using Bint = mp::cpp_int; */ using namespace std; #define int long long #define REP(i, s, e) for ((i) = (s); (i) < (e); (i)++) #define RREP(i, s, e) for ((i) = ((s)-1); (i) >= (e); (i)--) #define FOR(i, n) for ((i) = (0); (i) < (n); (i)++) #define RFOR(i, n) for ((i) = ((n)-1); (i) >= (0); (i)--) #define MOD 1000000007 #define NMAX 100000 int N, K, A[NMAX]; int g[NMAX], a[NMAX]; void inpmake() { N = NMAX; K = NMAX; for (int i = 0; i < N; i++) { A[i] = 0; } A[N - 3] = 1; } void inp() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } } void gutyoku() { for (int i = 0; i < N; i++) { g[i] = A[i]; } for (int i = 0; i < K; i++) { int n[NMAX] = {0}; for (int j = 0; j < N; j++) { for (int k = -g[j]; k <= g[j]; k++) { if (j + k >= 0 && j + k < N) { n[j + k]++; } } } for (int j = 0; j < N; j++) { g[j] = n[j]; cout << n[j] << " "; } cout << endl; } } void ans() { for (int i = 0; i < N; i++) { a[i] = A[i]; } for (int i = 0; i < K; i++) { int n[NMAX] = {0}; int sp = 0; for (int j = 0; j < N; j++) { if (j - a[j] < 0) sp++; else n[j - a[j]]++; if (j + a[j] + 1 < N) n[j + a[j] + 1]--; } for (int j = 0; j < N; j++) { sp += n[j]; n[j] = sp; } bool zf = true; bool mf = true; for (int j = 0; j < N; j++) { a[j] = n[j]; // cout<<n[j]<<" "; if (a[j] != 0) zf = false; if (a[j] != N) mf = false; } // cout<<endl; if (zf || mf) break; // cout<<i<<endl; } for (int j = 0; j < N; j++) { cout << a[j] << " "; } cout << endl; } signed main() { inp(); ans(); } /* 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3 3 2 4 5 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 7 7 7 6 6 5 4 8 9 10 11 12 12 13 13 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 15 15 15 15 14 14 14 13 13 12 12 11 10 9 8 16 17 18 19 20 21 22 23 24 24 25 25 26 26 27 27 28 28 28 29 29 29 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 32 31 31 31 31 31 30 30 30 30 29 29 29 28 28 28 27 27 26 26 25 25 24 24 23 22 21 20 19 18 17 16 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 48 49 49 50 50 51 51 52 52 53 53 54 54 55 55 56 56 56 57 58 57 58 58 58 59 59 58 59 59 59 59 59 59 59 59 59 59 59 59 58 59 59 58 58 58 57 57 57 56 56 56 55 55 54 54 53 53 52 52 51 51 50 50 49 49 48 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 59 60 61 62 62 63 64 65 65 66 67 68 68 69 70 70 71 72 72 73 74 74 75 76 76 77 78 78 79 80 80 81 82 81 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 81 82 81 80 80 79 78 78 77 76 76 75 74 74 73 72 72 71 70 70 69 68 68 67 66 65 65 64 64 62 62 61 60 59 77 77 78 78 79 80 80 81 81 82 83 83 84 84 85 86 86 87 87 88 89 89 90 90 91 91 92 93 93 94 95 95 95 96 97 97 98 98 99 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 98 98 97 97 96 95 95 94 94 93 93 92 91 91 90 90 89 89 88 87 87 86 86 85 84 84 83 83 82 81 81 80 80 79 78 78 77 77 86 86 87 88 88 89 90 90 91 91 92 93 93 94 95 95 96 96 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 96 96 95 95 94 93 93 92 91 91 90 90 89 88 88 87 86 86 92 92 93 94 94 95 95 96 97 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 97 96 95 95 94 94 93 92 92 95 96 97 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 97 96 95 98 98 99 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 */
// #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> /* #include <boost/multiprecision/cpp_dec_float.hpp> #include<boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> namespace mp = boost::multiprecision; using Real = mp::number<mp::cpp_dec_float<1024>>; using Bint = mp::cpp_int; */ using namespace std; #define int long long #define REP(i, s, e) for ((i) = (s); (i) < (e); (i)++) #define RREP(i, s, e) for ((i) = ((s)-1); (i) >= (e); (i)--) #define FOR(i, n) for ((i) = (0); (i) < (n); (i)++) #define RFOR(i, n) for ((i) = ((n)-1); (i) >= (0); (i)--) #define MOD 1000000007 #define NMAX 200010 int N, K, A[NMAX]; int g[NMAX], a[NMAX]; void inpmake() { N = NMAX; K = NMAX; for (int i = 0; i < N; i++) { A[i] = 0; } A[N - 3] = 1; } void inp() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } } void gutyoku() { for (int i = 0; i < N; i++) { g[i] = A[i]; } for (int i = 0; i < K; i++) { int n[NMAX] = {0}; for (int j = 0; j < N; j++) { for (int k = -g[j]; k <= g[j]; k++) { if (j + k >= 0 && j + k < N) { n[j + k]++; } } } for (int j = 0; j < N; j++) { g[j] = n[j]; cout << n[j] << " "; } cout << endl; } } void ans() { for (int i = 0; i < N; i++) { a[i] = A[i]; } for (int i = 0; i < K; i++) { int n[NMAX] = {0}; int sp = 0; for (int j = 0; j < N; j++) { if (j - a[j] < 0) sp++; else n[j - a[j]]++; if (j + a[j] + 1 < N) n[j + a[j] + 1]--; } for (int j = 0; j < N; j++) { sp += n[j]; n[j] = sp; } bool zf = true; bool mf = true; for (int j = 0; j < N; j++) { a[j] = n[j]; // cout<<n[j]<<" "; if (a[j] != 0) zf = false; if (a[j] != N) mf = false; } // cout<<endl; if (zf || mf) break; // cout<<i<<endl; } for (int j = 0; j < N; j++) { cout << a[j] << " "; } cout << endl; } signed main() { inp(); ans(); } /* 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3 3 2 4 5 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 7 7 7 6 6 5 4 8 9 10 11 12 12 13 13 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 15 15 15 15 14 14 14 13 13 12 12 11 10 9 8 16 17 18 19 20 21 22 23 24 24 25 25 26 26 27 27 28 28 28 29 29 29 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 32 31 31 31 31 31 30 30 30 30 29 29 29 28 28 28 27 27 26 26 25 25 24 24 23 22 21 20 19 18 17 16 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 48 49 49 50 50 51 51 52 52 53 53 54 54 55 55 56 56 56 57 58 57 58 58 58 59 59 58 59 59 59 59 59 59 59 59 59 59 59 59 58 59 59 58 58 58 57 57 57 56 56 56 55 55 54 54 53 53 52 52 51 51 50 50 49 49 48 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 59 60 61 62 62 63 64 65 65 66 67 68 68 69 70 70 71 72 72 73 74 74 75 76 76 77 78 78 79 80 80 81 82 81 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 81 82 81 80 80 79 78 78 77 76 76 75 74 74 73 72 72 71 70 70 69 68 68 67 66 65 65 64 64 62 62 61 60 59 77 77 78 78 79 80 80 81 81 82 83 83 84 84 85 86 86 87 87 88 89 89 90 90 91 91 92 93 93 94 95 95 95 96 97 97 98 98 99 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 98 98 97 97 96 95 95 94 94 93 93 92 91 91 90 90 89 89 88 87 87 86 86 85 84 84 83 83 82 81 81 80 80 79 78 78 77 77 86 86 87 88 88 89 90 90 91 91 92 93 93 94 95 95 96 96 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 96 96 95 95 94 93 93 92 91 91 90 90 89 88 88 87 86 86 92 92 93 94 94 95 95 96 97 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 97 96 95 95 94 94 93 92 92 95 96 97 97 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98 98 97 97 96 95 98 98 99 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 98 98 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 */
replace
24
25
24
25
0
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, start, end) for (int i = start; i <= end; i++) const int INF = 1001001001; typedef long long ll; const ll MOD = 1000000007; using namespace std; 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; } template <class T> auto MAX(const T &a) { return *max_element(a.begin(), a.end()); } template <class T> auto MIN(const T &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> U SUM(const T &a, const U &v) { return accumulate(a.begin(), a.end(), v); } template <class T, class U> U COUNT(const T &a, const U &v) { return count(a.begin(), a.end(), v); } template <class T, class U> int LOWER(const T &a, const U &v) { return lower_bound(a.begin(), a.end(), v) - a.begin(); } template <class T, class U> int UPPER(const T &a, const U &v) { return upper_bound(a.begin(), a.end(), v) - a.begin(); } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; } int main(void) { // Your code here! int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> b(n, 0); rep(j, n) { int l = max(0, j - a[j]); int r = min(j + a[j], n - 1); b[l]++; if (r + 1 < n) b[r + 1]--; } rep(j, n) b[j + 1] += b[j]; if (a == b) break; a = b; } rep(i, n) cout << a[i] << " "; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, start, end) for (int i = start; i <= end; i++) const int INF = 1001001001; typedef long long ll; const ll MOD = 1000000007; using namespace std; 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; } template <class T> auto MAX(const T &a) { return *max_element(a.begin(), a.end()); } template <class T> auto MIN(const T &a) { return *min_element(a.begin(), a.end()); } template <class T, class U> U SUM(const T &a, const U &v) { return accumulate(a.begin(), a.end(), v); } template <class T, class U> U COUNT(const T &a, const U &v) { return count(a.begin(), a.end(), v); } template <class T, class U> int LOWER(const T &a, const U &v) { return lower_bound(a.begin(), a.end(), v) - a.begin(); } template <class T, class U> int UPPER(const T &a, const U &v) { return upper_bound(a.begin(), a.end(), v) - a.begin(); } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; } int main(void) { // Your code here! int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> b(n, 0); rep(j, n) { int l = max(0, j - a[j]); int r = min(j + a[j], n - 1); b[l]++; if (r + 1 < n) b[r + 1]--; } rep(j, n - 1) b[j + 1] += b[j]; if (a == b) break; a = b; } rep(i, n) cout << a[i] << " "; }
replace
61
62
61
62
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <string> typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define F first #define S second #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define len(s) s.length() #define all(v) v.begin(), v.end() const ll INF = LONG_MAX; const int N = 2e5 + 5; const ll mod = 1000000007; using namespace std; int a[N], b[N]; int n; void solve() { int i; for (i = 0; i <= n; i++) b[i] = 0; for (i = 0; i < n; i++) { int l = max(i - a[i], 0); int r = min(i + a[i] + 1, n); b[l]++; b[r]--; } for (i = 1; i <= n; i++) b[i] += b[i - 1]; for (i = 0; i < n; i++) { a[i] = b[i]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); ll tc = 1; // cin >> tc; while (tc--) { int m, k, i, j; int x, y; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; int ok = 0; // for (i = 0; i < n; i++) { // // printf("%d ", a[i]); // cout << a[i] << " "; // } // cout << endl; while (k--) { for (i = 0; i < n; i++) { ok &= (a[i] == n); } if (ok) break; solve(); } for (i = 0; i < n; i++) { printf("%d ", a[i]); } } }
#include <bits/stdc++.h> #include <string> typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define F first #define S second #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define len(s) s.length() #define all(v) v.begin(), v.end() const ll INF = LONG_MAX; const int N = 2e5 + 5; const ll mod = 1000000007; using namespace std; int a[N], b[N]; int n; void solve() { int i; for (i = 0; i <= n; i++) b[i] = 0; for (i = 0; i < n; i++) { int l = max(i - a[i], 0); int r = min(i + a[i] + 1, n); b[l]++; b[r]--; } for (i = 1; i <= n; i++) b[i] += b[i - 1]; for (i = 0; i < n; i++) { a[i] = b[i]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); ll tc = 1; // cin >> tc; while (tc--) { int m, k, i, j; int x, y; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; int ok = 0; // for (i = 0; i < n; i++) { // // printf("%d ", a[i]); // cout << a[i] << " "; // } // cout << endl; while (k--) { ok = 1; for (i = 0; i < n; i++) { ok &= (a[i] == n); } if (ok) break; solve(); } for (i = 0; i < n; i++) { printf("%d ", a[i]); } } }
insert
67
67
67
68
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &&e : a) { cin >> e; } for (int i = 0; i < k; ++i) { vector<int> tmp(n, 0); for (int j = 0; j < n; ++j) { int l = max(0, j - a[j]); int r = j + a[j] + 1; tmp[l] += 1; if (n > r) tmp[r] -= 1; } for (int i = 0; i < n - 1; ++i) { a[i] = tmp[i]; tmp[i + 1] += tmp[i]; } a[n - 1] = tmp[n - 1]; } for (auto &&e : a) { cout << e << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &&e : a) { cin >> e; } for (int i = 0; i < min(k, 100); ++i) { vector<int> tmp(n, 0); for (int j = 0; j < n; ++j) { int l = max(0, j - a[j]); int r = j + a[j] + 1; tmp[l] += 1; if (n > r) tmp[r] -= 1; } for (int i = 0; i < n - 1; ++i) { a[i] = tmp[i]; tmp[i + 1] += tmp[i]; } a[n - 1] = tmp[n - 1]; } for (auto &&e : a) { cout << e << " "; } cout << endl; }
replace
13
14
13
14
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cfloat> #include <cmath> #include <cstdint> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lint = int64_t; using uint = uint32_t; using ulint = uint64_t; template <class T> using vector2d = vector<vector<T>>; template <class T> bool UpdateMax(T &a, const T &b) { if (a < b) { a = b; return true; } else { return false; } } template <class T> bool UpdateMin(T &a, const T &b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> void OutVec(const vector<T> &vec) { for (int i = 0; i < vec.size() - 1; ++i) { cout << vec[i] << " "; } cout << vec.back() << endl; } template <class T> void OutVec2d(const vector2d<T> &vec) { for (auto v : vec) { OutVec(v); } } int main() { cout << std::fixed << std::setprecision(16); cin.tie(nullptr); std::ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> imos(n + 1); for (int j = 0; j < n; j++) { int l = max(0, j - a[j]); int r = min(n, j + a[j]); imos[l]++; imos[r + 1]--; } a[0] = imos[0]; for (int j = 0; j < n; j++) { a[j] = a[j - 1] + imos[j]; } bool all_n = true; for (int j = 0; j < n; j++) { if (a[j] != n) { all_n = false; break; } } if (all_n) { OutVec(a); return 0; } } OutVec(a); return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <cmath> #include <cstdint> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lint = int64_t; using uint = uint32_t; using ulint = uint64_t; template <class T> using vector2d = vector<vector<T>>; template <class T> bool UpdateMax(T &a, const T &b) { if (a < b) { a = b; return true; } else { return false; } } template <class T> bool UpdateMin(T &a, const T &b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> void OutVec(const vector<T> &vec) { for (int i = 0; i < vec.size() - 1; ++i) { cout << vec[i] << " "; } cout << vec.back() << endl; } template <class T> void OutVec2d(const vector2d<T> &vec) { for (auto v : vec) { OutVec(v); } } int main() { cout << std::fixed << std::setprecision(16); cin.tie(nullptr); std::ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> imos(n + 10); for (int j = 0; j < n; j++) { int l = max(0, j - a[j]); int r = min(n, j + a[j]); imos[l]++; imos[r + 1]--; } a[0] = imos[0]; for (int j = 0; j < n; j++) { a[j] = a[j - 1] + imos[j]; } bool all_n = true; for (int j = 0; j < n; j++) { if (a[j] != n) { all_n = false; break; } } if (all_n) { OutVec(a); return 0; } } OutVec(a); return 0; }
replace
70
71
70
71
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pa pair<int, int> #define pal pair<long long, long long> #define pali pair<long long, int> #define pad pair<double, double> #define pb push_back #define mp make_pair #define COUT(v) \ for (int64_t i = 0; i < (v).size(); ++i) { \ cout << v.at(i) << endl; \ } #define REP(i, n) for (int64_t i = 0; i < n; ++i) #define FOR(i, r, n) for (int64_t i = (r); i < n; ++i) #define VIN(v) \ for (int64_t i = 0; i < (v).size(); ++i) { \ cin >> (v).at(i); \ } typedef vector<bool> bvec; typedef vector<int> ivec; typedef vector<long long> lvec; typedef vector<double> dvec; typedef vector<pa> pavec; typedef vector<pali> palivec; typedef vector<pal> palvec; typedef vector<vector<bool>> bmat; typedef vector<vector<int>> imat; typedef vector<vector<long long>> lmat; typedef vector<string> svec; typedef vector<vector<string>> smat; const ll infll = (1LL << 60) - 1; const int inf = (1 << 30) - 1; const ll MOD = 1000000007; ll gcd(ll x, ll y) { ll r = x % y; if (r == 0) return y; else return gcd(y, r); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } lvec mfactor(ll n) { bvec ip(n, true); lvec mf(n, -1); ip[0] = false; ip[1] = false; mf[0] = 0; mf[1] = 1; REP(i, n) { if (ip[i]) { mf[i] = i; for (ll j = i * i; j < n; j += i) { ip[j] = false; if (mf[j] == -1) mf[j] = i; } } } return mf; } palivec get_prime(ll n, const lvec &mf) { palivec plist; while (n != 1) { int cnt = 0; ll m = mf[n]; while (mf[n] == m) { cnt++; n /= m; } plist.pb(pali(m, cnt)); } return plist; } void COMinit(int m, lvec &fac, lvec &finv) { lvec inv(m); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < m; 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; } } ll pow_mod(ll a, ll n) { ll x = 1; while (n > 0) { if (n & 1) { x = x * a % MOD; } a = a * a % MOD; n >>= 1; } return x; } ll pow_mod2(ll a, ll n) { ll x = 1; while (n > 0) { if (n & 1) { x = x * a; } a = a * a; n >>= 1; } return x; } ll COM(int n, int k, const lvec &fac, const lvec &finv) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // union by size + path having class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } // Union(Unite, Merge) bool merge(ll x, ll 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(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; lvec a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { // lvec mb(n+1, 0), mf(n+1, 0); map<ll, ll> mb, mf; lvec b(n), sb(n + 1), sf(n + 1); for (int j = 0; j < n; j++) { if (j - a[j] <= 0) mb[0]++; else mb[j - a[j]]++; if (j + a[j] + 1 >= n) mf[n]++; else mf[j + a[j] + 1]++; } sb[n] = 0; sf[0] = 0; for (int j = 1; j < n + 1; j++) sf[j] = sf[j - 1] + mf[j]; for (int j = n - 1; j >= 0; j--) sb[j] = sb[j + 1] + mb[j]; bool flg = true; for (int j = 0; j < n; j++) { b[j] = n - sb[j + 1] - (j == 0 ? sf[0] : sf[j]); if (b[j] != n) flg = false; } a = b; if (flg) break; } for (int i = 0; i < n; i++) { cout << a[i] << ' '; } cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pa pair<int, int> #define pal pair<long long, long long> #define pali pair<long long, int> #define pad pair<double, double> #define pb push_back #define mp make_pair #define COUT(v) \ for (int64_t i = 0; i < (v).size(); ++i) { \ cout << v.at(i) << endl; \ } #define REP(i, n) for (int64_t i = 0; i < n; ++i) #define FOR(i, r, n) for (int64_t i = (r); i < n; ++i) #define VIN(v) \ for (int64_t i = 0; i < (v).size(); ++i) { \ cin >> (v).at(i); \ } typedef vector<bool> bvec; typedef vector<int> ivec; typedef vector<long long> lvec; typedef vector<double> dvec; typedef vector<pa> pavec; typedef vector<pali> palivec; typedef vector<pal> palvec; typedef vector<vector<bool>> bmat; typedef vector<vector<int>> imat; typedef vector<vector<long long>> lmat; typedef vector<string> svec; typedef vector<vector<string>> smat; const ll infll = (1LL << 60) - 1; const int inf = (1 << 30) - 1; const ll MOD = 1000000007; ll gcd(ll x, ll y) { ll r = x % y; if (r == 0) return y; else return gcd(y, r); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } lvec mfactor(ll n) { bvec ip(n, true); lvec mf(n, -1); ip[0] = false; ip[1] = false; mf[0] = 0; mf[1] = 1; REP(i, n) { if (ip[i]) { mf[i] = i; for (ll j = i * i; j < n; j += i) { ip[j] = false; if (mf[j] == -1) mf[j] = i; } } } return mf; } palivec get_prime(ll n, const lvec &mf) { palivec plist; while (n != 1) { int cnt = 0; ll m = mf[n]; while (mf[n] == m) { cnt++; n /= m; } plist.pb(pali(m, cnt)); } return plist; } void COMinit(int m, lvec &fac, lvec &finv) { lvec inv(m); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < m; 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; } } ll pow_mod(ll a, ll n) { ll x = 1; while (n > 0) { if (n & 1) { x = x * a % MOD; } a = a * a % MOD; n >>= 1; } return x; } ll pow_mod2(ll a, ll n) { ll x = 1; while (n > 0) { if (n & 1) { x = x * a; } a = a * a; n >>= 1; } return x; } ll COM(int n, int k, const lvec &fac, const lvec &finv) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // union by size + path having class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } // Union(Unite, Merge) bool merge(ll x, ll 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(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; lvec a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { lvec mb(n + 1, 0), mf(n + 1, 0); // map<ll, ll> mb, mf; lvec b(n), sb(n + 1), sf(n + 1); for (int j = 0; j < n; j++) { if (j - a[j] <= 0) mb[0]++; else mb[j - a[j]]++; if (j + a[j] + 1 >= n) mf[n]++; else mf[j + a[j] + 1]++; } sb[n] = 0; sf[0] = 0; for (int j = 1; j < n + 1; j++) sf[j] = sf[j - 1] + mf[j]; for (int j = n - 1; j >= 0; j--) sb[j] = sb[j + 1] + mb[j]; bool flg = true; for (int j = 0; j < n; j++) { b[j] = n - sb[j + 1] - (j == 0 ? sf[0] : sf[j]); if (b[j] != n) flg = false; } a = b; if (flg) break; } for (int i = 0; i < n; i++) { cout << a[i] << ' '; } cout << endl; }
replace
197
199
197
199
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define srep(i, n, m) for (int i = n; i < m; i++) #define elif else if #define INF 1000000007 #define pi 3.141592653589793 using namespace std; int saidaikouyakusuu(int a, int b) { if (b == 0) return a; return saidaikouyakusuu(b, a % b); } int saisyoukoubaisuu(int a, int b) { return a * b / saidaikouyakusuu(a, b); } int n, m, cnt = 0, aa[220000], ab[220000]; pair<int, int> pp[220000]; string s, ss[220000]; char c, ca; queue<int> que; signed main() { cin >> n >> m; rep(i, n) { cin >> aa[i]; ab[max((long long)0, i - aa[i])]++; ab[min(n, i + aa[i] + 1)]--; } rep(i, min(m, n - 1)) { rep(j, n) { aa[j] = ab[j] + aa[j - 1]; ab[j] = 0; } rep(j, n) { ab[max((long long)0, j - aa[j])]++; ab[min(n, j + aa[j] + 1)]--; } } rep(i, n) { cout << aa[i] << ' '; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define srep(i, n, m) for (int i = n; i < m; i++) #define elif else if #define INF 1000000007 #define pi 3.141592653589793 using namespace std; int saidaikouyakusuu(int a, int b) { if (b == 0) return a; return saidaikouyakusuu(b, a % b); } int saisyoukoubaisuu(int a, int b) { return a * b / saidaikouyakusuu(a, b); } int n, m, cnt = 0, aa[220000], ab[220000]; pair<int, int> pp[220000]; string s, ss[220000]; char c, ca; queue<int> que; signed main() { cin >> n >> m; rep(i, n) { cin >> aa[i]; ab[max((long long)0, i - aa[i])]++; ab[min(n, i + aa[i] + 1)]--; } rep(i, min(m, (long long)100)) { rep(j, n) { aa[j] = ab[j] + aa[j - 1]; ab[j] = 0; } rep(j, n) { ab[max((long long)0, j - aa[j])]++; ab[min(n, j + aa[j] + 1)]--; } } rep(i, n) { cout << aa[i] << ' '; } }
replace
36
37
36
37
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) #include <bits/stdc++.h> using namespace std; static const ll INF = 1e15; static const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> prev(n); rep(i, n) cin >> prev[i]; vector<ll> current(n); rep(_, k) { vector<ll> sums(n + 1, 0); const auto &source = prev; for (int i = 0; i < n; i++) { auto t = source[i]; auto front = max(0LL, i - t); auto back = min(n, i + t + 1); sums[front]++; sums[back]--; } // cout << "back array" << endl; // rep(i, n + 1) { // cout << sums[i] << ","; // } // cout << endl; ll s = 0; // cout << "current" << endl; rep(i, n) { s += sums[i]; // cout << s << ","; current[i] = s; } bool finish = true; rep(i, n) { if (current[i] != n) { finish = false; break; } } swap(prev, current); } rep(i, n) { cout << prev[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) #include <bits/stdc++.h> using namespace std; static const ll INF = 1e15; static const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> prev(n); rep(i, n) cin >> prev[i]; vector<ll> current(n); rep(_, k) { vector<ll> sums(n + 1, 0); const auto &source = prev; for (int i = 0; i < n; i++) { auto t = source[i]; auto front = max(0LL, i - t); auto back = min(n, i + t + 1); sums[front]++; sums[back]--; } // cout << "back array" << endl; // rep(i, n + 1) { // cout << sums[i] << ","; // } // cout << endl; ll s = 0; // cout << "current" << endl; rep(i, n) { s += sums[i]; // cout << s << ","; current[i] = s; } bool finish = true; rep(i, n) { if (current[i] != n) { finish = false; break; } } swap(prev, current); if (finish) break; } rep(i, n) { cout << prev[i] << " "; } cout << endl; return 0; }
insert
59
59
59
61
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 998244353; // 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) 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; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 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; } // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> 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 dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, n) cin >> a[i]; while (k--) { vector<ll> b(n + 1, 0); REP(i, n) { int l = max(0LL, i - a[i]); int r = min(n, i + a[i] + 1); b[l]++; b[r]--; } a[0] = b[0]; REP(i, n) { b[i + 1] = b[i] + b[i + 1]; if (i + 1 < n) a[i + 1] = b[i + 1]; } } REP(i, n) { cout << a[i]; if (i != n - 1) cout << ' '; else cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 998244353; // 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) 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; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 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; } // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> 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 dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, n) cin >> a[i]; k = min(k, (ll)1000); while (k--) { vector<ll> b(n + 1, 0); REP(i, n) { int l = max(0LL, i - a[i]); int r = min(n, i + a[i] + 1); b[l]++; b[r]--; } a[0] = b[0]; REP(i, n) { b[i + 1] = b[i] + b[i + 1]; if (i + 1 < n) a[i + 1] = b[i + 1]; } } REP(i, n) { cout << a[i]; if (i != n - 1) cout << ' '; else cout << endl; } return 0; }
insert
264
264
264
265
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 200010; int n, m, minn = 1 << 30; int a[N], sum[N]; int main() { scanf("%d%d", &n, &m); for (int k = 1; k <= n; k++) scanf("%d", &a[k]), minn = min(minn, a[k]); for (int k = 1; k <= m && minn < n; k++) { memset(sum, 0, sizeof sum); for (int i = 1; i <= n; i++) { sum[i - a[i]]++; sum[i + a[i] + 1]--; } for (int i = 1; i <= n; i++) sum[i] += sum[i - 1]; minn = 1 << 30; for (int i = 1; i <= n; i++) a[i] = sum[i], minn = min(minn, a[i]); } for (int k = 1; k <= n; k++) printf("%d ", a[k]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 200010; int n, m, minn = 1 << 30; int a[N], sum[N]; int main() { scanf("%d%d", &n, &m); for (int k = 1; k <= n; k++) scanf("%d", &a[k]), minn = min(minn, a[k]); for (int k = 1; k <= m && minn < n; k++) { memset(sum, 0, sizeof sum); for (int i = 1; i <= n; i++) { sum[max(1, i - a[i])]++; sum[min(i + a[i] + 1, n + 1)]--; } for (int i = 1; i <= n; i++) sum[i] += sum[i - 1]; minn = 1 << 30; for (int i = 1; i <= n; i++) a[i] = sum[i], minn = min(minn, a[i]); } for (int k = 1; k <= n; k++) printf("%d ", a[k]); return 0; }
replace
15
17
15
17
0
p02647
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef char SINT8; typedef short SINT16; typedef int SINT32; typedef long long SINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++) #define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--) #define put(a) cout << (a) << endl #define puts(a) cout << (a) << " " #define putr(a) \ rep(testIncrement, 0, a.size()) { puts(a[testIncrement]); } \ cout << endl #define putrr(a) \ rep(Incr1, 0, a.size()) { \ rep(Incr2, 0, a[Incr1].size()) { puts(a[Incr1][Incr2]); } \ cout << endl; \ } \ cout << endl; #define INF 1000000001 #define MOD 1000000007 #define INF64 1000000000000000001 #define PI (acos(-1)) #define F first #define S second #define Pii pair<SINT32, SINT32> #define Pll pair<SINT64, SINT64> #define Piii pair<SINT32, pair<SINT32, SINT32>> #define Plll pair<SINT64, pair<SINT64, SINT64>> #define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c)) #define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d))) using namespace std; int main() { SINT64 N; cin >> N; SINT64 M; cin >> M; vector<SINT64> data(N); vector<SINT64> cp(N); vector<SINT64> cd(N); rep(i, 0, N) { cin >> data[i]; } rep(i, 0, N) { cp[i] = i + 1; cd[i] = N - i; } rep(ccc, 0, M) { vector<SINT64> l(N, 0); vector<SINT64> r(N, 0); rep(i, 0, N) { if (data[i] + 1; i < N) { r[data[i] + 1 + i] += -1; } } rep(i, 1, N) r[i] += r[i - 1]; rep(i, 0, N) r[i] += cp[i]; rep(i, 0, N) { if (i - data[i] - 1 >= 0) { l[i - data[i] - 1] += -1; } } rrep(i, N - 2, 0) l[i] += l[i + 1]; rep(i, 0, N) l[i] += cd[i]; rep(i, 0, N) { data[i] = l[i] + r[i] - 1; } // putr(r); // putr(l); SINT64 ok = 0; rep(i, 0, N) { if (data[i] != N) { ok = 1; break; } } if (ok == 0) break; } putr(data); return 0; } // vector<vector<SINT64>> data(N,vector<SINT64>(N)); ////2次元配列 vector<vector<vector<SINT64>>> //data(N,vector<vector<SINT64>>(N,vector<SINT64>(N))); //3次元配列 // Vll(data,N,N); //2次元配列 // Vlll(data,N,N,N); //3次元配列 // sort(data.begin(),data.end()); // sort(data.begin(),data.end(),std::greater<SINT64>()); // __gcd(A,B); // reverse(data.begin(),data.end()); // 関数へのvectorポインタ渡し // void dfs(SINT64 poi, SINT64 d, vector<vector<Pll>>& data) { // } /* 複数条件ソート bool sortcompare(Pll A, Pll B) { if(A.F == B.F){ return A.S > B.S; } else { return A.F < B.F; } } sort(data.begin(),data.end(),sortcompare); */ // タプル // vector<tuple<SINT64,SINT64,SINT64>> edges; // edges.emplace_back(a,b,c); // cout << get<0>(edges[i]); // cout << get<1>(edges[i]); // cout << get<2>(edges[i]); // sort(begin(edges), end(edges)); //ソート // data.emplace_back(BUF); //後ろに追加 // data.erase(std::unique(data.begin(), data.end()), data.end()); // //ソート後に使用 同じ値を消す // data.insert(data.begin() + X, 0); //X番目の要素に0を挿入 // 隣接リスト // vector<vector<SINT64>> data(N); // data[ A ].emplace_back( B ); // 両端キュー // deque<SINT64> data; // data.emplace_front(buf); //先頭挿入 // lower_boundは値がなければ最大値(.size())を返す // posi = lower_bound(data.begin(),data.end(), X) - data.begin(); // // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) - // data.begin(); //pair /* 文字列回転 string N; cin >> N; N = N[N.length()-1] + N.substr(0,N.length()-1); s = to_string(i); //ストリング変換 */ /* 文字列合成 string N,M; cin >> N >> M; SINT64 ans = 0; ans = stoi(N+M); */ /* 文字列変更 string s; cin >> s; rep(i,0,s.length()) { s[i] = (((s[i]-'A' + N) % 26) + 'A'); } put(s); */ /* //ワーシャルフロイド vector<vector<SINT64>> dist(N,vector<SINT64>(N,INF64)); rep(i,0,N) { dist[i][i] = 0; } rep(k,0,N) { rep(i,0,N) { rep(j,0,N) { dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]); } } } */ /* 優先度付きキュー priority_queue<SINT64, vector<SINT64>, greater<SINT64>> q; //小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> q; //大きいほうから取り出せる q.push(X); //X を挿入 q.top(); //先頭データ読み q.pop(); //先頭データ削除 */ /* キュー queue<SINT64> q; //宣言 q.push(0); //挿入 q.front(); //先頭データ読み q.pop(); //先頭データ削除 */ /* SET コンテナ set<SINT64> data; data.insert(X); //X を挿入 data.erase(data.begin()); //先頭を削除 data.erase(--data.end()); //末尾を削除 *data.begin(); //先頭要素にアクセス *data.rbegin(); //末尾要素にアクセス //全表示 set<SINT64>::iterator it; //イテレータを用意 for(it = data.begin(); it != data.end(); it++) { cout << *it << " "; } cout << endl; //N番目を一部表示 set<SINT64>::iterator it; // イテレータを用意 it = data.begin(); rep (i,0,N) { it++; } cout << *it << endl; */ /* map map<string,SINT32> mp; SINT32 N = 0; SINT32 mx = 0; cin >> N; for (SINT32 i = 0; i < N; i++) { string s; cin >> s; mp[s]++; } for(auto it=mp.begin();it!=mp.end();it++) { mx=max(mx,it->second); } //abc146E map<SINT64,SINT64> mp; rep(i,0,N+1) { ans += mp[rui[i]]; mp[rui[i]]++; bufq.push(rui[i]); if (bufq.size() == M) { mp[bufq.front()]--; bufq.pop(); } } */ /* //順列全表示 //sortしてからでないと全列挙にならない sort(data.begin(),data.end()); do { cout << buf << endl; rep(i,0,R) { cout << data[i] << " "; } cout << endl; } while (next_permutation(data.begin(),data.end())); */ /* bit数数え上げ SINT64 bits64(SINT64 bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff); } */ // bitシフトのLONG対応 // ans += (1L<<50); /* 余弦定理 2辺 A,B その間の角度からもう1辺を求める long double yogen(long double A, long double B, long double angle) { long double ans = A*A+B*B-A*B*2*cosl((PI/180.0)*angle); ans = sqrt(ans); return ans; } */ // 桁指定表示 // ans = ans * M_PI; // cout << setprecision(15) << ans << endl; // 桁数0埋め // cout << std::setfill('0') << std::right << std::setw(2) << 5; //05 // 2次元累積和 /* vector<vector<SINT64>> data(H,vector<SINT64>(W)); vector<vector<SINT64>> rui(H+1,vector<SINT64>(W+1)); rep(i,0,H) { rep(j,0,W) { cin >> data[i][j]; } } rep(i,1,H+1) { rep(j,1,W+1) { rui[i][j] = data[i-1][j-1] + rui[i][j-1]; } } rep(i,1,H+1) { rep(j,1,W+1) { rui[i][j] += rui[i-1][j]; } } */ // 逆元 コンビネーション /* SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { //pが偶数の時 SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); //a^(p/2) をhalfとして、half*halfを計算 return half * half % MOD; } else { //pが奇数の時は、偶数にするために1減らす return a * modpow(a, p - 1) % MOD; } } SINT64 calcComb(SINT64 a, SINT64 b) { SINT64 Mul = 1; SINT64 Div = 1; SINT64 ans = 0; if (b > a - b) { return calcComb(a, a - b); } rep(i,0,b) { Mul *= (a - i); Div *= (i + 1); Mul %= MOD; Div %= MOD; } ans = Mul * modpow(Div, MOD - 2) % MOD; return ans; } */ /* UNION FIND class UnionFind { public: vector<SINT64> parent; UnionFind(SINT64 N) { parent = vector<SINT64>(N+10, -1); //少し多めに } SINT64 root(SINT64 A) { if (parent[A] < 0) { return A; } else { parent[A] = root(parent[A]); return parent[A]; } } SINT64 size(SINT64 A) { return parent[root(A)] * (-1); } bool judge(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A == B) { return true; //同じグループ } else { return false; //違うグループ } } void connect(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A != B) { if (size(A) < size(B)) { swap(A, B); } parent[A] += parent[B]; parent[B] = A; } } }; UnionFind uni(N); */ /* セグ木 class SegTree { private: SINT64 size; vector<SINT64> node; SINT64 jugdement(SINT64 a, SINT64 b) { SINT64 ans = 0; ans = a+b; return ans; } public: //コンストラクタ SegTree(vector<SINT64> data) { SINT64 ori_size; ori_size = data.size(); size = 1; while (size < ori_size) { size *= 2; } node.resize(2*size-1, 0); rep(i,0,ori_size) { node[size-1+i] = data[i]; } rrep(i,size-2,0) { node[i] = jugdement(node[2*i+1], node[2*i+2]); } } //データ更新 void update(SINT64 x, SINT64 val) { x += (size - 1); node[x] = val+node[x]; while(x > 0) { x = (x - 1) / 2; node[x] = jugdement(node[2*x+1], node[2*x+2]); } } //データ取得 [a,b) SINT64 getdata(SINT64 a, SINT64 b, SINT64 k = 0, SINT64 l = 0, SINT64 r = -1) { if (r < 0) { r = size; } //要求範囲外 if ((r <= a) || (b <= l)) { return 0; } //完全要求区間内 if ((a <= l) && (r <= b)) { return node[k]; } SINT64 vl = getdata(a, b, 2*k+1, l, (l+r)/2); SINT64 vr = getdata(a, b, 2*k+2, (l+r)/2, r); return jugdement(vl, vr); } //表示 void disp() { rep(i,0,size) { puts(node[size-1+i]); } cout << endl; } void alldisp() { SINT64 cnt = 0; SINT64 end = 2; while (1) { puts(node[cnt]); if (cnt == end-2) { end *= 2; cout << endl; } cnt++; if (cnt == size*2-1) { break; } } } }; SegTree seg(N); */ /* 最大フロー最小カット class Dinic { struct EDGE { SINT64 to; SINT64 cap; SINT64 rev; }; vector<vector<EDGE>> G; vector<SINT64> level; vector<SINT64> root; SINT64 N; public: Dinic(SINT64 n) { N = n; G.resize(N); level.resize(N); } void add(SINT64 a, SINT64 b, SINT64 cap) { G[a].emplace_back((EDGE){b,cap,(SINT64)G[b].size()}); G[b].emplace_back((EDGE){a,0,(SINT64)G[a].size()-1}); } void bfs(SINT64 s) { level[s] = 0; queue<SINT64> q; q.push(s); while(q.size() != 0) { SINT64 buf = q.front(); q.pop(); rep(i,0,G[buf].size()) { EDGE now = G[buf][i]; if ((now.cap > 0) && (level[now.to] == -1)) { level[now.to] = level[buf]+1; q.push(now.to); } } } } SINT64 dfs(SINT64 now, SINT64 g, SINT64 flow) { if (now == g) return flow; rep(i,root[now],G[now].size()) { EDGE buf = G[now][i]; root[now] = i; //dsf進捗更新 if ((buf.cap > 0) && (level[buf.to] > level[now])) { SINT64 mi = MIN(buf.cap,flow); SINT64 nowf = dfs(buf.to,g,mi); if (nowf > 0) { G[now][i].cap -= nowf; //順経路に容量削減 G[buf.to][buf.rev].cap += nowf; //逆経路に容量追加 return nowf; //今回探索のFLOW追加数 } } } return 0; } SINT64 act(SINT64 s, SINT64 g) { SINT64 cnt = 0; //最大FLOWカウント if (s == g) return cnt; //スタート=ゴールは例外 while(1) { level.assign(N,-1); //sからの最短距離初期化 root.assign(N,0); //dsf進捗初期化 bfs(s); if (level[g] == -1) break; //gへ到達不可 while(1) { SINT64 flow; flow = dfs(s,g,INF64); if (flow == 0) break; cnt += flow; } } return cnt; } }; */ /* ダイクストラ class Dijkstra { vector<vector<Pll>> G; vector<SINT64> dist; public: Dijkstra(SINT64 n) { G.resize(n); dist.resize(n, INF64); } void add(SINT64 a, SINT64 b, SINT64 cost) { G[a].emplace_back(Pll(b,cost)); } void clear(SINT64 n) { dist.resize(0); dist.resize(n,INF64); } void form(SINT64 s) { priority_queue<Pll, vector<Pll>, greater<Pll>> q; q.push(Pll(0,s)); //cost,位置 while(q.size() != 0) { Pll now = q.top(); q.pop(); if (dist[now.S] == INF64) { dist[now.S] = now.F; rep(i,0,G[now.S].size()) { Pll buf = G[now.S][i]; if (dist[buf.F] == INF64) { q.push(Pll(buf.S+now.F,buf.F)); } } } } } //form()で構築したsからの距離を返す SINT64 get_dist(SINT64 a) { if (dist[a] == INF64) { return -1; //到達不可 } else { return dist[a]; } } }; */ /* LCA class Lca { vector<vector<SINT64>> G; vector<vector<SINT64>> D; //ダブリング vector<SINT64> depth; SINT64 N; SINT64 LOG_N; public: Lca(SINT64 n) { N = n; LOG_N = floor(log2(N)); G.resize(N); D.resize(N); depth.resize(N,-1); } void add(SINT64 a, SINT64 b) { G[a].emplace_back(b); G[b].emplace_back(a); } void bfs(SINT64 s) { depth[s] = 0; D[s].emplace_back(-1); queue<SINT64> q; q.push(s); while(q.size() != 0) { SINT64 now = q.front(); q.pop(); rep(i,0,G[now].size()) { SINT64 next = G[now][i]; if (depth[next] == -1) { depth[next] = depth[now]+1; D[next].emplace_back(now); q.push(next); } } } } //頂点のsからのダブリング構築 void form(SINT64 s) { bfs(s); rep(i,1,LOG_N+1) { rep(j,0,N) { SINT64 buf = D[j][i-1]; if (buf == -1) { D[j].emplace_back(-1); } else { D[j].emplace_back(D[buf][i-1]); } } } } //aのx上の頂点を求める SINT64 get(SINT64 a, SINT64 x) { rrep(i,LOG_N,0) { if (((x >> i) & 1) == 1) { a = D[a][i]; if (a == -1) return -1; } } return a; } //aとbの共通祖先を求める SINT64 get_lca(SINT64 a, SINT64 b) { if (depth[a] < depth[b]) swap(a,b); SINT64 diff = depth[a] - depth[b]; a = get(a,diff); //aのx上の頂点を求める if (a == b) return a; rrep(i,LOG_N,0) { if (D[a][i] != D[b][i]) { a = D[a][i]; b = D[b][i]; } } return D[a][0]; } //aとbの共通祖先までの距離の合計を求める SINT64 get_dist(SINT64 a, SINT64 b) { SINT64 buf = get_lca(a,b); return depth[a] + depth[b] - depth[buf]*2; } }; */ /* ベルマンフォード class Bellman { struct EDGE { SINT64 from; SINT64 to; SINT64 cost; }; vector<EDGE> edges; vector<SINT64> dist; SINT64 N; public: Bellman(SINT64 n) { N = n; dist.resize(n, INF64); } void add(SINT64 from, SINT64 to, SINT64 cost) { edges.emplace_back((EDGE){from,to,cost}); } //sで構築したt迄の距離取得 SINT64 get_dist(SINT64 t) { //到達不可はINF64 return dist[t]; } //構築 //負の閉路無し : 0 //負の閉路有り : 1 //負の閉路有るが目的地gの更新は停止 : 2 SINT64 form(SINT64 s, SINT64 g) { dist[s] = 0; SINT64 cnt = 0; SINT64 check = 0; while(1) { SINT64 renew = 0; rep(i,0,edges.size()) { EDGE e = edges[i]; if (dist[e.from] != INF64) { if (dist[e.to] > dist[e.from] + e.cost) { renew = 1; dist[e.to] = dist[e.from] + e.cost; } } } if (renew == 0) return 0; //N回更新後のgの距離と 2N回更新後のgの距離を比較 if (cnt == N) check = dist[g]; if (cnt > 2*N) { if (check == dist[g]) return 2; return 1; } cnt++; } } }; */ /*コンビネーション class Comb { vector<SINT64> base; SINT64 N; public: Comb (SINT64 n) { N = n+5; base.resize(N); base[0] = 1; rep(i,1,N) { base[i] = base[i-1]*i; base[i] %= MOD; } } SINT64 get_comb(SINT64 a, SINT64 b) { SINT64 ans = 0; SINT64 aa = base[a] * modpow(base[a-b], MOD - 2) % MOD; ans = aa * modpow(base[b], MOD - 2) % MOD; return ans; } SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); return half * half % MOD; } else { return a * modpow(a, p - 1) % MOD; } } }; */ /* SUFFIX ARRAY class SuffixArray { private: vector<string> array; // サフィックスアレイ vector<SINT64> lcp; // LCP vector<SINT64> sais; // SA IS string str; public: // コンストラクタ SuffixArray (string s) { str = s; vector<SINT64> Vstr; rep(i,0,str.length()) { Vstr.emplace_back(str[i]); } sais_act(Vstr, sais, 255); // SAIS実行 // lcp_act(); // 隣り合うSUFFIXの先頭から同じ長さを算出 // suffix array 文字列作成 // array.resize(str.length()); // rep(i,0,array.size()) { // array[i] = str.substr(sais[i]); // } // rep(i,0,array.size()) {put(array[i]);} // 表示用 } // LCP作成 void lcp_act(void) { lcp.resize(str.length()); vector<SINT64> buffer(str.length()); rep(i,0,str.length()) { buffer[sais[i]] = i; } SINT64 cnt = 0; rep(i,0,str.length()) { if (buffer[i] >= str.length()-1) { cnt = 0; } else { SINT64 a = buffer[i]; SINT64 b = buffer[i]+1; while(1) { if (cnt >= str.length() - sais[a]) break; if (cnt >= str.length() - sais[a]) break; if (str[sais[a]+cnt] == str[sais[b]+cnt]) { cnt++; } else { break; } } } lcp[buffer[i]] = cnt; if (cnt != 0) cnt--; } } // 引数の文字列が何個含まれるか算出 SINT64 get_cnt(string t) { SINT64 low,high; SINT64 L,R; L = -1; R = str.length(); while(R-L > 1) { SINT64 M = (R+L)/2; string buf = str.substr(sais[M]); if (buf.length() > t.length()) { buf = buf.substr(0,t.length()); } if (buf > t) {R = M;} else {L = M;} } high = R; L = -1; R = str.length(); while(R-L > 1) { SINT64 M = (R+L)/2; string buf = str.substr(sais[M]); if (buf >= t) {R = M;} else {L = M;} } low = R; return high - low; } // SAIS実行 void sais_act(vector<SINT64>& Vstr, vector<SINT64>& r_sais, SINT64 type) { Vstr.push_back(0); // 番兵追加 vector<SINT64> lms_seed; // LMS ソート前 vector<SINT64> lms_sort; // LMS ソート後 vector<SINT64> lms_long(Vstr.size(),0); // LMS 長さ vector<SINT64> lms_type(Vstr.size(),1); // 0:L 1:S 2:LMS vector<SINT64> lms_posi(Vstr.size(),-1); // LMS内での位置 SINT64 len = 0; // L S LMS判定 初期値は全てS rrep(i,Vstr.size()-2,0) { len++; if (Vstr[i] > Vstr[i+1]) { lms_type[i] = 0; // L if (lms_type[i+1] == 1) { lms_type[i+1] = 2; // LMS lms_long[i+1] = len; // LMSの長さ格納 len = 1; } } if (Vstr[i] == Vstr[i+1]) lms_type[i] = lms_type[i+1]; // 右と同じ } SINT64 cnt = 0; rep(i,0,Vstr.size()) { if (lms_type[i] == 2) lms_seed.emplace_back(i); if (lms_type[i] == 2) lms_posi[i] = cnt++; } // Induced Sort初回 vector<SINT64> bucket; // Induced Sort初回結果格納用 induced_sort(Vstr, lms_seed, bucket, lms_type, type); // lms_sortにLMSのソートを格納 rrep(i,Vstr.size()-1,0) { if ((bucket[i] != -1) && (lms_type[bucket[i]] == 2)) { lms_sort.emplace_back(bucket[i]); } } SINT64 ok = 0; // 再帰必要性判定 SINT64 rank = 1; // 再帰用文字 vector<SINT64> next(lms_sort.size(), 1); // 再帰用文字列 rrep(i,lms_sort.size()-2,0) { SINT64 A = lms_long[lms_sort[i]]; SINT64 B = lms_long[lms_sort[i+1]]; if (A == B) { SINT64 ck = 0; rep(j,0,A) { if (Vstr[lms_sort[i]+j] != Vstr[lms_sort[i+1]+j]) { ck = 1; break; } } if (ck == 0) { ok = 1; // 再帰必要 } else { rank++; } } else { rank++; } next[lms_posi[lms_sort[i]]] = rank; } if (ok == 1) { vector<SINT64> recursive; sais_act(next, recursive, rank+1); rep(i,0,recursive.size()) { lms_sort[recursive.size()-i-1] = lms_seed[recursive[i]]; } } // SORT済みLMSでInduced Sorting r_sais.resize(Vstr.size(),-1); induced_sort(Vstr, lms_sort, r_sais, lms_type, type); r_sais.erase(r_sais.begin()); // 番兵削除 } // induced_sort void induced_sort(vector<SINT64>& Vstr, vector<SINT64>& seed, vector<SINT64>& bucket_sort, vector<SINT64>& lms_type, SINT64 type) { vector<SINT64> bucket_cnt(type,0); // バケット 文字種ごとの数 vector<SINT64> bucket_st(type,0); // バケット 文字種の開始位置 vector<SINT64> bucket_end(type,0); // バケット 文字種の終了位置 vector<SINT64> bucket_pre(Vstr.size(),-1); // バケット 初回格納用 vector<SINT64> cnt1(type,0); vector<SINT64> cnt2(type,0); vector<SINT64> cnt3(type,0); bucket_sort.resize(Vstr.size(),-1); // バケットソート位置作成 rep(i,0,Vstr.size()) bucket_cnt[Vstr[i]]++; // 個数作成 rep(i,1,type) bucket_st[i] = bucket_st[i-1] + bucket_cnt[i-1]; // 開始位置 rep(i,0,type) bucket_end[i] = bucket_st[i] + bucket_cnt[i]-1; // 終了位置 // LMSをbucket_preに格納 rep(i,0,seed.size()) { SINT64 no = seed[i]; bucket_pre[bucket_end[Vstr[no]] - cnt1[Vstr[no]]] = no; cnt1[Vstr[no]]++; } // Lをbucket_sortに格納 rep(i,0,Vstr.size()) { if ((bucket_pre[i] != -1) && (bucket_pre[i] != 0)) { if (lms_type[bucket_pre[i]-1] == 0) { // -1がLの場合 SINT64 buf = Vstr[bucket_pre[i]-1]; bucket_pre [bucket_st[buf] + cnt2[buf]] = bucket_pre[i]-1; bucket_sort[bucket_st[buf] + cnt2[buf]] = bucket_pre[i]-1; cnt2[buf]++; } } } // Sをbucket_sortに格納 bucket_sort[0] = Vstr.size()-1; // 番兵追加 rrep(i,Vstr.size()-1,0) { if ((bucket_sort[i] != -1) && (bucket_sort[i] != 0)) { if (lms_type[bucket_sort[i]-1] != 0) { // -1がS(LMS)の場合 SINT64 buf = Vstr[bucket_sort[i]-1]; bucket_sort[bucket_end[buf] - cnt3[buf]] = bucket_sort[i]-1; cnt3[buf]++; } } } } }; */ /* 転倒数の数え上げ SINT64 merge_cnt(vector<SINT64> &a) { SINT64 n = a.size(); if (n <= 1) { return 0; } SINT64 cnt = 0; vector<SINT64> b(a.begin(), a.begin()+n/2); vector<SINT64> c(a.begin()+n/2, a.end()); cnt += merge_cnt(b); cnt += merge_cnt(c); SINT64 ai = 0, bi = 0, ci = 0; // merge の処理 while (ai < n) { if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) { a[ai++] = b[bi++]; } else { cnt += n / 2 - bi; a[ai++] = c[ci++]; } } return cnt; } */ /* 最長部分文字列 SINT64 LCS(string s, string t) { SINT64 n = s.size(); SINT64 m = t.size(); vector<vector<SINT64>> DP(n+1,vector<SINT64>(m+1,0)); rep(i,0,n) { rep(j,0,m) { if (s[i] == t[j]) { DP[i+1][j+1] = DP[i][j]+1; } else { DP[i+1][j+1] = MAX(DP[i+1][j],DP[i][j+1]); } } } return DP[n][m]; } */
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef char SINT8; typedef short SINT16; typedef int SINT32; typedef long long SINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++) #define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--) #define put(a) cout << (a) << endl #define puts(a) cout << (a) << " " #define putr(a) \ rep(testIncrement, 0, a.size()) { puts(a[testIncrement]); } \ cout << endl #define putrr(a) \ rep(Incr1, 0, a.size()) { \ rep(Incr2, 0, a[Incr1].size()) { puts(a[Incr1][Incr2]); } \ cout << endl; \ } \ cout << endl; #define INF 1000000001 #define MOD 1000000007 #define INF64 1000000000000000001 #define PI (acos(-1)) #define F first #define S second #define Pii pair<SINT32, SINT32> #define Pll pair<SINT64, SINT64> #define Piii pair<SINT32, pair<SINT32, SINT32>> #define Plll pair<SINT64, pair<SINT64, SINT64>> #define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c)) #define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d))) using namespace std; int main() { SINT64 N; cin >> N; SINT64 M; cin >> M; vector<SINT64> data(N); vector<SINT64> cp(N); vector<SINT64> cd(N); rep(i, 0, N) { cin >> data[i]; } rep(i, 0, N) { cp[i] = i + 1; cd[i] = N - i; } rep(ccc, 0, M) { vector<SINT64> l(N, 0); vector<SINT64> r(N, 0); rep(i, 0, N) { if (data[i] + 1 + i < N) { r[data[i] + 1 + i] += -1; } } rep(i, 1, N) r[i] += r[i - 1]; rep(i, 0, N) r[i] += cp[i]; rep(i, 0, N) { if (i - data[i] - 1 >= 0) { l[i - data[i] - 1] += -1; } } rrep(i, N - 2, 0) l[i] += l[i + 1]; rep(i, 0, N) l[i] += cd[i]; rep(i, 0, N) { data[i] = l[i] + r[i] - 1; } // putr(r); // putr(l); SINT64 ok = 0; rep(i, 0, N) { if (data[i] != N) { ok = 1; break; } } if (ok == 0) break; } putr(data); return 0; } // vector<vector<SINT64>> data(N,vector<SINT64>(N)); ////2次元配列 vector<vector<vector<SINT64>>> //data(N,vector<vector<SINT64>>(N,vector<SINT64>(N))); //3次元配列 // Vll(data,N,N); //2次元配列 // Vlll(data,N,N,N); //3次元配列 // sort(data.begin(),data.end()); // sort(data.begin(),data.end(),std::greater<SINT64>()); // __gcd(A,B); // reverse(data.begin(),data.end()); // 関数へのvectorポインタ渡し // void dfs(SINT64 poi, SINT64 d, vector<vector<Pll>>& data) { // } /* 複数条件ソート bool sortcompare(Pll A, Pll B) { if(A.F == B.F){ return A.S > B.S; } else { return A.F < B.F; } } sort(data.begin(),data.end(),sortcompare); */ // タプル // vector<tuple<SINT64,SINT64,SINT64>> edges; // edges.emplace_back(a,b,c); // cout << get<0>(edges[i]); // cout << get<1>(edges[i]); // cout << get<2>(edges[i]); // sort(begin(edges), end(edges)); //ソート // data.emplace_back(BUF); //後ろに追加 // data.erase(std::unique(data.begin(), data.end()), data.end()); // //ソート後に使用 同じ値を消す // data.insert(data.begin() + X, 0); //X番目の要素に0を挿入 // 隣接リスト // vector<vector<SINT64>> data(N); // data[ A ].emplace_back( B ); // 両端キュー // deque<SINT64> data; // data.emplace_front(buf); //先頭挿入 // lower_boundは値がなければ最大値(.size())を返す // posi = lower_bound(data.begin(),data.end(), X) - data.begin(); // // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) - // data.begin(); //pair /* 文字列回転 string N; cin >> N; N = N[N.length()-1] + N.substr(0,N.length()-1); s = to_string(i); //ストリング変換 */ /* 文字列合成 string N,M; cin >> N >> M; SINT64 ans = 0; ans = stoi(N+M); */ /* 文字列変更 string s; cin >> s; rep(i,0,s.length()) { s[i] = (((s[i]-'A' + N) % 26) + 'A'); } put(s); */ /* //ワーシャルフロイド vector<vector<SINT64>> dist(N,vector<SINT64>(N,INF64)); rep(i,0,N) { dist[i][i] = 0; } rep(k,0,N) { rep(i,0,N) { rep(j,0,N) { dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]); } } } */ /* 優先度付きキュー priority_queue<SINT64, vector<SINT64>, greater<SINT64>> q; //小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> q; //大きいほうから取り出せる q.push(X); //X を挿入 q.top(); //先頭データ読み q.pop(); //先頭データ削除 */ /* キュー queue<SINT64> q; //宣言 q.push(0); //挿入 q.front(); //先頭データ読み q.pop(); //先頭データ削除 */ /* SET コンテナ set<SINT64> data; data.insert(X); //X を挿入 data.erase(data.begin()); //先頭を削除 data.erase(--data.end()); //末尾を削除 *data.begin(); //先頭要素にアクセス *data.rbegin(); //末尾要素にアクセス //全表示 set<SINT64>::iterator it; //イテレータを用意 for(it = data.begin(); it != data.end(); it++) { cout << *it << " "; } cout << endl; //N番目を一部表示 set<SINT64>::iterator it; // イテレータを用意 it = data.begin(); rep (i,0,N) { it++; } cout << *it << endl; */ /* map map<string,SINT32> mp; SINT32 N = 0; SINT32 mx = 0; cin >> N; for (SINT32 i = 0; i < N; i++) { string s; cin >> s; mp[s]++; } for(auto it=mp.begin();it!=mp.end();it++) { mx=max(mx,it->second); } //abc146E map<SINT64,SINT64> mp; rep(i,0,N+1) { ans += mp[rui[i]]; mp[rui[i]]++; bufq.push(rui[i]); if (bufq.size() == M) { mp[bufq.front()]--; bufq.pop(); } } */ /* //順列全表示 //sortしてからでないと全列挙にならない sort(data.begin(),data.end()); do { cout << buf << endl; rep(i,0,R) { cout << data[i] << " "; } cout << endl; } while (next_permutation(data.begin(),data.end())); */ /* bit数数え上げ SINT64 bits64(SINT64 bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff); } */ // bitシフトのLONG対応 // ans += (1L<<50); /* 余弦定理 2辺 A,B その間の角度からもう1辺を求める long double yogen(long double A, long double B, long double angle) { long double ans = A*A+B*B-A*B*2*cosl((PI/180.0)*angle); ans = sqrt(ans); return ans; } */ // 桁指定表示 // ans = ans * M_PI; // cout << setprecision(15) << ans << endl; // 桁数0埋め // cout << std::setfill('0') << std::right << std::setw(2) << 5; //05 // 2次元累積和 /* vector<vector<SINT64>> data(H,vector<SINT64>(W)); vector<vector<SINT64>> rui(H+1,vector<SINT64>(W+1)); rep(i,0,H) { rep(j,0,W) { cin >> data[i][j]; } } rep(i,1,H+1) { rep(j,1,W+1) { rui[i][j] = data[i-1][j-1] + rui[i][j-1]; } } rep(i,1,H+1) { rep(j,1,W+1) { rui[i][j] += rui[i-1][j]; } } */ // 逆元 コンビネーション /* SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { //pが偶数の時 SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); //a^(p/2) をhalfとして、half*halfを計算 return half * half % MOD; } else { //pが奇数の時は、偶数にするために1減らす return a * modpow(a, p - 1) % MOD; } } SINT64 calcComb(SINT64 a, SINT64 b) { SINT64 Mul = 1; SINT64 Div = 1; SINT64 ans = 0; if (b > a - b) { return calcComb(a, a - b); } rep(i,0,b) { Mul *= (a - i); Div *= (i + 1); Mul %= MOD; Div %= MOD; } ans = Mul * modpow(Div, MOD - 2) % MOD; return ans; } */ /* UNION FIND class UnionFind { public: vector<SINT64> parent; UnionFind(SINT64 N) { parent = vector<SINT64>(N+10, -1); //少し多めに } SINT64 root(SINT64 A) { if (parent[A] < 0) { return A; } else { parent[A] = root(parent[A]); return parent[A]; } } SINT64 size(SINT64 A) { return parent[root(A)] * (-1); } bool judge(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A == B) { return true; //同じグループ } else { return false; //違うグループ } } void connect(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A != B) { if (size(A) < size(B)) { swap(A, B); } parent[A] += parent[B]; parent[B] = A; } } }; UnionFind uni(N); */ /* セグ木 class SegTree { private: SINT64 size; vector<SINT64> node; SINT64 jugdement(SINT64 a, SINT64 b) { SINT64 ans = 0; ans = a+b; return ans; } public: //コンストラクタ SegTree(vector<SINT64> data) { SINT64 ori_size; ori_size = data.size(); size = 1; while (size < ori_size) { size *= 2; } node.resize(2*size-1, 0); rep(i,0,ori_size) { node[size-1+i] = data[i]; } rrep(i,size-2,0) { node[i] = jugdement(node[2*i+1], node[2*i+2]); } } //データ更新 void update(SINT64 x, SINT64 val) { x += (size - 1); node[x] = val+node[x]; while(x > 0) { x = (x - 1) / 2; node[x] = jugdement(node[2*x+1], node[2*x+2]); } } //データ取得 [a,b) SINT64 getdata(SINT64 a, SINT64 b, SINT64 k = 0, SINT64 l = 0, SINT64 r = -1) { if (r < 0) { r = size; } //要求範囲外 if ((r <= a) || (b <= l)) { return 0; } //完全要求区間内 if ((a <= l) && (r <= b)) { return node[k]; } SINT64 vl = getdata(a, b, 2*k+1, l, (l+r)/2); SINT64 vr = getdata(a, b, 2*k+2, (l+r)/2, r); return jugdement(vl, vr); } //表示 void disp() { rep(i,0,size) { puts(node[size-1+i]); } cout << endl; } void alldisp() { SINT64 cnt = 0; SINT64 end = 2; while (1) { puts(node[cnt]); if (cnt == end-2) { end *= 2; cout << endl; } cnt++; if (cnt == size*2-1) { break; } } } }; SegTree seg(N); */ /* 最大フロー最小カット class Dinic { struct EDGE { SINT64 to; SINT64 cap; SINT64 rev; }; vector<vector<EDGE>> G; vector<SINT64> level; vector<SINT64> root; SINT64 N; public: Dinic(SINT64 n) { N = n; G.resize(N); level.resize(N); } void add(SINT64 a, SINT64 b, SINT64 cap) { G[a].emplace_back((EDGE){b,cap,(SINT64)G[b].size()}); G[b].emplace_back((EDGE){a,0,(SINT64)G[a].size()-1}); } void bfs(SINT64 s) { level[s] = 0; queue<SINT64> q; q.push(s); while(q.size() != 0) { SINT64 buf = q.front(); q.pop(); rep(i,0,G[buf].size()) { EDGE now = G[buf][i]; if ((now.cap > 0) && (level[now.to] == -1)) { level[now.to] = level[buf]+1; q.push(now.to); } } } } SINT64 dfs(SINT64 now, SINT64 g, SINT64 flow) { if (now == g) return flow; rep(i,root[now],G[now].size()) { EDGE buf = G[now][i]; root[now] = i; //dsf進捗更新 if ((buf.cap > 0) && (level[buf.to] > level[now])) { SINT64 mi = MIN(buf.cap,flow); SINT64 nowf = dfs(buf.to,g,mi); if (nowf > 0) { G[now][i].cap -= nowf; //順経路に容量削減 G[buf.to][buf.rev].cap += nowf; //逆経路に容量追加 return nowf; //今回探索のFLOW追加数 } } } return 0; } SINT64 act(SINT64 s, SINT64 g) { SINT64 cnt = 0; //最大FLOWカウント if (s == g) return cnt; //スタート=ゴールは例外 while(1) { level.assign(N,-1); //sからの最短距離初期化 root.assign(N,0); //dsf進捗初期化 bfs(s); if (level[g] == -1) break; //gへ到達不可 while(1) { SINT64 flow; flow = dfs(s,g,INF64); if (flow == 0) break; cnt += flow; } } return cnt; } }; */ /* ダイクストラ class Dijkstra { vector<vector<Pll>> G; vector<SINT64> dist; public: Dijkstra(SINT64 n) { G.resize(n); dist.resize(n, INF64); } void add(SINT64 a, SINT64 b, SINT64 cost) { G[a].emplace_back(Pll(b,cost)); } void clear(SINT64 n) { dist.resize(0); dist.resize(n,INF64); } void form(SINT64 s) { priority_queue<Pll, vector<Pll>, greater<Pll>> q; q.push(Pll(0,s)); //cost,位置 while(q.size() != 0) { Pll now = q.top(); q.pop(); if (dist[now.S] == INF64) { dist[now.S] = now.F; rep(i,0,G[now.S].size()) { Pll buf = G[now.S][i]; if (dist[buf.F] == INF64) { q.push(Pll(buf.S+now.F,buf.F)); } } } } } //form()で構築したsからの距離を返す SINT64 get_dist(SINT64 a) { if (dist[a] == INF64) { return -1; //到達不可 } else { return dist[a]; } } }; */ /* LCA class Lca { vector<vector<SINT64>> G; vector<vector<SINT64>> D; //ダブリング vector<SINT64> depth; SINT64 N; SINT64 LOG_N; public: Lca(SINT64 n) { N = n; LOG_N = floor(log2(N)); G.resize(N); D.resize(N); depth.resize(N,-1); } void add(SINT64 a, SINT64 b) { G[a].emplace_back(b); G[b].emplace_back(a); } void bfs(SINT64 s) { depth[s] = 0; D[s].emplace_back(-1); queue<SINT64> q; q.push(s); while(q.size() != 0) { SINT64 now = q.front(); q.pop(); rep(i,0,G[now].size()) { SINT64 next = G[now][i]; if (depth[next] == -1) { depth[next] = depth[now]+1; D[next].emplace_back(now); q.push(next); } } } } //頂点のsからのダブリング構築 void form(SINT64 s) { bfs(s); rep(i,1,LOG_N+1) { rep(j,0,N) { SINT64 buf = D[j][i-1]; if (buf == -1) { D[j].emplace_back(-1); } else { D[j].emplace_back(D[buf][i-1]); } } } } //aのx上の頂点を求める SINT64 get(SINT64 a, SINT64 x) { rrep(i,LOG_N,0) { if (((x >> i) & 1) == 1) { a = D[a][i]; if (a == -1) return -1; } } return a; } //aとbの共通祖先を求める SINT64 get_lca(SINT64 a, SINT64 b) { if (depth[a] < depth[b]) swap(a,b); SINT64 diff = depth[a] - depth[b]; a = get(a,diff); //aのx上の頂点を求める if (a == b) return a; rrep(i,LOG_N,0) { if (D[a][i] != D[b][i]) { a = D[a][i]; b = D[b][i]; } } return D[a][0]; } //aとbの共通祖先までの距離の合計を求める SINT64 get_dist(SINT64 a, SINT64 b) { SINT64 buf = get_lca(a,b); return depth[a] + depth[b] - depth[buf]*2; } }; */ /* ベルマンフォード class Bellman { struct EDGE { SINT64 from; SINT64 to; SINT64 cost; }; vector<EDGE> edges; vector<SINT64> dist; SINT64 N; public: Bellman(SINT64 n) { N = n; dist.resize(n, INF64); } void add(SINT64 from, SINT64 to, SINT64 cost) { edges.emplace_back((EDGE){from,to,cost}); } //sで構築したt迄の距離取得 SINT64 get_dist(SINT64 t) { //到達不可はINF64 return dist[t]; } //構築 //負の閉路無し : 0 //負の閉路有り : 1 //負の閉路有るが目的地gの更新は停止 : 2 SINT64 form(SINT64 s, SINT64 g) { dist[s] = 0; SINT64 cnt = 0; SINT64 check = 0; while(1) { SINT64 renew = 0; rep(i,0,edges.size()) { EDGE e = edges[i]; if (dist[e.from] != INF64) { if (dist[e.to] > dist[e.from] + e.cost) { renew = 1; dist[e.to] = dist[e.from] + e.cost; } } } if (renew == 0) return 0; //N回更新後のgの距離と 2N回更新後のgの距離を比較 if (cnt == N) check = dist[g]; if (cnt > 2*N) { if (check == dist[g]) return 2; return 1; } cnt++; } } }; */ /*コンビネーション class Comb { vector<SINT64> base; SINT64 N; public: Comb (SINT64 n) { N = n+5; base.resize(N); base[0] = 1; rep(i,1,N) { base[i] = base[i-1]*i; base[i] %= MOD; } } SINT64 get_comb(SINT64 a, SINT64 b) { SINT64 ans = 0; SINT64 aa = base[a] * modpow(base[a-b], MOD - 2) % MOD; ans = aa * modpow(base[b], MOD - 2) % MOD; return ans; } SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); return half * half % MOD; } else { return a * modpow(a, p - 1) % MOD; } } }; */ /* SUFFIX ARRAY class SuffixArray { private: vector<string> array; // サフィックスアレイ vector<SINT64> lcp; // LCP vector<SINT64> sais; // SA IS string str; public: // コンストラクタ SuffixArray (string s) { str = s; vector<SINT64> Vstr; rep(i,0,str.length()) { Vstr.emplace_back(str[i]); } sais_act(Vstr, sais, 255); // SAIS実行 // lcp_act(); // 隣り合うSUFFIXの先頭から同じ長さを算出 // suffix array 文字列作成 // array.resize(str.length()); // rep(i,0,array.size()) { // array[i] = str.substr(sais[i]); // } // rep(i,0,array.size()) {put(array[i]);} // 表示用 } // LCP作成 void lcp_act(void) { lcp.resize(str.length()); vector<SINT64> buffer(str.length()); rep(i,0,str.length()) { buffer[sais[i]] = i; } SINT64 cnt = 0; rep(i,0,str.length()) { if (buffer[i] >= str.length()-1) { cnt = 0; } else { SINT64 a = buffer[i]; SINT64 b = buffer[i]+1; while(1) { if (cnt >= str.length() - sais[a]) break; if (cnt >= str.length() - sais[a]) break; if (str[sais[a]+cnt] == str[sais[b]+cnt]) { cnt++; } else { break; } } } lcp[buffer[i]] = cnt; if (cnt != 0) cnt--; } } // 引数の文字列が何個含まれるか算出 SINT64 get_cnt(string t) { SINT64 low,high; SINT64 L,R; L = -1; R = str.length(); while(R-L > 1) { SINT64 M = (R+L)/2; string buf = str.substr(sais[M]); if (buf.length() > t.length()) { buf = buf.substr(0,t.length()); } if (buf > t) {R = M;} else {L = M;} } high = R; L = -1; R = str.length(); while(R-L > 1) { SINT64 M = (R+L)/2; string buf = str.substr(sais[M]); if (buf >= t) {R = M;} else {L = M;} } low = R; return high - low; } // SAIS実行 void sais_act(vector<SINT64>& Vstr, vector<SINT64>& r_sais, SINT64 type) { Vstr.push_back(0); // 番兵追加 vector<SINT64> lms_seed; // LMS ソート前 vector<SINT64> lms_sort; // LMS ソート後 vector<SINT64> lms_long(Vstr.size(),0); // LMS 長さ vector<SINT64> lms_type(Vstr.size(),1); // 0:L 1:S 2:LMS vector<SINT64> lms_posi(Vstr.size(),-1); // LMS内での位置 SINT64 len = 0; // L S LMS判定 初期値は全てS rrep(i,Vstr.size()-2,0) { len++; if (Vstr[i] > Vstr[i+1]) { lms_type[i] = 0; // L if (lms_type[i+1] == 1) { lms_type[i+1] = 2; // LMS lms_long[i+1] = len; // LMSの長さ格納 len = 1; } } if (Vstr[i] == Vstr[i+1]) lms_type[i] = lms_type[i+1]; // 右と同じ } SINT64 cnt = 0; rep(i,0,Vstr.size()) { if (lms_type[i] == 2) lms_seed.emplace_back(i); if (lms_type[i] == 2) lms_posi[i] = cnt++; } // Induced Sort初回 vector<SINT64> bucket; // Induced Sort初回結果格納用 induced_sort(Vstr, lms_seed, bucket, lms_type, type); // lms_sortにLMSのソートを格納 rrep(i,Vstr.size()-1,0) { if ((bucket[i] != -1) && (lms_type[bucket[i]] == 2)) { lms_sort.emplace_back(bucket[i]); } } SINT64 ok = 0; // 再帰必要性判定 SINT64 rank = 1; // 再帰用文字 vector<SINT64> next(lms_sort.size(), 1); // 再帰用文字列 rrep(i,lms_sort.size()-2,0) { SINT64 A = lms_long[lms_sort[i]]; SINT64 B = lms_long[lms_sort[i+1]]; if (A == B) { SINT64 ck = 0; rep(j,0,A) { if (Vstr[lms_sort[i]+j] != Vstr[lms_sort[i+1]+j]) { ck = 1; break; } } if (ck == 0) { ok = 1; // 再帰必要 } else { rank++; } } else { rank++; } next[lms_posi[lms_sort[i]]] = rank; } if (ok == 1) { vector<SINT64> recursive; sais_act(next, recursive, rank+1); rep(i,0,recursive.size()) { lms_sort[recursive.size()-i-1] = lms_seed[recursive[i]]; } } // SORT済みLMSでInduced Sorting r_sais.resize(Vstr.size(),-1); induced_sort(Vstr, lms_sort, r_sais, lms_type, type); r_sais.erase(r_sais.begin()); // 番兵削除 } // induced_sort void induced_sort(vector<SINT64>& Vstr, vector<SINT64>& seed, vector<SINT64>& bucket_sort, vector<SINT64>& lms_type, SINT64 type) { vector<SINT64> bucket_cnt(type,0); // バケット 文字種ごとの数 vector<SINT64> bucket_st(type,0); // バケット 文字種の開始位置 vector<SINT64> bucket_end(type,0); // バケット 文字種の終了位置 vector<SINT64> bucket_pre(Vstr.size(),-1); // バケット 初回格納用 vector<SINT64> cnt1(type,0); vector<SINT64> cnt2(type,0); vector<SINT64> cnt3(type,0); bucket_sort.resize(Vstr.size(),-1); // バケットソート位置作成 rep(i,0,Vstr.size()) bucket_cnt[Vstr[i]]++; // 個数作成 rep(i,1,type) bucket_st[i] = bucket_st[i-1] + bucket_cnt[i-1]; // 開始位置 rep(i,0,type) bucket_end[i] = bucket_st[i] + bucket_cnt[i]-1; // 終了位置 // LMSをbucket_preに格納 rep(i,0,seed.size()) { SINT64 no = seed[i]; bucket_pre[bucket_end[Vstr[no]] - cnt1[Vstr[no]]] = no; cnt1[Vstr[no]]++; } // Lをbucket_sortに格納 rep(i,0,Vstr.size()) { if ((bucket_pre[i] != -1) && (bucket_pre[i] != 0)) { if (lms_type[bucket_pre[i]-1] == 0) { // -1がLの場合 SINT64 buf = Vstr[bucket_pre[i]-1]; bucket_pre [bucket_st[buf] + cnt2[buf]] = bucket_pre[i]-1; bucket_sort[bucket_st[buf] + cnt2[buf]] = bucket_pre[i]-1; cnt2[buf]++; } } } // Sをbucket_sortに格納 bucket_sort[0] = Vstr.size()-1; // 番兵追加 rrep(i,Vstr.size()-1,0) { if ((bucket_sort[i] != -1) && (bucket_sort[i] != 0)) { if (lms_type[bucket_sort[i]-1] != 0) { // -1がS(LMS)の場合 SINT64 buf = Vstr[bucket_sort[i]-1]; bucket_sort[bucket_end[buf] - cnt3[buf]] = bucket_sort[i]-1; cnt3[buf]++; } } } } }; */ /* 転倒数の数え上げ SINT64 merge_cnt(vector<SINT64> &a) { SINT64 n = a.size(); if (n <= 1) { return 0; } SINT64 cnt = 0; vector<SINT64> b(a.begin(), a.begin()+n/2); vector<SINT64> c(a.begin()+n/2, a.end()); cnt += merge_cnt(b); cnt += merge_cnt(c); SINT64 ai = 0, bi = 0, ci = 0; // merge の処理 while (ai < n) { if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) { a[ai++] = b[bi++]; } else { cnt += n / 2 - bi; a[ai++] = c[ci++]; } } return cnt; } */ /* 最長部分文字列 SINT64 LCS(string s, string t) { SINT64 n = s.size(); SINT64 m = t.size(); vector<vector<SINT64>> DP(n+1,vector<SINT64>(m+1,0)); rep(i,0,n) { rep(j,0,m) { if (s[i] == t[j]) { DP[i+1][j+1] = DP[i][j]+1; } else { DP[i+1][j+1] = MAX(DP[i+1][j],DP[i][j+1]); } } } return DP[n][m]; } */
replace
76
77
76
77
0
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() // c int main() { int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(51)); rep(i, n) cin >> a[0][i]; rep(i, k) { vector<int> memo(n + 1); rep(j, n) { int min, max; min = j - a[i][j]; max = j + 1 + a[i][j]; if (min < 0) min = 0; if (max > n) max = n; memo[min]++; memo[max]--; } int cnt = 0; rep(j, n) { cnt += memo[j]; a[i + 1][j] = cnt; } bool fin = true; rep(j, n) { if (a[i][j] != a[i + 1][j]) fin = false; } if (fin) { k = i + 1; break; } } rep(j, n - 1) { cout << a[k][j] << " "; } cout << a[k][n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() // c int main() { int n, k; cin >> n >> k; vector<vector<int>> a(51, vector<int>(n)); rep(i, n) cin >> a[0][i]; rep(i, k) { vector<int> memo(n + 1); rep(j, n) { int min, max; min = j - a[i][j]; max = j + 1 + a[i][j]; if (min < 0) min = 0; if (max > n) max = n; memo[min]++; memo[max]--; } int cnt = 0; rep(j, n) { cnt += memo[j]; a[i + 1][j] = cnt; } bool fin = true; rep(j, n) { if (a[i][j] != a[i + 1][j]) fin = false; } if (fin) { k = i + 1; break; } } rep(j, n - 1) { cout << a[k][j] << " "; } cout << a[k][n - 1] << endl; return 0; }
replace
9
10
9
10
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; // ######################################### signed main() { int n, k; cin >> n >> k; int a[n + 1]; rep(i, n) { cin >> a[i + 1]; } vector<int> lamp(n + 100); if (k >= n * 100) { rep(i, n) cout << n << endl; return 0; } rep(j, k) { bool end = true; rep(i, n) { int l = max((i + 1) - a[i + 1], 1ll); int r = min((i + 1) + a[i + 1] + 1, n + 1); if (l != 1 || r != n) end = false; lamp[l]++; lamp[r]--; } if (end) { rep(i, n) cout << n << endl; return 0; } rep(i, n) { // trace(lamp[i],i); lamp[i + 1] += lamp[i]; a[i + 1] = lamp[i + 1]; // trace(a[i+1],i+1); } if (j != k - 1) rep(i, n + 1) lamp[i] = 0; } rep(i, n) cout << lamp[i + 1] << endl; return 0; }
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; // ######################################### signed main() { int n, k; cin >> n >> k; int a[n + 1]; rep(i, n) { cin >> a[i + 1]; } vector<int> lamp(n + 100); if (n * k >= 10000000) { rep(i, n) cout << n << endl; return 0; } rep(j, k) { bool end = true; rep(i, n) { int l = max((i + 1) - a[i + 1], 1ll); int r = min((i + 1) + a[i + 1] + 1, n + 1); if (l != 1 || r != n) end = false; lamp[l]++; lamp[r]--; } if (end) { rep(i, n) cout << n << endl; return 0; } rep(i, n) { // trace(lamp[i],i); lamp[i + 1] += lamp[i]; a[i + 1] = lamp[i + 1]; // trace(a[i+1],i+1); } if (j != k - 1) rep(i, n + 1) lamp[i] = 0; } rep(i, n) cout << lamp[i + 1] << endl; return 0; }
replace
82
83
82
83
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define DEB2(X) cout << X << " "; #define END cout << endl; #else #define DEB(X) \ {} #define DEB2(X) \ {} #define END \ {} #endif typedef long long ll; #define int ll #define uset unordered_set #define umap unordered_map // typedef std::pair<int,int> P; struct edge { int to, cost; }; const int INF = 100000000000000000; const int INF2 = 9223372036854775807; const int MOD = 1000000007; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y)) #define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y)) #define NP(X, Y) next_permutation(X, Y) #define setdouble(X, Y) cout << fixed << setprecision(X) << Y int ceil2(int a, int b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int pow2(int a, int b) { int r = 1; for (int i = 1; i <= b; i++) { r *= a; } return r; } int Log2(int a) { int t = 0; while (1) { if (a == 0 || a == 1) { break; } a /= 2; t++; } return t; } int N, K; int A[200010]; int num[200010]; int calc() { REP(i, N) { num[i] = 0; } REP(i, N) { int l = max(0, i - A[i]); int r = min(N - 1, i + A[i]); num[l]++; num[r + 1]--; } REP(i, N) { num[i + 1] += num[i]; } REP(i, N) { A[i] = num[i]; } } signed main() { cin >> N >> K; REP(i, N) { cin >> A[i]; } REP(i, min(50, K)) { calc(); } REP(i, N) { cout << A[i]; if (i < N - 1) cout << " "; } cout << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define DEB2(X) cout << X << " "; #define END cout << endl; #else #define DEB(X) \ {} #define DEB2(X) \ {} #define END \ {} #endif typedef long long ll; #define int ll #define uset unordered_set #define umap unordered_map // typedef std::pair<int,int> P; struct edge { int to, cost; }; const int INF = 100000000000000000; const int INF2 = 9223372036854775807; const int MOD = 1000000007; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y)) #define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y)) #define NP(X, Y) next_permutation(X, Y) #define setdouble(X, Y) cout << fixed << setprecision(X) << Y int ceil2(int a, int b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int pow2(int a, int b) { int r = 1; for (int i = 1; i <= b; i++) { r *= a; } return r; } int Log2(int a) { int t = 0; while (1) { if (a == 0 || a == 1) { break; } a /= 2; t++; } return t; } int N, K; int A[200010]; int num[200010]; void calc() { REP(i, N) { num[i] = 0; } REP(i, N) { int l = max(0, i - A[i]); int r = min(N - 1, i + A[i]); num[l]++; num[r + 1]--; } REP(i, N) { num[i + 1] += num[i]; } REP(i, N) { A[i] = num[i]; } } signed main() { cin >> N >> K; REP(i, N) { cin >> A[i]; } REP(i, min(50, K)) { calc(); } REP(i, N) { cout << A[i]; if (i < N - 1) cout << " "; } cout << endl; return 0; }
replace
76
77
76
77
0
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; #define INF (1e9) int main() { int N, K; cin >> N >> K; vi A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } while (K--) { vi B(N + 1); for (int i = 0; i < N; i++) { B[max(0, i - A[i])]++; B[min(N, i + A[i]) + 1]--; } int s = 0; bool f = true; for (int i = 0; i < N; i++) { s += B[i]; A[i] = s; f &= s == N; } if (f) break; } for (int i = 0; i < N; i++) { cout << A[i] << ' '; } cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; #define INF (1e9) int main() { int N, K; cin >> N >> K; vi A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } while (K--) { vi B(N + 1); for (int i = 0; i < N; i++) { B[max(0, i - A[i])]++; B[min(N, i + A[i] + 1)]--; } int s = 0; bool f = true; for (int i = 0; i < N; i++) { s += B[i]; A[i] = s; f &= s == N; } if (f) break; } for (int i = 0; i < N; i++) { cout << A[i] << ' '; } cout << endl; }
replace
19
20
19
20
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; typedef long long ll; #define N 200005 int a[N], d[N]; int check(int n) { int i; for (i = 1; i <= n; i++) { if (i != n) return 0; } return 1; } int main() { int n, k, i, l, r; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; } while (k--) { memset(d, 0, sizeof(d)); for (i = 1; i <= n; i++) { l = i - a[i]; r = i + a[i]; if (l < 1) l = 1; if (r > n) r = n; d[r + 1] -= 1; d[l] += 1; } a[1] = d[1]; for (i = 2; i <= n; i++) { d[i] += d[i - 1]; a[i] = d[i]; } if (check(n)) { for (i = 1; i <= n; i++) { cout << n << " "; } return 0; } } for (i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; typedef long long ll; #define N 200005 int a[N], d[N]; int check(int n) { int i; for (i = 1; i <= n; i++) { if (a[i] != n) return 0; } return 1; } int main() { int n, k, i, l, r; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; } while (k--) { memset(d, 0, sizeof(d)); for (i = 1; i <= n; i++) { l = i - a[i]; r = i + a[i]; if (l < 1) l = 1; if (r > n) r = n; d[r + 1] -= 1; d[l] += 1; } a[1] = d[1]; for (i = 2; i <= n; i++) { d[i] += d[i - 1]; a[i] = d[i]; } if (check(n)) { for (i = 1; i <= n; i++) { cout << n << " "; } return 0; } } for (i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }
replace
12
13
12
13
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int A[100100], B[100100]; priority_queue<int, vector<int>, greater<int>> PQ1; priority_queue<int, vector<int>, less<int>> PQ2; int main() { int N, K; cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; while (K--) { while (!PQ1.empty()) PQ1.pop(); for (int i = 0; i < N; i++) { PQ1.push(i + A[i]); while (PQ1.top() < i) PQ1.pop(); B[i] = (int)(PQ1.size()); } while (!PQ2.empty()) PQ2.pop(); for (int i = N - 1; i >= 0; i--) { PQ2.push(i - A[i]); while (PQ2.top() > i) PQ2.pop(); B[i] += (int)(PQ2.size()); B[i]--; } bool OK = true; for (int i = 0; i < N; i++) { if (B[i] != N) OK = false; A[i] = B[i]; } if (OK) break; } for (int i = 0; i < N; i++) cout << A[i] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; int A[200100], B[200100]; priority_queue<int, vector<int>, greater<int>> PQ1; priority_queue<int, vector<int>, less<int>> PQ2; int main() { int N, K; cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; while (K--) { while (!PQ1.empty()) PQ1.pop(); for (int i = 0; i < N; i++) { PQ1.push(i + A[i]); while (PQ1.top() < i) PQ1.pop(); B[i] = (int)(PQ1.size()); } while (!PQ2.empty()) PQ2.pop(); for (int i = N - 1; i >= 0; i--) { PQ2.push(i - A[i]); while (PQ2.top() > i) PQ2.pop(); B[i] += (int)(PQ2.size()); B[i]--; } bool OK = true; for (int i = 0; i < N; i++) { if (B[i] != N) OK = false; A[i] = B[i]; } if (OK) break; } for (int i = 0; i < N; i++) cout << A[i] << " "; return 0; }
replace
2
3
2
3
0
p02647
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tl3; const int BIG_NUM = 1e9; const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const int MAX = 1e5 + 5; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> b(n); for (int j = 0; j < n; j++) { int l = max(0, j - a[j]); int r = min(n - 1, i + a[i]); b[l]++; if (r + 1 < n) { b[r + 1]--; } } for (int j = 1; j < n; j++) { b[j] += b[j - 1]; } bool isEnd = true; for (int j = 0; j < n; j++) { if (a[j] != n) { isEnd = false; break; } } if (isEnd) { for (int j = 0; j < n; j++) { cout << n << " "; } cout << endl; return 0; } a = b; } for (int ai : a) { cout << ai << " "; } cout << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tl3; const int BIG_NUM = 1e9; const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const int MAX = 1e5 + 5; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { vector<int> b(n); for (int j = 0; j < n; j++) { int l = max(0, j - a[j]); int r = min(n - 1, j + a[j]); b[l]++; if (r + 1 < n) { b[r + 1]--; } } for (int j = 1; j < n; j++) { b[j] += b[j - 1]; } bool isEnd = true; for (int j = 0; j < n; j++) { if (a[j] != n) { isEnd = false; break; } } if (isEnd) { for (int j = 0; j < n; j++) { cout << n << " "; } cout << endl; return 0; } a = b; } for (int ai : a) { cout << ai << " "; } cout << endl; }
replace
39
40
39
40
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mod 1e9 + 7 int main() { int n, k; cin >> n >> k; int a[n + 1], b[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } while (k--) { memset(b, 0, sizeof(b)); for (int i = 1; i <= n; i++) { if (a[i] + i < n) { b[i]++; b[i + a[i] + 1]--; } else { b[i]++; } if (i - a[i] >= 1) { b[i - a[i]]++; b[i]--; } else { b[1]++; b[i]--; } } a[1] = b[1]; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + b[i]; } } for (int i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1e9 + 7 int main() { int n, k; cin >> n >> k; int a[n + 1], b[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } while (k--) { memset(b, 0, sizeof(b)); for (int i = 1; i <= n; i++) { if (a[i] + i < n) { b[i]++; b[i + a[i] + 1]--; } else { b[i]++; } if (i - a[i] >= 1) { b[i - a[i]]++; b[i]--; } else { b[1]++; b[i]--; } } a[1] = b[1]; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + b[i]; } int flag = 0; for (int i = 1; i <= n; i++) { if (a[i] != n) { flag++; break; } } if (!flag) { break; } } for (int i = 1; i <= n; i++) { cout << a[i] << " "; } return 0; }
insert
78
78
78
101
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, k; int a[200005], b[200005]; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < k; ++i) { memset(b, 0, sizeof(b)); for (int i = 0; i < n; ++i) { int l = max(0, i - a[i]); int r = min(n - 1, i + a[i]); b[l]++; if (r + 1 < n) { b[r + 1]--; } } for (int i = 1; i < n; ++i) { b[i] += b[i - 1]; } for (int i = 0; i < n; ++i) { a[i] = b[i]; } } for (int i = 0; i < n; ++i) { cout << a[i] << ' '; } cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[200005], b[200005]; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (k > 50) { for (int i = 0; i < n; ++i) { cout << n << ' '; } cout << '\n'; return 0; } for (int i = 0; i < k; ++i) { memset(b, 0, sizeof(b)); for (int i = 0; i < n; ++i) { int l = max(0, i - a[i]); int r = min(n - 1, i + a[i]); b[l]++; if (r + 1 < n) { b[r + 1]--; } } for (int i = 1; i < n; ++i) { b[i] += b[i - 1]; } for (int i = 0; i < n; ++i) { a[i] = b[i]; } } for (int i = 0; i < n; ++i) { cout << a[i] << ' '; } cout << '\n'; return 0; }
insert
8
8
8
15
TLE
p02647
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; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } rep(i, k) { bool end_flag = true; vector<int> s(n, 0); // a[i] = s[0] + s[1] + ... + s[i] rep(i, n) { s[max(0, i - a[i])]++; if (i + a[i] + 1 < n) s[i + a[i] + 1]--; } a[0] = s[0]; rep(i, n - 1) { a[i + 1] = a[i] + s[i + 1]; } rep(i, n) if (a[i + 1] != n) end_flag = false; if (end_flag) break; } rep(i, n) { cout << a[i] << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } rep(i, k) { bool end_flag = true; vector<int> s(n, 0); // a[i] = s[0] + s[1] + ... + s[i] rep(i, n) { s[max(0, i - a[i])]++; if (i + a[i] + 1 < n) s[i + a[i] + 1]--; } a[0] = s[0]; rep(i, n - 1) { a[i + 1] = a[i] + s[i + 1]; } rep(i, n) if (a[i] != n) end_flag = false; if (end_flag) break; } rep(i, n) { cout << a[i] << endl; } }
replace
34
35
34
35
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second int n, k; int it[200001]; int pre[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> it[i]; } for (int i = 0; i < k; i++) { for (int j = 0; j < n + 1; j++) { pre[j] = 0; } for (int j = 0; j < n; j++) { pre[max(j - it[j], 0)] += 1; pre[min(j + it[j] + 1, n)] -= 1; } int x = pre[0]; int st = 0; int su = 0; for (int j = 0; j < n; j++) { su += pre[j]; if (su + j < n - 1 or su - j > 0) { st = 1; } it[j] = su; } if (st == 0) { break; } } for (int i = 0; i < n; i++) { cout << it[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second int n, k; int it[200001]; int pre[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> it[i]; } for (int i = 0; i < k; i++) { for (int j = 0; j < n + 1; j++) { pre[j] = 0; } for (int j = 0; j < n; j++) { pre[max(j - it[j], 0)] += 1; pre[min(j + it[j] + 1, n)] -= 1; } int x = pre[0]; int st = 0; int su = 0; for (int j = 0; j < n; j++) { su += pre[j]; if (it[j] != x) { st = 1; } it[j] = su; } if (st == 0) { break; } } for (int i = 0; i < n; i++) { cout << it[i] << " "; } cout << endl; return 0; }
replace
30
31
30
31
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } }; template <typename T> struct BIT { int n; vector<T> bit[2]; BIT(int n_) { init(n_); } void init(int n_) { n = n_ + 1; for (int p = 0; p < 2; p++) bit[p].assign(n, 0); } void add_sub(int p, int i, T x) { for (int idx = i; idx < n; idx += (idx & -idx)) { bit[p][idx] += x; } } void add(int l, int r, T x) { add_sub(0, l, -x * (l - 1)); add_sub(0, r, x * (r - 1)); add_sub(1, l, x); add_sub(1, r, -x); } T sum_sub(int p, int i) { T s(0); for (int idx = i; idx > 0; idx -= (idx & -idx)) { s += bit[p][idx]; } return s; } T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; } }; struct WeightedUnionFind { vector<int> data; vector<ll> ws; WeightedUnionFind() {} WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {} int find(int k) { if (data[k] < 0) return k; auto par = find(data[k]); ws[k] += ws[data[k]]; return data[k] = par; } ll weight(int t) { find(t); return ws[t]; } bool unite(int x, int y, ll w) { w += weight(x); w -= weight(y); x = find(x), y = find(y); if (x == y) return false; if (data[x] > data[y]) { swap(x, y); w *= -1; } data[x] += data[y]; data[y] = x; ws[y] = w; return true; } ll diff(int x, int y) { return weight(y) - weight(x); } }; 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; } int main() { int n, k; cin >> n >> k; vector<int> A(n + 10); for (int i = 0; i < n; ++i) { cin >> A[i]; } for (int l = 0; l < k; ++l) { vector<int> b(n), c(n); bool done = true; for (int i = 0; i < n; ++i) { b[max(0, i - A[i])]++; c[min(n, i + A[i]) + 1]++; if (A[i] < n) done = false; } if (done) break; int x = 0; for (int i = 0; i < n; ++i) { x += b[i] - c[i]; A[i] = x; } } for (int i = 0; i < n; ++i) { cout << A[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } }; template <typename T> struct BIT { int n; vector<T> bit[2]; BIT(int n_) { init(n_); } void init(int n_) { n = n_ + 1; for (int p = 0; p < 2; p++) bit[p].assign(n, 0); } void add_sub(int p, int i, T x) { for (int idx = i; idx < n; idx += (idx & -idx)) { bit[p][idx] += x; } } void add(int l, int r, T x) { add_sub(0, l, -x * (l - 1)); add_sub(0, r, x * (r - 1)); add_sub(1, l, x); add_sub(1, r, -x); } T sum_sub(int p, int i) { T s(0); for (int idx = i; idx > 0; idx -= (idx & -idx)) { s += bit[p][idx]; } return s; } T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; } }; struct WeightedUnionFind { vector<int> data; vector<ll> ws; WeightedUnionFind() {} WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {} int find(int k) { if (data[k] < 0) return k; auto par = find(data[k]); ws[k] += ws[data[k]]; return data[k] = par; } ll weight(int t) { find(t); return ws[t]; } bool unite(int x, int y, ll w) { w += weight(x); w -= weight(y); x = find(x), y = find(y); if (x == y) return false; if (data[x] > data[y]) { swap(x, y); w *= -1; } data[x] += data[y]; data[y] = x; ws[y] = w; return true; } ll diff(int x, int y) { return weight(y) - weight(x); } }; 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; } int main() { int n, k; cin >> n >> k; vector<int> A(n + 10); for (int i = 0; i < n; ++i) { cin >> A[i]; } for (int l = 0; l < k; ++l) { vector<int> b(n + 10), c(n + 10); bool done = true; for (int i = 0; i < n; ++i) { b[max(0, i - A[i])]++; c[min(n, i + A[i]) + 1]++; if (A[i] < n) done = false; } if (done) break; int x = 0; for (int i = 0; i < n; ++i) { x += b[i] - c[i]; A[i] = x; } } for (int i = 0; i < n; ++i) { cout << A[i] << " "; } cout << endl; return 0; }
replace
193
194
193
194
0
p02647
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define LL long long const int MAXSSTN = 200010; class StarrySkyTree { public: int size = 0; int depth = 0; // the depth of the tree int best = 0; // the index of maximum element int start = 0; // the initial index of inputs long long dat_add[4 * MAXSSTN]; long long dat[4 * MAXSSTN]; StarrySkyTree(int n) { size = n; while ((1 << depth) < n) depth++; start = (1 << depth) - 1; for (int i = start; i < (1 << (depth + 1)); i++) { if (i < start + n) dat[i] = 0; else dat[i] = 1e15; } for (int i = start; i < start + n; i++) { int tmp = i; while (par(tmp) != -1) { dat[par(tmp)] = min(dat[tmp], dat[(tmp + 1) / 2 * 4 - 1 - tmp]); tmp = par(tmp); } } int i = 0; while (i < start) i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; best = i - start; } long long max_element(int a, int b) { return max_element(a, b, 0, 0, (1 << depth)); } void add(int s, int t, int x) { add(s, t, 0, 0, (1 << depth), x); } void add(int i, int x) { add(i, i + 1, 0, 0, (1 << depth), x); } int par(int i) { if (i == 0) return -1; return (i - 1) / 2; } void clear() { for (int i = start; i < (1 << (depth + 1)); i++) { if (i < start + size) dat[i] = 0; else dat[i] = 1e15; } for (int i = start; i < start + size; i++) { int tmp = i; while (par(tmp) != -1) { dat[par(tmp)] = min(dat[tmp], dat[(tmp + 1) / 2 * 4 - 1 - tmp]); tmp = par(tmp); } } int i = 0; while (i < start) i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; best = i - start; REP(i, 4 * MAXSSTN) dat_add[i] = 0; } void update(int d, long long x) { int i = d + start; dat[i] = x; while (par(i) != -1) { dat[par(i)] = min(dat[i], dat[(i + 1) / 2 * 4 - 1 - i]); i = par(i); } i = 0; while (i < start) { i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; } best = i - start; } void dump() { for (int i = 0; i < (1 << (depth + 1)); i++) { cerr << dat[i] << " "; } cerr << endl; } private: long long max_element(int a, int b, int k, int l, int r) { if (b <= l || r <= a) return 1e15; if (a <= l && r <= b) return dat[k] + dat_add[k]; long long vl = max_element(a, b, k * 2 + 1, l, (l + r) / 2); long long vr = max_element(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr) + dat_add[k]; } void add(int a, int b, int k, int l, int r, long long x) { if (b <= l || r <= a) return; if (a <= l && r <= b) { dat_add[k] += x; } else { add(a, b, k * 2 + 1, l, (l + r) / 2, x); add(a, b, k * 2 + 2, (l + r) / 2, r, x); dat[k] = min(dat[k * 2 + 1] + dat_add[k * 2 + 1], dat[k * 2 + 2] + dat_add[k * 2 + 2]); } } }; int n, k; int a[200000]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; if (k >= 41) { REP(i, n) cout << n << " "; cout << endl; return 0; } StarrySkyTree sst(n); REP(i, k) { REP(j, n) sst.update(j, 0); REP(j, n) { sst.add(max(0, j - a[j]), min(n - 1, j + a[j]) + 1, 1); } REP(j, n) { a[j] = sst.max_element(j, j + 1); } sst.clear(); } REP(i, n) cout << a[i] << " "; cout << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define LL long long const int MAXSSTN = 200010; class StarrySkyTree { public: int size = 0; int depth = 0; // the depth of the tree int best = 0; // the index of maximum element int start = 0; // the initial index of inputs long long dat_add[4 * MAXSSTN]; long long dat[4 * MAXSSTN]; StarrySkyTree(int n) { size = n; while ((1 << depth) < n) depth++; start = (1 << depth) - 1; for (int i = start; i < (1 << (depth + 1)); i++) { if (i < start + n) dat[i] = 0; else dat[i] = 1e15; } for (int i = start; i < start + n; i++) { int tmp = i; while (par(tmp) != -1) { dat[par(tmp)] = min(dat[tmp], dat[(tmp + 1) / 2 * 4 - 1 - tmp]); tmp = par(tmp); } } int i = 0; while (i < start) i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; best = i - start; } long long max_element(int a, int b) { return max_element(a, b, 0, 0, (1 << depth)); } void add(int s, int t, int x) { add(s, t, 0, 0, (1 << depth), x); } void add(int i, int x) { add(i, i + 1, 0, 0, (1 << depth), x); } int par(int i) { if (i == 0) return -1; return (i - 1) / 2; } void clear() { for (int i = start; i < (1 << (depth + 1)); i++) { if (i < start + size) dat[i] = 0; else dat[i] = 1e15; } for (int i = start; i < start + size; i++) { int tmp = i; while (par(tmp) != -1) { dat[par(tmp)] = min(dat[tmp], dat[(tmp + 1) / 2 * 4 - 1 - tmp]); tmp = par(tmp); } } int i = 0; while (i < start) i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; best = i - start; REP(i, 4 * MAXSSTN) dat_add[i] = 0; } void update(int d, long long x) { int i = d + start; dat[i] = x; while (par(i) != -1) { dat[par(i)] = min(dat[i], dat[(i + 1) / 2 * 4 - 1 - i]); i = par(i); } i = 0; while (i < start) { i = (dat[i] == dat[2 * i + 1]) ? 2 * i + 1 : 2 * i + 2; } best = i - start; } void dump() { for (int i = 0; i < (1 << (depth + 1)); i++) { cerr << dat[i] << " "; } cerr << endl; } private: long long max_element(int a, int b, int k, int l, int r) { if (b <= l || r <= a) return 1e15; if (a <= l && r <= b) return dat[k] + dat_add[k]; long long vl = max_element(a, b, k * 2 + 1, l, (l + r) / 2); long long vr = max_element(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr) + dat_add[k]; } void add(int a, int b, int k, int l, int r, long long x) { if (b <= l || r <= a) return; if (a <= l && r <= b) { dat_add[k] += x; } else { add(a, b, k * 2 + 1, l, (l + r) / 2, x); add(a, b, k * 2 + 2, (l + r) / 2, r, x); dat[k] = min(dat[k * 2 + 1] + dat_add[k * 2 + 1], dat[k * 2 + 2] + dat_add[k * 2 + 2]); } } }; int n, k; int a[200000]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; if (k >= 41) { REP(i, n) cout << n << " "; cout << endl; return 0; } StarrySkyTree sst(n); REP(i, k) { REP(j, n) sst.update(j, 0); REP(j, n) { sst.add(max(0, j - a[j]), min(n - 1, j + a[j]) + 1, 1); } REP(j, n) { if (a[j] != n || !i) a[j] = sst.max_element(j, j + 1); } sst.clear(); } REP(i, n) cout << a[i] << " "; cout << endl; return 0; }
replace
135
136
135
139
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++) #define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++) #define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--) #define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--) #define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--) #define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--) #define iter(i, it) for (auto &(i) : (it)) template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; rep(k, K) { vector<ll> B(N + 1); rep(i, N) { B[max(0LL, i - A[i])]++; B[min(N, i + A[i]) + 1]--; } rep(i, N) B[i + 1] += B[i]; B.pop_back(); if (A == B) break; A = B; } iter(i, A) cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++) #define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++) #define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--) #define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--) #define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--) #define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--) #define iter(i, it) for (auto &(i) : (it)) template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; rep(k, K) { vector<ll> B(N + 1); rep(i, N) { B[max(0LL, i - A[i])]++; B[min(N, i + A[i] + 1)]--; } rep(i, N) B[i + 1] += B[i]; B.pop_back(); if (A == B) break; A = B; } iter(i, A) cout << i << endl; return 0; }
replace
55
56
55
56
0
p02647
C++
Time Limit Exceeded
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; #define int ll #define double ld #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 repR(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rep1R(i, n) for (int i = (int)(n); i >= 1; i--) #define loop(i, a, B) for (int i = a; i B; i++) #define loopR(i, a, B) for (int i = a; i B; i--) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define mp make_pair #define fst first #define snd second template <class Int> auto constexpr inf = numeric_limits<Int>::max() / 2 - 1; auto constexpr INF32 = inf<int32_t>; auto constexpr INF64 = inf<int64_t>; auto constexpr INF = inf<int>; #ifdef LOCAL #include "debug.hpp" #define dump(...) \ cerr << "[" << setw(3) << __LINE__ << ":" << __FUNCTION__ << "] ", \ dump_impl(#__VA_ARGS__, __VA_ARGS__) #define say(x) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << x << endl #define debug if (1) #else #define dump(...) (void)(0) #define say(x) (void)(0) #define debug if (0) #endif template <class T> using pque_max = priority_queue<T>; template <class T> using pque_min = priority_queue<T, vector<T>, greater<T>>; template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> ostream &operator<<(ostream &os, T const &v) { bool f = true; for (auto const &x : v) os << (f ? "" : " ") << x, f = false; return os; } template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> istream &operator>>(istream &is, T &v) { for (auto &x : v) is >> x; return is; } template <class T, class S> ostream &operator<<(ostream &os, pair<T, S> const &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) { return is >> p.first >> p.second; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; template <class F> struct FixPoint : private F { constexpr FixPoint(F &&f) : F(forward<F>(f)) {} template <class... T> constexpr auto operator()(T &&...x) const { return F::operator()(*this, forward<T>(x)...); } }; struct MakeFixPoint { template <class F> constexpr auto operator|(F &&f) const { return FixPoint<F>(forward<F>(f)); } }; #define MFP MakeFixPoint() | #define def(name, ...) auto name = MFP[&](auto &&name, __VA_ARGS__) template <class T, size_t d> struct vec_impl { using type = vector<typename vec_impl<T, d - 1>::type>; template <class... U> static type make_v(size_t n, U &&...x) { return type(n, vec_impl<T, d - 1>::make_v(forward<U>(x)...)); } }; template <class T> struct vec_impl<T, 0> { using type = T; static type make_v(T const &x = {}) { return x; } }; template <class T, size_t d = 1> using vec = typename vec_impl<T, d>::type; template <class T, size_t d = 1, class... Args> auto make_v(Args &&...args) { return vec_impl<T, d>::make_v(forward<Args>(args)...); } template <class T> void quit(T const &x) { cout << x << endl; exit(0); } template <class T, class U> constexpr bool chmin(T &x, U const &y) { if (x > y) { x = y; return true; } return false; } template <class T, class U> constexpr bool chmax(T &x, U const &y) { if (x < y) { x = y; return true; } return false; } template <class It> constexpr auto sumof(It b, It e) { return accumulate(b, e, typename iterator_traits<It>::value_type{}); } template <class T> int sz(T const &x) { return x.size(); } template <class C, class T> int lbd(C const &v, T const &x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <class C, class T> int ubd(C const &v, T const &x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); } template <class C, class F> int ppt(C const &v, F f) { return partition_point(v.begin(), v.end(), f) - v.begin(); } // <<< int32_t main() { int n, k; cin >> n >> k; vector<int> a(n); cin >> a; rep(_, k) { vector<int> b(n + 1); rep(i, n) { int l = max(0LL, i - a[i]); int r = min(n, i + a[i] + 1); b[l]++; b[r]--; } rep(i, n) b[i + 1] += b[i]; b.pop_back(); swap(a, b); } cout << a << endl; }
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; #define int ll #define double ld #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 repR(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rep1R(i, n) for (int i = (int)(n); i >= 1; i--) #define loop(i, a, B) for (int i = a; i B; i++) #define loopR(i, a, B) for (int i = a; i B; i--) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define mp make_pair #define fst first #define snd second template <class Int> auto constexpr inf = numeric_limits<Int>::max() / 2 - 1; auto constexpr INF32 = inf<int32_t>; auto constexpr INF64 = inf<int64_t>; auto constexpr INF = inf<int>; #ifdef LOCAL #include "debug.hpp" #define dump(...) \ cerr << "[" << setw(3) << __LINE__ << ":" << __FUNCTION__ << "] ", \ dump_impl(#__VA_ARGS__, __VA_ARGS__) #define say(x) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << x << endl #define debug if (1) #else #define dump(...) (void)(0) #define say(x) (void)(0) #define debug if (0) #endif template <class T> using pque_max = priority_queue<T>; template <class T> using pque_min = priority_queue<T, vector<T>, greater<T>>; template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> ostream &operator<<(ostream &os, T const &v) { bool f = true; for (auto const &x : v) os << (f ? "" : " ") << x, f = false; return os; } template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> istream &operator>>(istream &is, T &v) { for (auto &x : v) is >> x; return is; } template <class T, class S> ostream &operator<<(ostream &os, pair<T, S> const &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) { return is >> p.first >> p.second; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; template <class F> struct FixPoint : private F { constexpr FixPoint(F &&f) : F(forward<F>(f)) {} template <class... T> constexpr auto operator()(T &&...x) const { return F::operator()(*this, forward<T>(x)...); } }; struct MakeFixPoint { template <class F> constexpr auto operator|(F &&f) const { return FixPoint<F>(forward<F>(f)); } }; #define MFP MakeFixPoint() | #define def(name, ...) auto name = MFP[&](auto &&name, __VA_ARGS__) template <class T, size_t d> struct vec_impl { using type = vector<typename vec_impl<T, d - 1>::type>; template <class... U> static type make_v(size_t n, U &&...x) { return type(n, vec_impl<T, d - 1>::make_v(forward<U>(x)...)); } }; template <class T> struct vec_impl<T, 0> { using type = T; static type make_v(T const &x = {}) { return x; } }; template <class T, size_t d = 1> using vec = typename vec_impl<T, d>::type; template <class T, size_t d = 1, class... Args> auto make_v(Args &&...args) { return vec_impl<T, d>::make_v(forward<Args>(args)...); } template <class T> void quit(T const &x) { cout << x << endl; exit(0); } template <class T, class U> constexpr bool chmin(T &x, U const &y) { if (x > y) { x = y; return true; } return false; } template <class T, class U> constexpr bool chmax(T &x, U const &y) { if (x < y) { x = y; return true; } return false; } template <class It> constexpr auto sumof(It b, It e) { return accumulate(b, e, typename iterator_traits<It>::value_type{}); } template <class T> int sz(T const &x) { return x.size(); } template <class C, class T> int lbd(C const &v, T const &x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <class C, class T> int ubd(C const &v, T const &x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); } template <class C, class F> int ppt(C const &v, F f) { return partition_point(v.begin(), v.end(), f) - v.begin(); } // <<< int32_t main() { int n, k; cin >> n >> k; vector<int> a(n); cin >> a; rep(_, k) { vector<int> b(n + 1); rep(i, n) { int l = max(0LL, i - a[i]); int r = min(n, i + a[i] + 1); b[l]++; b[r]--; } rep(i, n) b[i + 1] += b[i]; b.pop_back(); swap(a, b); if (count(all(a), n) == n) break; } cout << a << endl; }
insert
149
149
149
152
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(x) ((int)x.size()) #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9 + 7; const ll INF = 2e18; template <class T> void print(const T &t) { cout << t << endl; } 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; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ll n, k; cin >> n >> k; vl a(n + 2); a[0] = 0; for (ll i = 1; i <= n; i++) { cin >> a[i]; } vl dp(n + 1, 0); rep(i, k) { for (ll j = 1; j <= n; j++) { ll in = j - a[j]; if (in <= 0) in = 1; ll out = j + a[j] + 1; if (out > n) out = n + 1; dp[in]++; dp[out]--; } ll count = 0; for (ll j = 1; j <= n; j++) { count += dp[j]; a[j] = count; dp[j] = 0; } } for (ll i = 1; i <= n; i++) { cout << a[i] << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(x) ((int)x.size()) #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9 + 7; const ll INF = 2e18; template <class T> void print(const T &t) { cout << t << endl; } 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; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ll n, k; cin >> n >> k; vl a(n + 2); a[0] = 0; for (ll i = 1; i <= n; i++) { cin >> a[i]; } if (k >= 10000) { for (ll i = 1; i <= n; i++) { cout << n << " "; } cout << endl; return 0; } vl dp(n + 1, 0); rep(i, k) { for (ll j = 1; j <= n; j++) { ll in = j - a[j]; if (in <= 0) in = 1; ll out = j + a[j] + 1; if (out > n) out = n + 1; dp[in]++; dp[out]--; } ll count = 0; for (ll j = 1; j <= n; j++) { count += dp[j]; a[j] = count; dp[j] = 0; } } for (ll i = 1; i <= n; i++) { cout << a[i] << " "; } cout << endl; }
insert
42
42
42
49
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using lint = long long int; long long int INF = 1001001001001001LL; int inf = 1000000007; long long int MOD = 1000000007LL; double PI = 3.1415926535897932; template <typename T1, typename T2> inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; } #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() /* do your best */ // quoted from beet-aizu template <typename T, typename E, typename F, typename G, typename H> struct LazySegmentTree { // using F = function<T(T,T)>; // using G = function<T(T,E)>; // using H = function<E(E,E)>; int n, height; F f; G g; H h; T ti; E ei; vector<T> dat; vector<E> laz; LazySegmentTree(F f, G g, H h, T ti, E ei) : f(f), g(g), h(h), ti(ti), ei(ei) {} void init(int n_) { n = 1; height = 0; while (n < n_) n <<= 1, height++; dat.assign(2 * n, ti); laz.assign(2 * n, ei); } void build(const vector<T> &v) { int n_ = v.size(); init(n_); for (int i = 0; i < n_; i++) dat[n + i] = v[i]; for (int i = n - 1; i; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } inline T reflect(int k) { return laz[k] == ei ? dat[k] : g(dat[k], laz[k]); } inline void eval(int k) { if (laz[k] == ei) return; laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]); laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]); dat[k] = reflect(k); laz[k] = ei; } inline void thrust(int k) { for (int i = height; i; i--) eval(k >> i); } inline void recalc(int k) { while (k >>= 1) dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1)); } void update(int a, int b, E x) { thrust(a += n); thrust(b += n - 1); for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) laz[l] = h(laz[l], x), l++; if (r & 1) --r, laz[r] = h(laz[r], x); } recalc(a); recalc(b); } void set_val(int a, T x) { thrust(a += n); dat[a] = x; laz[a] = ei; recalc(a); } T query(int a, int b) { thrust(a += n); thrust(b += n - 1); T vl = ti, vr = ti; for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, reflect(l++)); if (r & 1) vr = f(reflect(--r), vr); } return f(vl, vr); } }; /* * [考えるべきこと] * 区間をマージしてから作用素を作用させても、作用素を作用させてから区間をマージするのと結果が同じ * 複数の作用素をマージして一度に作用させられること * 作用素を伝搬し終わっているのかの判定に必要(まあこれは満たされていなくても最悪どうにかなる) * O(N) とかだと困る(setのマージとか) * 区間の長さに比例して作用が変わるときは,practice/RSRA や Library-Checher * の RangeAffineRangeSum を参照する * */ int main() { int n, k; cin >> n >> k; vector<lint> a(n + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0; j < k; j++) { bool end = true; for (int i = 1; i <= n; i++) { if (a[i] != n) end = false; } if (end) break; vector<int> acc(n + 1, 0); for (int i = 0; i < n; i++) { int l = i - a[i]; l = max(l, 0); int r = i + a[i]; r = min(r, n - 1); acc[l]++; acc[r + 1]--; } for (int i = 1; i <= n; i++) { acc[i] += acc[i - 1]; } for (int i = 0; i < n; i++) { a[i] = acc[i]; } } for (int i = 0; i < n; i++) { if (i == n - 1) { cout << a[i] << endl; } else { cout << a[i] << " "; } } }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using lint = long long int; long long int INF = 1001001001001001LL; int inf = 1000000007; long long int MOD = 1000000007LL; double PI = 3.1415926535897932; template <typename T1, typename T2> inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; } #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() /* do your best */ // quoted from beet-aizu template <typename T, typename E, typename F, typename G, typename H> struct LazySegmentTree { // using F = function<T(T,T)>; // using G = function<T(T,E)>; // using H = function<E(E,E)>; int n, height; F f; G g; H h; T ti; E ei; vector<T> dat; vector<E> laz; LazySegmentTree(F f, G g, H h, T ti, E ei) : f(f), g(g), h(h), ti(ti), ei(ei) {} void init(int n_) { n = 1; height = 0; while (n < n_) n <<= 1, height++; dat.assign(2 * n, ti); laz.assign(2 * n, ei); } void build(const vector<T> &v) { int n_ = v.size(); init(n_); for (int i = 0; i < n_; i++) dat[n + i] = v[i]; for (int i = n - 1; i; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } inline T reflect(int k) { return laz[k] == ei ? dat[k] : g(dat[k], laz[k]); } inline void eval(int k) { if (laz[k] == ei) return; laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]); laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]); dat[k] = reflect(k); laz[k] = ei; } inline void thrust(int k) { for (int i = height; i; i--) eval(k >> i); } inline void recalc(int k) { while (k >>= 1) dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1)); } void update(int a, int b, E x) { thrust(a += n); thrust(b += n - 1); for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) laz[l] = h(laz[l], x), l++; if (r & 1) --r, laz[r] = h(laz[r], x); } recalc(a); recalc(b); } void set_val(int a, T x) { thrust(a += n); dat[a] = x; laz[a] = ei; recalc(a); } T query(int a, int b) { thrust(a += n); thrust(b += n - 1); T vl = ti, vr = ti; for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, reflect(l++)); if (r & 1) vr = f(reflect(--r), vr); } return f(vl, vr); } }; /* * [考えるべきこと] * 区間をマージしてから作用素を作用させても、作用素を作用させてから区間をマージするのと結果が同じ * 複数の作用素をマージして一度に作用させられること * 作用素を伝搬し終わっているのかの判定に必要(まあこれは満たされていなくても最悪どうにかなる) * O(N) とかだと困る(setのマージとか) * 区間の長さに比例して作用が変わるときは,practice/RSRA や Library-Checher * の RangeAffineRangeSum を参照する * */ int main() { int n, k; cin >> n >> k; vector<lint> a(n + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0; j < k; j++) { bool end = true; for (int i = 0; i < n; i++) { if (a[i] != n) end = false; } if (end) break; vector<int> acc(n + 1, 0); for (int i = 0; i < n; i++) { int l = i - a[i]; l = max(l, 0); int r = i + a[i]; r = min(r, n - 1); acc[l]++; acc[r + 1]--; } for (int i = 1; i <= n; i++) { acc[i] += acc[i - 1]; } for (int i = 0; i < n; i++) { a[i] = acc[i]; } } for (int i = 0; i < n; i++) { if (i == n - 1) { cout << a[i] << endl; } else { cout << a[i] << " "; } } }
replace
147
148
147
148
TLE
p02647
C++
Time Limit Exceeded
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author NikuKyabe */ #include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) FOR(i, 0, (n)) typedef vector<int> vec; class CLamps { public: void solve(std::istream &in, std::ostream &out) { int n, k; in >> n >> k; vector<int> a(n); REP(i, n) in >> a[i]; vector<pair<double, double>> b(n); REP(j, k) { REP(i, n) { b[i] = make_pair(max(i - a[i], 0ll), min(i + a[i] + 1, n)); } vec c(n + 1, 0); REP(i, n) { c[b[i].first]++; c[b[i].second]--; } FOR(i, 1, c.size()) { c[i] += c[i - 1]; a[i - 1] = c[i - 1]; } } REP(i, n) { out << a[i] << " "; } out << endl; } }; signed main() { ios::sync_with_stdio(false); cout.tie(0); cout << fixed; CLamps solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author NikuKyabe */ #include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) FOR(i, 0, (n)) typedef vector<int> vec; class CLamps { public: void solve(std::istream &in, std::ostream &out) { int n, k; in >> n >> k; vector<int> a(n); REP(i, n) in >> a[i]; vector<pair<double, double>> b(n); REP(j, min(k, 100ll)) { REP(i, n) { b[i] = make_pair(max(i - a[i], 0ll), min(i + a[i] + 1, n)); } vec c(n + 1, 0); REP(i, n) { c[b[i].first]++; c[b[i].second]--; } FOR(i, 1, c.size()) { c[i] += c[i - 1]; a[i - 1] = c[i - 1]; } } REP(i, n) { out << a[i] << " "; } out << endl; } }; signed main() { ios::sync_with_stdio(false); cout.tie(0); cout << fixed; CLamps solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
replace
22
23
22
23
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, N) for (int(i) = 0; (i) < (N); (i)++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int mod = 1000000007; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(i, k) { vector<int> sum(n + 1); rep(i, n) { int low = max(0, i - a[i]); int high = min(n + 1, i + a[i] + 1); sum[low]++; sum[high]--; } int cur = 0; bool ok = true; rep(i, n) { cur += sum[i]; a[i] = cur; if (cur != n) ok = false; } if (ok) break; } rep(i, n) printf("%d%c", a[i], (i == n - 1) ? '\n' : ' '); }
#include <bits/stdc++.h> #define rep(i, N) for (int(i) = 0; (i) < (N); (i)++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int mod = 1000000007; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(i, k) { vector<int> sum(n + 1); rep(i, n) { int low = max(0, i - a[i]); int high = min(n, i + a[i] + 1); sum[low]++; sum[high]--; } int cur = 0; bool ok = true; rep(i, n) { cur += sum[i]; a[i] = cur; if (cur != n) ok = false; } if (ok) break; } rep(i, n) printf("%d%c", a[i], (i == n - 1) ? '\n' : ' '); }
replace
19
20
19
20
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL 9223372036854775 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define MOD 1000000007 #define MOD9 998244353 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double #define int long long using II = pair<int, int>; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; } #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin((a)), end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) const int MAX_N = 200005; int N, K; int A[2][MAX_N]; signed main() { cin >> N >> K; REP(n, N) { cin >> A[0][n]; } int now, next; REP(k, min((LL)50, K)) { now = k % 2; next = (k + 1) % 2; REP(n, N) { memset(A[next], 0, sizeof(A[next])); } REP(n, N) { int l = max((LL)0, n - A[now][n]); int r = min((LL)N, n + A[now][n] + 1); A[next][l]++; A[next][r]--; } REP(n, N) { A[next][n + 1] += A[next][n]; } } REP(n, N) { if (0 < n) { cout << " "; } cout << A[next][n]; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL 9223372036854775 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define MOD 1000000007 #define MOD9 998244353 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double #define int long long using II = pair<int, int>; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; } #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin((a)), end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) const int MAX_N = 200005; int N, K; int A[2][MAX_N]; signed main() { cin >> N >> K; REP(n, N) { cin >> A[0][n]; } int now, next; REP(k, min((LL)50, K)) { now = k % 2; next = (k + 1) % 2; memset(A[next], 0, sizeof(A[next])); REP(n, N) { int l = max((LL)0, n - A[now][n]); int r = min((LL)N, n + A[now][n] + 1); A[next][l]++; A[next][r]--; } REP(n, N) { A[next][n + 1] += A[next][n]; } } REP(n, N) { if (0 < n) { cout << " "; } cout << A[next][n]; } cout << endl; return 0; }
replace
53
54
53
56
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { int n, k; cin >> n >> k; vector<int> v(n); rep(i, n) cin >> v[i]; vector<int> imo(n + 1); /*いもす法*/ rep(j, min(k, (int)log2(n) + 100)) { imo = vector<int>(n + 1); rep(i, n) { imo[max(0, i - v[i])]++; imo[i + min(v[i] + 1, n)]--; } int bef = 0; rep(i, n) { bef += imo[i]; v[i] = bef; } } rep(i, n) cout << v[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { int n, k; cin >> n >> k; vector<int> v(n); rep(i, n) cin >> v[i]; vector<int> imo(n + 1); /*いもす法*/ rep(j, min(k, (int)log2(n) + 100)) { imo = vector<int>(n + 1); rep(i, n) { imo[max(0, i - v[i])]++; imo[min(i + (v[i] + 1), n)]--; } int bef = 0; rep(i, n) { bef += imo[i]; v[i] = bef; } } rep(i, n) cout << v[i] << " "; cout << endl; return 0; }
replace
16
17
16
17
0
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<ll> #define rep(i, n) for (ll i = 0; i < (n); ++i) int main() { ll N, K; cin >> N >> K; vl A(N); rep(i, N) cin >> A[i]; ll n = 0; while (n < K) { vl B(N + 1, 0); rep(i, N) { if (i - A[i] <= 0) B[0]++; else B[i - A[i]]++; if (i + A[i] > N) B[N]--; else B[i + A[i] + 1]--; } vl C(N, 0); bool ok = true; rep(i, N) { if (i > 0) C[i] = C[i - 1]; C[i] += B[i]; if (C[i] < N) ok = false; } if (ok) { rep(i, N) { cout << N << " "; } cout << endl; return 0; } n++; A = C; } rep(i, N) { cout << A[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<ll> #define rep(i, n) for (ll i = 0; i < (n); ++i) int main() { ll N, K; cin >> N >> K; vl A(N); rep(i, N) cin >> A[i]; ll n = 0; while (n < K) { vl B(N + 1, 0); rep(i, N) { if (i - A[i] <= 0) B[0]++; else B[i - A[i]]++; if (i + A[i] + 1 >= N) B[N]--; else B[i + A[i] + 1]--; } vl C(N, 0); bool ok = true; rep(i, N) { if (i > 0) C[i] = C[i - 1]; C[i] += B[i]; if (C[i] < N) ok = false; } if (ok) { rep(i, N) { cout << N << " "; } cout << endl; return 0; } n++; A = C; } rep(i, N) { cout << A[i] << " "; } cout << endl; return 0; }
replace
21
22
21
22
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) (x).begin(), (x).end() const long long MOD = 1e9 + 7; // const long long MOD=998244353; const int INF = 1e9; const long long IINF = 1e18; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const char dir[4] = {'D', 'R', 'U', 'L'}; #define LOCAL template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { cout << '(' << p.first << ',' << p.second << ')'; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << '{'; for (auto itr = m.begin(); itr != m.end(); ++itr) { os << '(' << itr->first << ',' << itr->second << ')'; if (++itr != m.end()) os << ','; --itr; } os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { os << '{'; for (auto itr = s.begin(); itr != s.end(); ++itr) { os << *itr; if (++itr != s.end()) os << ','; --itr; } os << '}'; return os; } void debug_out() { cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head &&head, Tail &&...tail) { cerr << head; if (sizeof...(Tail) > 0) cerr << ", "; debug_out(move(tail)...); } #ifdef LOCAL #define debug(...) \ cerr << " "; \ cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << '\n'; \ cerr << " "; \ debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; } template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; } template <class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> A(N); cin >> A; vector<int> ans(N), imos(N); for (int i = 0; i < N; ++i) ans[i] = A[i]; for (int i = 0; i < K; ++i) { for (int j = 0; j < N; ++j) imos[j] = 0; for (int j = 0; j < N; ++j) { ++imos[max(0, j - ans[j])]; if (j + ans[j] + 1 < N) --imos[j + ans[j] + 1]; } for (int j = 0; j < N - 1; ++j) imos[j + 1] += imos[j]; int check = 0; for (int j = 0; j < N; ++j) { ans[j] = imos[j]; if (ans[j] != N) check = 0; } if (check) break; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) (x).begin(), (x).end() const long long MOD = 1e9 + 7; // const long long MOD=998244353; const int INF = 1e9; const long long IINF = 1e18; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const char dir[4] = {'D', 'R', 'U', 'L'}; #define LOCAL template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { cout << '(' << p.first << ',' << p.second << ')'; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << '{'; for (auto itr = m.begin(); itr != m.end(); ++itr) { os << '(' << itr->first << ',' << itr->second << ')'; if (++itr != m.end()) os << ','; --itr; } os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &s) { os << '{'; for (auto itr = s.begin(); itr != s.end(); ++itr) { os << *itr; if (++itr != s.end()) os << ','; --itr; } os << '}'; return os; } void debug_out() { cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head &&head, Tail &&...tail) { cerr << head; if (sizeof...(Tail) > 0) cerr << ", "; debug_out(move(tail)...); } #ifdef LOCAL #define debug(...) \ cerr << " "; \ cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << '\n'; \ cerr << " "; \ debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; } template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; } template <class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> A(N); cin >> A; vector<int> ans(N), imos(N); for (int i = 0; i < N; ++i) ans[i] = A[i]; for (int i = 0; i < K; ++i) { for (int j = 0; j < N; ++j) imos[j] = 0; for (int j = 0; j < N; ++j) { ++imos[max(0, j - ans[j])]; if (j + ans[j] + 1 < N) --imos[j + ans[j] + 1]; } for (int j = 0; j < N - 1; ++j) imos[j + 1] += imos[j]; int check = 1; for (int j = 0; j < N; ++j) { ans[j] = imos[j]; if (ans[j] != N) check = 0; } if (check) break; } cout << ans << '\n'; }
replace
111
112
111
112
TLE
p02647
C++
Runtime Error
// #include <tourist> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; 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; } // cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //-std=gnu++17 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; } int n, k; vector<int> a; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; rep(i, min(k, 100)) { vector<int> count(n + 1, 0); rep(j, n) { if (j - a[j] < 0) count[0]++; else count[j - a[j]]++; if (j + a[i] + 1 > n) count[n]--; else count[j + a[j] + 1]--; } int sum = 0; rep(j, n) { sum += count[j]; a[j] = sum; } } rep(i, n) cout << a[i] << " "; cout << "\n"; }
// #include <tourist> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; 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; } // cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //-std=gnu++17 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; } int n, k; vector<int> a; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; rep(i, min(k, 100)) { vector<int> count(n + 1, 0); rep(j, n) { if (j - a[j] < 0) count[0]++; else count[j - a[j]]++; if (j + a[j] + 1 > n) count[n]--; else count[j + a[j] + 1]--; } int sum = 0; rep(j, n) { sum += count[j]; a[j] = sum; } } rep(i, n) cout << a[i] << " "; cout << "\n"; }
replace
58
59
58
59
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(X, N) for (ll X = 0LL; X < (N); X++) #define PI (acos(-1.0)) #define MODN 1000000007 #define MODN2 998244353 #define ALL(V) (V).begin(), (V).end() #define INT_MAX_HALF (INT_MAX / 2) #define EPS (1e-10) using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<int> light(n + 2); rep(i, n) { cin >> light[i + 1]; } // imos法をつかう vector<int> count(n + 2); for (int j = 0; j < k; j++) { for (int i = 1; i <= n; i++) { if (i - light[i] < 1) { count[0]++; } else { count[i - light[i]]++; } if (i + light[i] + 1 > n) { count[n + 1]--; } else { count[i + light[i] + 1]--; } } ll sum = 0; for (int i = 1; i <= n + 1; i++) { count[i] = count[i] + count[i - 1]; light[i] = count[i]; if (i != n) sum += count[i]; } if (sum == n * n) break; rep(i, n + 2) { count[i] = 0; } } for (int i = 1; i <= n; i++) { cout << light[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> #define rep(X, N) for (ll X = 0LL; X < (N); X++) #define PI (acos(-1.0)) #define MODN 1000000007 #define MODN2 998244353 #define ALL(V) (V).begin(), (V).end() #define INT_MAX_HALF (INT_MAX / 2) #define EPS (1e-10) using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<int> light(n + 2); rep(i, n) { cin >> light[i + 1]; } // imos法をつかう vector<int> count(n + 2); for (int j = 0; j < k; j++) { for (int i = 1; i <= n; i++) { if (i - light[i] < 1) { count[0]++; } else { count[i - light[i]]++; } if (i + light[i] + 1 > n) { count[n + 1]--; } else { count[i + light[i] + 1]--; } } ll sum = 0; for (int i = 1; i <= n + 1; i++) { count[i] = count[i] + count[i - 1]; light[i] = count[i]; if (i != n + 1) sum += count[i]; } if (sum == n * n) break; rep(i, n + 2) { count[i] = 0; } } for (int i = 1; i <= n; i++) { cout << light[i] << " "; } cout << endl; return 0; }
replace
48
49
48
49
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> a(n, 0); vector<pair<int, int>> x(n); for (int i = 0; i < n; ++i) { cin >> a[i]; int left = i - a[i]; int right = i + a[i]; if (left < 0) left = 0; if (right > n - 1) right = n - 1; x[i] = make_pair(left, right); } // sort(x.begin(),x.end()); vector<int> ans(n + 1, 0); for (int i = 0; i < n; ++i) { ans[x[i].first]++; ans[x[i].second + 1]--; } for (int i = 0; i < n; ++i) { ans[i + 1] += ans[i]; } k--; bool ok = false; vector<int> tmp(n + 1, 0); for (int i = 0; i < k; ++i) { for (int j = 0; j < n; ++j) { if (ok) break; int left = j - ans[j]; int right = j + ans[j]; if (left < 0) left = 0; if (right > n - 1) right = n - 1; tmp[left]++; tmp[right + 1]--; } for (int m = 0; m < n; ++m) { tmp[m + 1] += tmp[m]; ans[m + 1] = tmp[m + 1]; } ans[0] = tmp[0]; for (int l = 0; l < n; ++l) { if (ans[l] >= n) { ans[l] = n; ok = true; } else { ok = false; break; } } } for (int i = 0; i < n; ++i) { if (ans[i] > n) ans[i] = n; if (i != n - 1) { cout << ans[i] << " "; } else { cout << ans[i] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> a(n, 0); vector<pair<int, int>> x(n); for (int i = 0; i < n; ++i) { cin >> a[i]; int left = i - a[i]; int right = i + a[i]; if (left < 0) left = 0; if (right > n - 1) right = n - 1; x[i] = make_pair(left, right); } // sort(x.begin(),x.end()); vector<int> ans(n + 1, 0); for (int i = 0; i < n; ++i) { ans[x[i].first]++; ans[x[i].second + 1]--; } for (int i = 0; i < n; ++i) { ans[i + 1] += ans[i]; } k--; bool ok = false; vector<int> tmp(n + 1, 0); for (int i = 0; i < k; ++i) { if (ok) break; tmp = vector<int>(n + 1, 0); for (int j = 0; j < n; ++j) { if (ok) break; int left = j - ans[j]; int right = j + ans[j]; if (left < 0) left = 0; if (right > n - 1) right = n - 1; tmp[left]++; tmp[right + 1]--; } for (int m = 0; m < n; ++m) { tmp[m + 1] += tmp[m]; ans[m + 1] = tmp[m + 1]; } ans[0] = tmp[0]; for (int l = 0; l < n; ++l) { if (ans[l] >= n) { ans[l] = n; ok = true; } else { ok = false; break; } } } for (int i = 0; i < n; ++i) { if (ans[i] > n) ans[i] = n; if (i != n - 1) { cout << ans[i] << " "; } else { cout << ans[i] << endl; } } return 0; }
insert
32
32
32
35
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> //////////////////////////////////////////////// #define REP(i, n) for (int i = 0; i < (int)n; i++) #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++) #define REPe(e, mp) for (auto &e : mp) #define all(x) x.begin(), x.end() #define MOD 1000000007 // 1e9+7 using namespace std; using ll = long long int; using vecint = vector<int>; using vecll = vector<ll>; using vec2int = vector<vector<int>>; using P = pair<int, int>; //////////////////////////////////////////////// //////////////////////////////////////////////// int main() { //////////////////////////////////////////////// cin.tie(nullptr); ios_base::sync_with_stdio(false); //////////////////////////////////////////////// int n, k; cin >> n >> k; vecint a(n, 0); REPe(e, a) cin >> e; if (n <= k) { REP(i, n) cout << n << " "; cout << endl; return 0; } vecint b(n, 0); REP(j, k) { REP(i, n) b[i] = 0; REP(i, n) { int l = max(0, i - a[i]); int r = i + a[i] + 1; b[l]++; if (r < n) b[r]--; } a[0] = b[0]; for (int i = 1; i < n; i++) a[i] = a[i - 1] + b[i]; } REPe(e, a) cout << e << " "; cout << endl; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> //////////////////////////////////////////////// #define REP(i, n) for (int i = 0; i < (int)n; i++) #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++) #define REPe(e, mp) for (auto &e : mp) #define all(x) x.begin(), x.end() #define MOD 1000000007 // 1e9+7 using namespace std; using ll = long long int; using vecint = vector<int>; using vecll = vector<ll>; using vec2int = vector<vector<int>>; using P = pair<int, int>; //////////////////////////////////////////////// //////////////////////////////////////////////// int main() { //////////////////////////////////////////////// cin.tie(nullptr); ios_base::sync_with_stdio(false); //////////////////////////////////////////////// int n, k; cin >> n >> k; vecint a(n, 0); REPe(e, a) cin >> e; if (n < 2 * k) { REP(i, n) cout << n << " "; cout << endl; return 0; } vecint b(n, 0); REP(j, k) { REP(i, n) b[i] = 0; REP(i, n) { int l = max(0, i - a[i]); int r = i + a[i] + 1; b[l]++; if (r < n) b[r]--; } a[0] = b[0]; for (int i = 1; i < n; i++) a[i] = a[i - 1] + b[i]; } REPe(e, a) cout << e << " "; cout << endl; }
replace
44
45
44
45
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; int a[200005] = {0}, b[200005] = {0}; int main() { int n, k, l, r, cnt = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } for (int i = 1; i <= k; i++) { cnt = 0; for (int j = 1; j <= n; j++) { if (a[j] == n) cnt++; } if (cnt == n) break; memset(b, 0, sizeof(b)); for (int j = 1; j <= n; j++) { l = j - a[j]; r = j + a[j]; if (l < 1) l = 1; if (r > n) r = n; for (int ii = l; ii <= r; ii++) { b[ii]++; } } for (int j = 1; j <= n; j++) { a[j] = b[j]; } } for (int i = 1; i <= n; i++) { printf("%d ", b[i]); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; int a[200005] = {0}, b[200005] = {0}; int main() { int n, k, l, r, cnt = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } for (int i = 1; i <= k; i++) { cnt = 0; for (int j = 1; j <= n; j++) { if (a[j] == n) cnt++; } if (cnt == n) break; memset(b, 0, sizeof(b)); for (int j = 1; j <= n; j++) { l = j - a[j]; r = j + a[j]; if (l < 1) l = 1; if (r > n) r = n; b[l]++; if (r + 1 <= n) b[r + 1]--; } for (int j = 2; j <= n; j++) { b[j] += b[j - 1]; } for (int j = 1; j <= n; j++) { a[j] = b[j]; } } for (int i = 1; i <= n; i++) { printf("%d ", b[i]); } return 0; }
replace
31
34
31
37
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using ULL = unsigned long long; using LL = long long; using String = std::string; using Ints = std::vector<int>; using Doubles = std::vector<double>; using Bools = std::vector<bool>; using Strings = std::vector<std::string>; using ULLs = std::vector<ULL>; using LLs = std::vector<LL>; // pythonのdictionary相当 template <typename T1, typename T2> using Dict = std::unordered_map<T1, T2>; int main(void) { int n, k; std::cin >> n >> k; Ints A(n); for (int i = 0; i < n; i++) { int _a; std::cin >> _a; A[i] = _a; } for (int i = 0; i < k; i++) { Ints B(n + 1, 0); for (int j = 0; j < n; j++) { B[std::max(0, j - A[j])]++; B[std::min(n, j + A[j] + 1)]--; } for (int j = 0; j < n; j++) { B[j + 1] += B[j]; } A = B; } for (int i = 0; i < n; i++) { std::cout << A[i] << " "; } std::cout << std::endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using ULL = unsigned long long; using LL = long long; using String = std::string; using Ints = std::vector<int>; using Doubles = std::vector<double>; using Bools = std::vector<bool>; using Strings = std::vector<std::string>; using ULLs = std::vector<ULL>; using LLs = std::vector<LL>; // pythonのdictionary相当 template <typename T1, typename T2> using Dict = std::unordered_map<T1, T2>; int main(void) { int n, k; std::cin >> n >> k; Ints A(n); for (int i = 0; i < n; i++) { int _a; std::cin >> _a; A[i] = _a; } for (int i = 0; i < std::min(50, k); i++) { Ints B(n + 1, 0); for (int j = 0; j < n; j++) { B[std::max(0, j - A[j])]++; B[std::min(n, j + A[j] + 1)]--; } for (int j = 0; j < n; j++) { B[j + 1] += B[j]; } A = B; } for (int i = 0; i < n; i++) { std::cout << A[i] << " "; } std::cout << std::endl; return 0; }
replace
34
35
34
35
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define REP(i, b) FOR(i, 0, b) #define RFOR(i, a, b) for (ll i = a - 1; i >= b; i--) #define RREP(i, a) RFOR(i, a, 0) #define REPALL(i, x) for (ll i = 0; i < x.size(); i++) #define RREPALL(i, x) for (ll i = x.size() - 1; i >= 0; i--) #define REPITR(itr, x) for (auto itr = (x).begin(); itr != (x).end(); itr++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort(ALL(x)) #define MIN_ELEMENT(x) min_element(ALL(x)) #define MAX_ELEMENT(x) max_element(ALL(x)) #define COUNT(x, num) count(ALL(x), num) #define MEMSET(x, val) memset(&x[0], val, sizeof(x)) #define CHMAX(a, b) a = max(a, b) #define CHMIN(a, b) a = min(a, b) #define debug(x) cerr << __LINE__ << ": " << (#x) << " = " << (x) << endl; void YES(bool flag) { cout << (flag ? "YES" : "NO") << endl; } void Yes(bool flag) { cout << (flag ? "Yes" : "No") << endl; } void yes(bool flag) { cout << (flag ? "yes" : "no") << endl; } #define e1 first #define e2 second #define newline putchar('\n') typedef long long ll; typedef unsigned long long ull; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef vector<ll> VLL; typedef vector<vector<ll>> VVLL; const int INF = 1e7; const ll MOD = 1e9 + 7; const double pi = 3.141592653589793; const VI dx = {1, 0, -1, 0}; const VI dy = {0, 1, 0, -1}; VI a; int main() { int n, k; cin >> n >> k; a.resize(n); REP(i, n) { cin >> a[i]; } REP(i, k) { VI sum(n + 1); REP(j, n) { // cout<<max((int)j-a[j], 0)<<" "<<min((int)j+a[j]+1, n)<<endl; sum[max((int)j - a[j], 0)]++; sum[min((int)j + a[j] + 1, n)]--; } a[0] = sum[0]; REP(j, n - 1) { a[j + 1] = a[j] + sum[j + 1]; } if (a[0] == k && a[n - 1] == k) { break; } } REP(i, n) { cout << a[i]; if (i != n - 1) cout << " "; } newline; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define REP(i, b) FOR(i, 0, b) #define RFOR(i, a, b) for (ll i = a - 1; i >= b; i--) #define RREP(i, a) RFOR(i, a, 0) #define REPALL(i, x) for (ll i = 0; i < x.size(); i++) #define RREPALL(i, x) for (ll i = x.size() - 1; i >= 0; i--) #define REPITR(itr, x) for (auto itr = (x).begin(); itr != (x).end(); itr++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort(ALL(x)) #define MIN_ELEMENT(x) min_element(ALL(x)) #define MAX_ELEMENT(x) max_element(ALL(x)) #define COUNT(x, num) count(ALL(x), num) #define MEMSET(x, val) memset(&x[0], val, sizeof(x)) #define CHMAX(a, b) a = max(a, b) #define CHMIN(a, b) a = min(a, b) #define debug(x) cerr << __LINE__ << ": " << (#x) << " = " << (x) << endl; void YES(bool flag) { cout << (flag ? "YES" : "NO") << endl; } void Yes(bool flag) { cout << (flag ? "Yes" : "No") << endl; } void yes(bool flag) { cout << (flag ? "yes" : "no") << endl; } #define e1 first #define e2 second #define newline putchar('\n') typedef long long ll; typedef unsigned long long ull; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef vector<ll> VLL; typedef vector<vector<ll>> VVLL; const int INF = 1e7; const ll MOD = 1e9 + 7; const double pi = 3.141592653589793; const VI dx = {1, 0, -1, 0}; const VI dy = {0, 1, 0, -1}; VI a; int main() { int n, k; cin >> n >> k; a.resize(n); REP(i, n) { cin >> a[i]; } REP(i, k) { VI sum(n + 1); REP(j, n) { // cout<<max((int)j-a[j], 0)<<" "<<min((int)j+a[j]+1, n)<<endl; sum[max((int)j - a[j], 0)]++; sum[min((int)j + a[j] + 1, n)]--; } a[0] = sum[0]; REP(j, n - 1) { a[j + 1] = a[j] + sum[j + 1]; } if (a[0] == n && a[n - 1] == n) { break; } } REP(i, n) { cout << a[i]; if (i != n - 1) cout << " "; } newline; return 0; }
replace
56
57
56
57
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ALL(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (n); i++) #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define INF 1000000000 #define mod 1000000007 using ll = long long; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(_, k) { if (*min_element(ALL(a)) == n) { rep(i, n) cout << n << (i + 1 == n ? "\n" : " "); return 0; } vector<int> imos(n, 0), b(n); rep(i, n) { imos[max(0, i - a[i])]++; imos[min(n, i + a[i] + 1)]--; } int p = 0; rep(i, n) { p += imos[i]; b[i] = p; } swap(a, b); } rep(i, n) cout << a[i] << (i + 1 == n ? "\n" : " "); return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (n); i++) #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define INF 1000000000 #define mod 1000000007 using ll = long long; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(_, k) { if (*min_element(ALL(a)) == n) { rep(i, n) cout << n << (i + 1 == n ? "\n" : " "); return 0; } vector<int> imos(n + 1, 0), b(n); rep(i, n) { imos[max(0, i - a[i])]++; imos[min(n, i + a[i] + 1)]--; } int p = 0; rep(i, n) { p += imos[i]; b[i] = p; } swap(a, b); } rep(i, n) cout << a[i] << (i + 1 == n ? "\n" : " "); return 0; }
replace
47
48
47
48
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using P = pair<int, int>; using pq = priority_queue<int>; typedef long long ll; int main() { int n; cin >> n; int k; cin >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(j, k) { vector<int> b(n + 1); rep(i, n) { int l = max(i - a[i], 0); int r = min(i + a[i], n - 1); b[l]++; if (r < n + 1) b[r + 1]--; } for (int i = 1; i < n; i++) b[i] += b[i - 1]; a = b; } rep(i, n) cout << a[i] << " "; cout << endl; return (0); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using P = pair<int, int>; using pq = priority_queue<int>; typedef long long ll; int main() { int n; cin >> n; int k; cin >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(j, k) { vector<int> b(n + 1); rep(i, n) { int l = max(i - a[i], 0); int r = min(i + a[i], n - 1); b[l]++; if (r < n + 1) b[r + 1]--; } for (int i = 1; i < n; i++) b[i] += b[i - 1]; if (a == b) break; a = b; } rep(i, n) cout << a[i] << " "; cout << endl; return (0); }
insert
26
26
26
28
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int lld; typedef unsigned long long int llu; #define INF (lld)(9223372036854775807) #define IINF (int)(2147483647) using namespace std; int main(void) { int n, k; cin >> n >> k; vector<vector<int>> a; a.push_back(vector<int>(n + 1)); for (int i = 0; i < n; i++) { cin >> a[0][i]; } for (int i = 1; i <= k; i++) { int ms = 0; a.push_back(vector<int>(n + 1)); for (int j = 0; j < n; j++) { a[i][max(0, j - a[i - 1][j])]++; a[i][min(n, j + a[i - 1][j] + 1)]--; } int c = 0; for (int j = 0; j < n; j++) { c += a[i][j]; a[i][j] = c; if (c == n) { ms++; } } if (ms == n) { break; } } for (int i = 0; i < n; i++) { cout << a[k][i] << (i == n - 1 ? "\n" : " "); } }
#include <bits/stdc++.h> typedef long long int lld; typedef unsigned long long int llu; #define INF (lld)(9223372036854775807) #define IINF (int)(2147483647) using namespace std; int main(void) { int n, k; cin >> n >> k; vector<vector<int>> a; a.push_back(vector<int>(n + 1)); for (int i = 0; i < n; i++) { cin >> a[0][i]; } for (int i = 1; i <= k; i++) { int ms = 0; a.push_back(vector<int>(n + 1)); for (int j = 0; j < n; j++) { a[i][max(0, j - a[i - 1][j])]++; a[i][min(n, j + a[i - 1][j] + 1)]--; } int c = 0; for (int j = 0; j < n; j++) { c += a[i][j]; a[i][j] = c; if (c == n) { ms++; } } if (ms == n) { k = i; break; } } for (int i = 0; i < n; i++) { cout << a[k][i] << (i == n - 1 ? "\n" : " "); } }
insert
33
33
33
34
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <sstream> #include <stdlib.h> #include <string> #include <vector> using namespace std; int a[300001]; int B[600003]; int n, N = 1; int right(int k) { return 2 * k + 2; } int left(int k) { return 2 * k + 1; } int parent(int k) { return (k - 1) / 2; } void query(int a, int b, int k, int l, int r) { // if (n==1)res = aray[0]; if (r <= a || b <= l) return; else if (a <= l && r <= b) B[k]++; else { query(a, b, left(k), l, (l + r) / 2); query(a, b, right(k), (l + r) / 2, r); } } void update(int root) { int r = right(root); int l = left(root); if (r < N - 1) { B[r] += B[root]; update(r); } else a[r - N + 1] = (B[r] + B[root] > n) ? n : B[r] + B[root]; if (l < N - 1) { B[l] += B[root]; update(l); } else a[l - N + 1] = (B[l] + B[root] > n) ? n : B[l] + B[root]; } void init() { for (int i = 0; i < 2 * N; i++) B[i] = 0; } int main() { int K, l, r; cin >> n >> K; int limit = log2(2 * pow(10, 7)); while (N < n) N *= 2; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < K; i++) { // if(i>limit+10) break; for (int j = 0; j < n; j++) { l = (j - a[j] >= 0) ? j - a[j] : 0; r = (j + a[j] + 1 <= n) ? j + a[j] + 1 : n; query(l, r, 0, 0, N); } update(0); init(); } for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; /* int t,p; t=p=1; for(int i=0;i<2*N-1;i++){ cout<<B[i]<<" "; if(t==p){ cout<<endl; t=1; p*=2; } else t++; }*/ return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <sstream> #include <stdlib.h> #include <string> #include <vector> using namespace std; int a[300001]; int B[600003]; int n, N = 1; int right(int k) { return 2 * k + 2; } int left(int k) { return 2 * k + 1; } int parent(int k) { return (k - 1) / 2; } void query(int a, int b, int k, int l, int r) { // if (n==1)res = aray[0]; if (r <= a || b <= l) return; else if (a <= l && r <= b) B[k]++; else { query(a, b, left(k), l, (l + r) / 2); query(a, b, right(k), (l + r) / 2, r); } } void update(int root) { int r = right(root); int l = left(root); if (r < N - 1) { B[r] += B[root]; update(r); } else a[r - N + 1] = (B[r] + B[root] > n) ? n : B[r] + B[root]; if (l < N - 1) { B[l] += B[root]; update(l); } else a[l - N + 1] = (B[l] + B[root] > n) ? n : B[l] + B[root]; } void init() { for (int i = 0; i < 2 * N; i++) B[i] = 0; } int main() { int K, l, r; cin >> n >> K; int limit = log2(2 * pow(10, 7)); while (N < n) N *= 2; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < K; i++) { if (i > 43) break; for (int j = 0; j < n; j++) { l = (j - a[j] >= 0) ? j - a[j] : 0; r = (j + a[j] + 1 <= n) ? j + a[j] + 1 : n; query(l, r, 0, 0, N); } update(0); init(); } for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; /* int t,p; t=p=1; for(int i=0;i<2*N-1;i++){ cout<<B[i]<<" "; if(t==p){ cout<<endl; t=1; p*=2; } else t++; }*/ return 0; }
replace
55
56
55
57
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(x) (x).begin(), (x).end() #define CASET2 \ int ___T, case_n = 1; \ scanf("%d ", &___T); \ while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0) #define CASET1 \ int ___T, case_n = 1; \ scanf("%d ", &___T); \ while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0) #define CASET \ int ___T; \ scanf("%d ", &___T); \ while (___T-- > 0) #define SZ(X) ((int)(X).size()) #define LEN(X) strlen(X) #define REP(i, n) for (int i = 0; i < int(n); i++) #define REP1(i, a, b) for (int i = (a); i <= int(b); i++) #define PER1(i, a, b) for (int i = (a); i >= (b); i--) #define REPL(i, x) for (int i = 0; x[i]; i++) #define PER(i, n) for (int i = (n)-1; i >= 0; i--) #define RI1(x) scanf("%d", &x) #define RI2(x, y) RI1(x), RI1(y) #define RI3(x, y...) RI1(x), RI2(y) #define RI4(x, y...) RI1(x), RI3(y) #define RI5(x, y...) RI1(x), RI4(y) #define RI6(x, y...) RI1(x), RI5(y) #define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME #define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv) #define DRI(argv...) \ int argv; \ RI(argv) #define WRI(argv...) while (RI(argv) != EOF) #define DWRI(x...) \ int x; \ WRI(x) #define RS(x) scanf("%s", x) #define MP make_pair #define PB push_back #define MS0(x) memset(x, 0, sizeof(x)) #define MS1(x) memset(x, -1, sizeof(x)) #define X first #define Y second #define V(x) vector<x> typedef long double LD; typedef pair<int, int> PII; typedef vector<int> VI; typedef long long LL; const int INF = 1000000000; void print(int i) { printf("%d", i); } void print(LL i); template <class T> void PI(T i) { print(i); puts(""); } template <class T> void PIS(T i) { print(i); printf(" "); } template <class T> void PV(T const &v, int N) { REP(i, N) { print(v[i]); printf("%c", i == N - 1 ? '\n' : ' '); } } template <class T> void PV(T const &v) { PV(v, SZ(v)); } template <class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; } long long shift(int i) { return 1ll << i; } template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } int popcount(int x) { return __builtin_popcount(x); } int popcount(long long x) { return __builtin_popcountll(x); } #include <unordered_map> #include <unordered_set> #define EB emplace_back #define RL(x) scanf("%lld", &(x)) #define PL(x) printf("%lld\n", x) #define DRL(x) \ LL x; \ RL(x) int A[100005], B[100005]; int main() { DRI(N, K); REP(i, N) { RI(A[i]); } while (K--) { MS0(B); REP(i, N) { int l = max(0, i - A[i]), r = min(N - 1, i + A[i]); B[l]++; B[r + 1]--; } A[0] = B[0]; REP1(i, 1, N - 1) { A[i] = B[i] + A[i - 1]; } bool go = false; REP(i, N) { if (A[i] != N) { go = true; } } if (!go) { break; } } REP(i, N) { printf("%d%c", A[i], i == N - 1 ? '\n' : ' '); } return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(x) (x).begin(), (x).end() #define CASET2 \ int ___T, case_n = 1; \ scanf("%d ", &___T); \ while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0) #define CASET1 \ int ___T, case_n = 1; \ scanf("%d ", &___T); \ while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0) #define CASET \ int ___T; \ scanf("%d ", &___T); \ while (___T-- > 0) #define SZ(X) ((int)(X).size()) #define LEN(X) strlen(X) #define REP(i, n) for (int i = 0; i < int(n); i++) #define REP1(i, a, b) for (int i = (a); i <= int(b); i++) #define PER1(i, a, b) for (int i = (a); i >= (b); i--) #define REPL(i, x) for (int i = 0; x[i]; i++) #define PER(i, n) for (int i = (n)-1; i >= 0; i--) #define RI1(x) scanf("%d", &x) #define RI2(x, y) RI1(x), RI1(y) #define RI3(x, y...) RI1(x), RI2(y) #define RI4(x, y...) RI1(x), RI3(y) #define RI5(x, y...) RI1(x), RI4(y) #define RI6(x, y...) RI1(x), RI5(y) #define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME #define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv) #define DRI(argv...) \ int argv; \ RI(argv) #define WRI(argv...) while (RI(argv) != EOF) #define DWRI(x...) \ int x; \ WRI(x) #define RS(x) scanf("%s", x) #define MP make_pair #define PB push_back #define MS0(x) memset(x, 0, sizeof(x)) #define MS1(x) memset(x, -1, sizeof(x)) #define X first #define Y second #define V(x) vector<x> typedef long double LD; typedef pair<int, int> PII; typedef vector<int> VI; typedef long long LL; const int INF = 1000000000; void print(int i) { printf("%d", i); } void print(LL i); template <class T> void PI(T i) { print(i); puts(""); } template <class T> void PIS(T i) { print(i); printf(" "); } template <class T> void PV(T const &v, int N) { REP(i, N) { print(v[i]); printf("%c", i == N - 1 ? '\n' : ' '); } } template <class T> void PV(T const &v) { PV(v, SZ(v)); } template <class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; } long long shift(int i) { return 1ll << i; } template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } int popcount(int x) { return __builtin_popcount(x); } int popcount(long long x) { return __builtin_popcountll(x); } #include <unordered_map> #include <unordered_set> #define EB emplace_back #define RL(x) scanf("%lld", &(x)) #define PL(x) printf("%lld\n", x) #define DRL(x) \ LL x; \ RL(x) int A[200005], B[200005]; int main() { DRI(N, K); REP(i, N) { RI(A[i]); } while (K--) { MS0(B); REP(i, N) { int l = max(0, i - A[i]), r = min(N - 1, i + A[i]); B[l]++; B[r + 1]--; } A[0] = B[0]; REP1(i, 1, N - 1) { A[i] = B[i] + A[i - 1]; } bool go = false; REP(i, N) { if (A[i] != N) { go = true; } } if (!go) { break; } } REP(i, N) { printf("%d%c", A[i], i == N - 1 ? '\n' : ' '); } return 0; }
replace
108
109
108
109
0
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; /* using PAIR = pair<string, int>; sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } using Graph = vector<vector<int>>; using P = pair<int, int>; using P1 = pair<pair<int, int>, int>; // クラスカル法とかで、{cost, {from, to}}的に使う。 const int INF = 1001001001; const double pi = acos(-1); int main() { ll n, k; cin >> n >> k; vector<ll> a(n); vector<ll> SUM(n + 10, 0); for (int i = 0; i < n; i++) { cin >> a[i]; SUM[max(0ll, i - a[i])]++; SUM[min(n, i + a[i] + 1)]--; } for (int i = 0; i < n; i++) { SUM[i + 1] += SUM[i]; } int rest = 0; for (ll i = 0; i < k - 1; i++) { ll MIN = 1001001001; vector<ll> SUM1(n + 10, 0); for (ll j = 0; j < n; j++) { SUM1[max(0ll, j - SUM[j])]++; SUM1[min(n, j + SUM[j] + 1)]--; } for (int j = 0; j < n; j++) { SUM1[j + 1] += SUM1[j]; MIN = min(MIN, SUM[j + 1]); } if (MIN >= n) { rest = k - 1 - i; break; } swap(SUM, SUM1); } for (int i = 0; i < n; i++) { SUM[i] += n * rest; } for (int i = 0; i < n; i++) { cout << SUM[i] << " "; } cout << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; /* using PAIR = pair<string, int>; sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } using Graph = vector<vector<int>>; using P = pair<int, int>; using P1 = pair<pair<int, int>, int>; // クラスカル法とかで、{cost, {from, to}}的に使う。 const int INF = 1001001001; const double pi = acos(-1); int main() { ll n, k; cin >> n >> k; vector<ll> a(n); vector<ll> SUM(n + 10, 0); for (int i = 0; i < n; i++) { cin >> a[i]; SUM[max(0ll, i - a[i])]++; SUM[min(n, i + a[i] + 1)]--; } for (int i = 0; i < n; i++) { SUM[i + 1] += SUM[i]; } int rest = 0; for (ll i = 0; i < min(100ll, k - 1); i++) { ll MIN = 1001001001; vector<ll> SUM1(n + 10, 0); for (ll j = 0; j < n; j++) { SUM1[max(0ll, j - SUM[j])]++; SUM1[min(n, j + SUM[j] + 1)]--; } for (int j = 0; j < n; j++) { SUM1[j + 1] += SUM1[j]; MIN = min(MIN, SUM[j + 1]); } if (MIN >= n) { rest = k - 1 - i; break; } swap(SUM, SUM1); } for (int i = 0; i < n; i++) { SUM[i] += n * rest; } for (int i = 0; i < n; i++) { cout << SUM[i] << " "; } cout << endl; return 0; }
replace
69
70
69
70
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> c(n, n); rep(i, n) { cin >> a[i]; } rep(j, k) { vector<int> d(n + 1); rep(i, n) { d[max(i - a[i], 0)]++; d[min(i + a[i] + 1, n)]--; } vector<int> e(n, d[0]); rep(i, n) { e[i + 1] = e[i] + d[i + 1]; } a = e; if (c == e) { break; } } rep(i, n - 1) { cout << a[i] << ' '; } cout << a[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> c(n, n); rep(i, n) { cin >> a[i]; } rep(j, k) { vector<int> d(n + 1); rep(i, n) { d[max(i - a[i], 0)]++; d[min(i + a[i] + 1, n)]--; } vector<int> e(n, d[0]); rep(i, n - 1) { e[i + 1] = e[i] + d[i + 1]; } a = e; if (c == e) { break; } } rep(i, n - 1) { cout << a[i] << ' '; } cout << a[n - 1] << endl; return 0; }
replace
16
17
16
17
0
p02647
C++
Runtime Error
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long void operation(vector<int> &a) { vector<int> b(a.size(), 0); for (int i = 0; i < (long long)a.size(); i++) { int start = i - a[i]; int end = i + a[i] + 1; if (start < 0) start = 0; b[start]++; if (end <= (long long)a.size()) b[end]--; } for (int i = 1; i < (long long)a.size(); i++) { b[i] += b[i - 1]; } a = b; } signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < k; i++) { operation(a); if (a == vector<int>(n, n)) break; } for (auto &&ai : a) { cout << ai << " "; } cout << endl; }
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long void operation(vector<int> &a) { vector<int> b(a.size(), 0); for (int i = 0; i < (long long)a.size(); i++) { int start = i - a[i]; int end = i + a[i] + 1; if (start < 0) start = 0; b[start]++; if (end < (long long)a.size()) b[end]--; } for (int i = 1; i < (long long)a.size(); i++) { b[i] += b[i - 1]; } a = b; } signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < k; i++) { operation(a); if (a == vector<int>(n, n)) break; } for (auto &&ai : a) { cout << ai << " "; } cout << endl; }
replace
20
21
20
21
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long int ll; typedef unsigned long long ull; 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; } typedef pair<ll, ll> P; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> tasu(n); vector<int> h(n); rep(i, n) { cin >> a[i]; vector<ll> tasu(n); vector<ll> h(n); } if (n <= k) { rep(i, n) cout << n << " "; cout << endl; return 0; } rep(t, k) { tasu = h; rep(i, n) { tasu[max(0, i - a[i])]++; int tasuin = i + a[i] + 1; if (tasuin < n) tasu[tasuin]--; } ll now = 0; bool finish = true; rep(i, n - 1) { tasu[i + 1] += tasu[i]; } if (tasu == a) break; a = tasu; } rep(i, n) cout << a[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long int ll; typedef unsigned long long ull; 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; } typedef pair<ll, ll> P; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> tasu(n); vector<int> h(n); rep(i, n) { cin >> a[i]; tasu[i]; h[i]; } if (n <= k) { rep(i, n) cout << n << " "; cout << endl; return 0; } rep(t, k) { tasu = h; rep(i, n) { tasu[max(0, i - a[i])]++; int tasuin = i + a[i] + 1; if (tasuin < n) tasu[tasuin]--; } ll now = 0; bool finish = true; rep(i, n - 1) { tasu[i + 1] += tasu[i]; } if (tasu == a) break; a = tasu; } rep(i, n) cout << a[i] << " "; cout << endl; return 0; }
replace
31
33
31
33
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double LD; using namespace std; const int INF = 2147483647; const int INF2 = 0x3f3f3f3f; const ll INF64 = 3e18; const double INFD = 1e30; const double EPS = 1e-10; const double PI = acos(-1); const int MOD = 998244353; template <typename T> inline T read() { T X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } const int MAXN = 200005; int n, m, k; int dr[4] = {1, 0, -1, 0}; int dc[4] = {0, 1, 0, -1}; int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1}; int CASE = 1; int arr[MAXN]; int b[MAXN]; #define self nodes[p] #define ls nodes[p << 1] #define rs nodes[p << 1 | 1] struct SegmentTree { struct Node { int cov, tag; }; Node nodes[MAXN << 2]; int tot; inline void modify(int l, int r, int p, int f) { self.tag += nodes[f].tag; self.cov += (r - l + 1) * nodes[f].tag; } inline void push_down(int l, int r, int p) { if (self.tag != 0) { int mid = (l + r) / 2; modify(l, mid, p << 1, p); modify(mid + 1, r, p << 1 | 1, p); self.tag = 0; } } void push_up(int p) { self.cov = ls.cov + rs.cov; } void update(int x, int y, int l, int r, int p, int v) { if (x <= l && y >= r) { self.cov += (r - l + 1) * v; self.tag += v; return; } push_down(l, r, p); int mid = (l + r) / 2; if (x <= mid) update(x, y, l, mid, p << 1, v); if (y > mid) update(x, y, mid + 1, r, p << 1 | 1, v); push_up(p); } int query(int x, int l, int r, int p) { if (l == r) return self.cov; int mid = (l + r) / 2; push_down(l, r, p); if (x <= mid) return query(x, l, mid, p << 1); else return query(x, mid + 1, r, p << 1 | 1); } }; SegmentTree tree; char text[MAXN]; int main() { #ifdef LOCALLL freopen("in", "r", stdin); freopen("out", "w", stdout); #endif scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &arr[i]); tree.update(max(1, i - arr[i]), min(n, i + arr[i]), 1, n, 1, 1); } for (int i = 0; i < min(m, 100); i++) { for (int j = 1; j <= n; j++) { b[j] = tree.query(j, 1, n, 1); } for (int j = 1; j <= n; j++) { tree.update(max(1, j - arr[j]), min(n, j + arr[j]), 1, n, 1, -1); arr[j] = b[j]; } for (int j = 1; j <= n; j++) { tree.update(max(1, j - b[j]), min(n, j + b[j]), 1, n, 1, 1); } } for (int j = 1; j <= n; j++) { printf("%d ", b[j]); } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double LD; using namespace std; const int INF = 2147483647; const int INF2 = 0x3f3f3f3f; const ll INF64 = 3e18; const double INFD = 1e30; const double EPS = 1e-10; const double PI = acos(-1); const int MOD = 998244353; template <typename T> inline T read() { T X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } const int MAXN = 200005; int n, m, k; int dr[4] = {1, 0, -1, 0}; int dc[4] = {0, 1, 0, -1}; int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1}; int CASE = 1; int arr[MAXN]; int b[MAXN]; #define self nodes[p] #define ls nodes[p << 1] #define rs nodes[p << 1 | 1] struct SegmentTree { struct Node { int cov, tag; }; Node nodes[MAXN << 2]; int tot; inline void modify(int l, int r, int p, int f) { self.tag += nodes[f].tag; self.cov += (r - l + 1) * nodes[f].tag; } inline void push_down(int l, int r, int p) { if (self.tag != 0) { int mid = (l + r) / 2; modify(l, mid, p << 1, p); modify(mid + 1, r, p << 1 | 1, p); self.tag = 0; } } void push_up(int p) { self.cov = ls.cov + rs.cov; } void update(int x, int y, int l, int r, int p, int v) { if (x <= l && y >= r) { self.cov += (r - l + 1) * v; self.tag += v; return; } push_down(l, r, p); int mid = (l + r) / 2; if (x <= mid) update(x, y, l, mid, p << 1, v); if (y > mid) update(x, y, mid + 1, r, p << 1 | 1, v); push_up(p); } int query(int x, int l, int r, int p) { if (l == r) return self.cov; int mid = (l + r) / 2; push_down(l, r, p); if (x <= mid) return query(x, l, mid, p << 1); else return query(x, mid + 1, r, p << 1 | 1); } }; SegmentTree tree; char text[MAXN]; int main() { #ifdef LOCALLL freopen("in", "r", stdin); freopen("out", "w", stdout); #endif scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &arr[i]); tree.update(max(1, i - arr[i]), min(n, i + arr[i]), 1, n, 1, 1); } for (int i = 0; i < min(m, 50); i++) { for (int j = 1; j <= n; j++) { b[j] = tree.query(j, 1, n, 1); } for (int j = 1; j <= n; j++) { tree.update(max(1, j - arr[j]), min(n, j + arr[j]), 1, n, 1, -1); arr[j] = b[j]; } for (int j = 1; j <= n; j++) { tree.update(max(1, j - b[j]), min(n, j + b[j]), 1, n, 1, 1); } } for (int j = 1; j <= n; j++) { printf("%d ", b[j]); } return 0; }
replace
108
109
108
109
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <numeric> const int MaxN = 100005; int n, A[MaxN]; bool trans() { static int B[MaxN]; std::fill(B, B + n, 0); for (int i = 0; i < n; ++i) { int l = std::max(0, i - A[i]); int r = std::min(n - 1, i + A[i]); B[l] += 1; B[r + 1] -= 1; } bool flag = true; for (int i = 0; i < n; ++i) { flag &= A[i] == B[i]; A[i] = B[i]; B[i + 1] += B[i]; } return flag; } int main() { int q; scanf("%d%d", &n, &q); for (int i = 0; i < n; ++i) scanf("%d", A + i); while (q--) { if (trans()) break; } for (int i = 0; i < n; ++i) printf("%d ", A[i]); puts(""); return 0; }
#include <algorithm> #include <cstdio> #include <numeric> const int MaxN = 200005; int n, A[MaxN]; bool trans() { static int B[MaxN]; std::fill(B, B + n, 0); for (int i = 0; i < n; ++i) { int l = std::max(0, i - A[i]); int r = std::min(n - 1, i + A[i]); B[l] += 1; B[r + 1] -= 1; } bool flag = true; for (int i = 0; i < n; ++i) { flag &= A[i] == B[i]; A[i] = B[i]; B[i + 1] += B[i]; } return flag; } int main() { int q; scanf("%d%d", &n, &q); for (int i = 0; i < n; ++i) scanf("%d", A + i); while (q--) { if (trans()) break; } for (int i = 0; i < n; ++i) printf("%d ", A[i]); puts(""); return 0; }
replace
4
5
4
5
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define FOR(i, l, r) for (ll i = l; i < r; i++) #define rep(i, N) FOR(i, 0, N) #define MOD 1000000007 #define INF 1000000000 using ll = long long int; using namespace std; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; int main() { int N, K; cin >> N >> K; vi A(N); rep(i, N) cin >> A[i]; rep(i, K) { bool flag = true; vi B(N, 0); rep(j, N) { if (flag && A[j] != N - 1) flag = false; B[max(0, (int)j - A[j])]++; if ((int)j + A[j] < N - 1) B[(int)j + A[j] + 1]--; } rep(j, N - 1) B[j + 1] += B[j]; rep(j, N) A[j] = B[j]; if (flag) break; } rep(i, N) { cout << A[i] << "\n"; } return 0; }
#include <bits/stdc++.h> #define FOR(i, l, r) for (ll i = l; i < r; i++) #define rep(i, N) FOR(i, 0, N) #define MOD 1000000007 #define INF 1000000000 using ll = long long int; using namespace std; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; int main() { int N, K; cin >> N >> K; vi A(N); rep(i, N) cin >> A[i]; rep(i, K) { bool flag = true; vi B(N, 0); rep(j, N) { if (flag && A[j] < N) flag = false; B[max(0, (int)j - A[j])]++; if ((int)j + A[j] < N - 1) B[(int)j + A[j] + 1]--; } rep(j, N - 1) B[j + 1] += B[j]; rep(j, N) A[j] = B[j]; if (flag) break; } rep(i, N) { cout << A[i] << "\n"; } return 0; }
replace
25
26
25
26
TLE
p02647
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (a); i >= (b); --i) const int mxN = 1e5 + 5; int N, K, A[mxN]; int ft[mxN]; void u(int i, int x) { for (; i <= N; i += i & -i) ft[i] += x; } void update(int i, int j, int x) { u(i, x); u(j + 1, -x); } int query(int i) { int r = 0; for (; i; i -= i & -i) r += ft[i]; return r; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; FOR(i, 1, N) { cin >> A[i]; update(max(1, i - A[i]), min(N, i + A[i]), 1); } FOR(i, 1, K) { bool brk = 1; FOR(j, 1, N) { A[j] = query(j); brk &= A[j] == N; } if (brk) break; memset(ft, 0, sizeof ft); FOR(j, 1, N) { update(max(1, j - A[j]), min(N, j + A[j]), 1); } } FOR(i, 1, N) { cout << A[i] << ' '; } cout << '\n'; }
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (a); i >= (b); --i) const int mxN = 2e5 + 5; int N, K, A[mxN]; int ft[mxN]; void u(int i, int x) { for (; i <= N; i += i & -i) ft[i] += x; } void update(int i, int j, int x) { u(i, x); u(j + 1, -x); } int query(int i) { int r = 0; for (; i; i -= i & -i) r += ft[i]; return r; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; FOR(i, 1, N) { cin >> A[i]; update(max(1, i - A[i]), min(N, i + A[i]), 1); } FOR(i, 1, K) { bool brk = 1; FOR(j, 1, N) { A[j] = query(j); brk &= A[j] == N; } if (brk) break; memset(ft, 0, sizeof ft); FOR(j, 1, N) { update(max(1, j - A[j]), min(N, j + A[j]), 1); } } FOR(i, 1, N) { cout << A[i] << ' '; } cout << '\n'; }
replace
10
11
10
11
0
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double const int MOD = 1e9 + 7; const long double Pi = acos(-1); using P = pair<ll, ll>; ll gcd(ll a, ll b) { // aとbの最大公約数を返す//計算量は0(log(max(a,b)) if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { // aとbの最小公倍数を返す//計算量は0(log(max(a,b)) return a * b / gcd(a, b); } ll pow(ll x, ll y) { // x^yを返す//計算量は0(log(y)) ll tmp = x, res = 1; while (y) { if (y % 2) { res = res * tmp % MOD; } y >>= 1; tmp = tmp * tmp % MOD; } return res; } ll nature(ll a) { // 絶対値を返す if (a >= 0) { return (a); } else { return (-1 * a); } } ll prime(ll a) { // 素数なら1を返す//計算量は0(sqrt(a)) if (a == 2) { return 1; } else if (a % 2 == 0 || a == 1) { return 0; } for (ll i = 3; i * i <= a; i += 2) { if (a % i == 0) { return 0; } } return 1; } vector<int> Z; void z_algorithm(string str) { // 計算量はO(str.size()) Z.resize(str.size()); Z.at(0) = str.size(); int m = 1, n = 0; while (m < (int)str.size()) { while (m + n < (int)str.size() && str.at(n) == str.at(m + n)) { n++; } Z.at(m) = n; if (n == 0) { m++; continue; } int k = 1; while (k + Z.at(k) < n) { Z.at(m + k) = Z.at(k); k++; } m += k; n -= k; } } template <typename T> struct BIT { // 区間加算O(log(N)) // 区間シグマ計算O(log(N)) // 単点加算O(log(N)) // 単点計算O(log(N)) int n; // 元の数列のサイズ vector<T> bit[2]; // データ収納用 void init(int n_) { n = n_ + 1; for (int j = 0; j < 2; j++) { bit[j].assign(n, 0); } } void add_sub(int p, int i, T x) { for (int j = i; j < n; j += j & -j) { bit[p][j] += x; } } void add(int l, int r, T x) { //[l,r]に加算 add_sub(0, l, -x * (l - 1)); add_sub(0, r + 1, x * r); add_sub(1, l, x); add_sub(1, r + 1, -x); } T sum_sub(int p, int i) { T s(0); for (int j = i; j > 0; j -= j & -j) { s += bit[p][j]; } return s; } T sum(int i, int j) { //[i,j]のΣを計算 return sum_sub(0, j) + sum_sub(1, j) * j - sum_sub(0, i - 1) - sum_sub(1, i - 1) * (i - 1); } T binary_search_sum1( int key) { // a_1+a_2+...+a_x>=keyとなるような最小のxを求める(ただしa_i>=0) // key以上の値 if (key <= 0) { return 0; } else { int x = 0, r = 1; while (r < n) { r = r << 1; } for (int length = r; length > 0; length = length >> 1) { // 長さlengthは1段下るごとに半分に if (x + length < n && sum(x + 1, x + length) < key) { // 採用するとき key -= sum(x + 1, x + length); x += length; } } return x + 1; } } T binary_search_sum2( int key) { // a_1+a_2+...+a_x<=keyとなるような最大のxを求める(ただしa_i>=0) // key以下の値 key++; if (key <= 0) { return 0; } else { int x = 0, r = 1; while (r < n) { r = r << 1; } for (int length = r; length > 0; length = length >> 1) { // 長さlenは1段下るごとに半分に if (x + length < n && sum(x + 1, x + length) < key) { // 採用するとき key -= sum(x + 1, x + length); x += length; } } return x; } } /* 使い方 BIT<int> rock; rock.init(N); Nは加算などの操作を行う配列のサイズ ...(その後は適当に) */ }; template <typename T> struct BIT2D { // 単点に値たすO(1) //[1,h][1,w]の総和O(log(h)*log(w)) //[h,hh][w,ww]の値の総和O(4*log(max(h,w,hh,ww))) int H, W; vector<vector<T>> bit; void init(int H_, int W_) { H = H_ + 1; W = W_ + 1; bit.assign(H, vector<T>(W, 0)); } void add(int h, int w, T x) { //(h,w)にxを足す0(1) (区間サイズnの場合O(N)) for (int i = h; i < H; i += i & -i) { for (int j = w; j < W; j += j & -j) { bit[i][j] += x; } } } T sum(int h, int w) { //[1,h][1,w]の総和O(log(h)*log(w)) T s = 0; for (int i = h; i > 0; i -= i & -i) { for (int j = w; j > 0; j -= j & -j) { s += bit[i][j]; } } return s; } T partsum(int h, int w, int hh, int ww) { //[h,hh][w,ww]の総和O(4*log(max(h,w,hh,ww))) // 前処理でsumを計算しておけば計算量減らせるかも return sum(hh, ww) + sum(h - 1, w - 1) - sum(hh, w - 1) - sum(h - 1, ww); } }; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } BIT<int> rock; rock.init(N); for (int i = 1; i <= N; i++) { rock.add(i, i, A.at(i - 1)); } vector<int> copy(N); for (int i = 0; i < K; i++) { for (int i = 1; i <= N; i++) { copy.at(i - 1) = rock.sum(i, i); } for (int i = 1; i <= N; i++) { rock.add(i, i, -1 * rock.sum(i, i)); } for (int i = 1; i <= N; i++) { int left = max(1, i - copy.at(i - 1)), right = min(N, i + copy.at(i - 1)); rock.add(left, right, 1); } int check = 0; for (int i = 0; i < N; i++) { if (A.at(i) == N) { check++; } } if (check == N) { break; } } for (int i = 1; i <= N; i++) { cout << rock.sum(i, i) << " "; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double const int MOD = 1e9 + 7; const long double Pi = acos(-1); using P = pair<ll, ll>; ll gcd(ll a, ll b) { // aとbの最大公約数を返す//計算量は0(log(max(a,b)) if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { // aとbの最小公倍数を返す//計算量は0(log(max(a,b)) return a * b / gcd(a, b); } ll pow(ll x, ll y) { // x^yを返す//計算量は0(log(y)) ll tmp = x, res = 1; while (y) { if (y % 2) { res = res * tmp % MOD; } y >>= 1; tmp = tmp * tmp % MOD; } return res; } ll nature(ll a) { // 絶対値を返す if (a >= 0) { return (a); } else { return (-1 * a); } } ll prime(ll a) { // 素数なら1を返す//計算量は0(sqrt(a)) if (a == 2) { return 1; } else if (a % 2 == 0 || a == 1) { return 0; } for (ll i = 3; i * i <= a; i += 2) { if (a % i == 0) { return 0; } } return 1; } vector<int> Z; void z_algorithm(string str) { // 計算量はO(str.size()) Z.resize(str.size()); Z.at(0) = str.size(); int m = 1, n = 0; while (m < (int)str.size()) { while (m + n < (int)str.size() && str.at(n) == str.at(m + n)) { n++; } Z.at(m) = n; if (n == 0) { m++; continue; } int k = 1; while (k + Z.at(k) < n) { Z.at(m + k) = Z.at(k); k++; } m += k; n -= k; } } template <typename T> struct BIT { // 区間加算O(log(N)) // 区間シグマ計算O(log(N)) // 単点加算O(log(N)) // 単点計算O(log(N)) int n; // 元の数列のサイズ vector<T> bit[2]; // データ収納用 void init(int n_) { n = n_ + 1; for (int j = 0; j < 2; j++) { bit[j].assign(n, 0); } } void add_sub(int p, int i, T x) { for (int j = i; j < n; j += j & -j) { bit[p][j] += x; } } void add(int l, int r, T x) { //[l,r]に加算 add_sub(0, l, -x * (l - 1)); add_sub(0, r + 1, x * r); add_sub(1, l, x); add_sub(1, r + 1, -x); } T sum_sub(int p, int i) { T s(0); for (int j = i; j > 0; j -= j & -j) { s += bit[p][j]; } return s; } T sum(int i, int j) { //[i,j]のΣを計算 return sum_sub(0, j) + sum_sub(1, j) * j - sum_sub(0, i - 1) - sum_sub(1, i - 1) * (i - 1); } T binary_search_sum1( int key) { // a_1+a_2+...+a_x>=keyとなるような最小のxを求める(ただしa_i>=0) // key以上の値 if (key <= 0) { return 0; } else { int x = 0, r = 1; while (r < n) { r = r << 1; } for (int length = r; length > 0; length = length >> 1) { // 長さlengthは1段下るごとに半分に if (x + length < n && sum(x + 1, x + length) < key) { // 採用するとき key -= sum(x + 1, x + length); x += length; } } return x + 1; } } T binary_search_sum2( int key) { // a_1+a_2+...+a_x<=keyとなるような最大のxを求める(ただしa_i>=0) // key以下の値 key++; if (key <= 0) { return 0; } else { int x = 0, r = 1; while (r < n) { r = r << 1; } for (int length = r; length > 0; length = length >> 1) { // 長さlenは1段下るごとに半分に if (x + length < n && sum(x + 1, x + length) < key) { // 採用するとき key -= sum(x + 1, x + length); x += length; } } return x; } } /* 使い方 BIT<int> rock; rock.init(N); Nは加算などの操作を行う配列のサイズ ...(その後は適当に) */ }; template <typename T> struct BIT2D { // 単点に値たすO(1) //[1,h][1,w]の総和O(log(h)*log(w)) //[h,hh][w,ww]の値の総和O(4*log(max(h,w,hh,ww))) int H, W; vector<vector<T>> bit; void init(int H_, int W_) { H = H_ + 1; W = W_ + 1; bit.assign(H, vector<T>(W, 0)); } void add(int h, int w, T x) { //(h,w)にxを足す0(1) (区間サイズnの場合O(N)) for (int i = h; i < H; i += i & -i) { for (int j = w; j < W; j += j & -j) { bit[i][j] += x; } } } T sum(int h, int w) { //[1,h][1,w]の総和O(log(h)*log(w)) T s = 0; for (int i = h; i > 0; i -= i & -i) { for (int j = w; j > 0; j -= j & -j) { s += bit[i][j]; } } return s; } T partsum(int h, int w, int hh, int ww) { //[h,hh][w,ww]の総和O(4*log(max(h,w,hh,ww))) // 前処理でsumを計算しておけば計算量減らせるかも return sum(hh, ww) + sum(h - 1, w - 1) - sum(hh, w - 1) - sum(h - 1, ww); } }; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } BIT<int> rock; rock.init(N); for (int i = 1; i <= N; i++) { rock.add(i, i, A.at(i - 1)); } vector<int> copy(N); for (int i = 0; i < K; i++) { for (int i = 1; i <= N; i++) { copy.at(i - 1) = rock.sum(i, i); } for (int i = 1; i <= N; i++) { rock.add(i, i, -1 * rock.sum(i, i)); } for (int i = 1; i <= N; i++) { int left = max(1, i - copy.at(i - 1)), right = min(N, i + copy.at(i - 1)); rock.add(left, right, 1); } int check = 0; for (int i = 1; i <= N; i++) { if (rock.sum(i, i) == N) { check++; } } if (check == N) { break; } } for (int i = 1; i <= N; i++) { cout << rock.sum(i, i) << " "; } }
replace
212
214
212
214
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; using P = pair<int, int>; int main() { int N, K; cin >> N >> K; vector<int> A(N); REP(i, N) cin >> A[i]; REP(i, K) { vector<int> imos(N + 1, 0); REP(j, N) { imos.at(max(0, j - A[j]))++; imos.at(min(N, j + A[j] + 1))--; } int sum = 0; REP(j, N) { sum += imos.at(j); A[j] = sum; } } REP(i, N) { if (i != N - 1) { cout << A[i] << " "; } else { cout << A[i]; } } cout << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; using P = pair<int, int>; int main() { int N, K; cin >> N >> K; vector<int> A(N); REP(i, N) cin >> A[i]; REP(i, K) { vector<int> imos(N + 1, 0); REP(j, N) { imos.at(max(0, j - A[j]))++; imos.at(min(N, j + A[j] + 1))--; } int sum = 0; REP(j, N) { sum += imos.at(j); A[j] = sum; } int flag = 0; REP(j, N) { if (A[j] != N) { flag = 1; } } if (flag == 0) { break; } } REP(i, N) { if (i != N - 1) { cout << A[i] << " "; } else { cout << A[i]; } } cout << endl; }
insert
27
27
27
36
TLE
p02647
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> const int MOD = 1e9 + 7; #define PI 3.14159265359 typedef long long ll; using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> task(n + 1); for (int i = 0; i < n; i++) cin >> a[i]; if (n * 4 <= k) { for (int i = 0; i < n; i++) cout << n << " "; cout << endl; return 0; } for (int i = 0; i < k; i++) { for (int j = 0; j <= n; j++) { task[j] = 0; } int temp = 0; for (int now = 0; now < n; now++) { task[max(0, now - a[now])] += 1; task[min(n, now + a[now] + 1)] -= 1; } for (int now = 0; now < n; now++) { temp += task[now]; a[now] = temp; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> const int MOD = 1e9 + 7; #define PI 3.14159265359 typedef long long ll; using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> task(n + 1); for (int i = 0; i < n; i++) cin >> a[i]; if (k > 1000) { for (int i = 0; i < n; i++) cout << n << " "; cout << endl; return 0; } for (int i = 0; i < k; i++) { for (int j = 0; j <= n; j++) { task[j] = 0; } int temp = 0; for (int now = 0; now < n; now++) { task[max(0, now - a[now])] += 1; task[min(n, now + a[now] + 1)] -= 1; } for (int now = 0; now < n; now++) { temp += task[now]; a[now] = temp; } } for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; return 0; }
replace
23
24
23
24
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fi first #define endl "\n" #define se second #define ll long long #define inf 0x3f3f3f3f #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int N = 3e5 + 10; const ll mod = 1e9 + 7; ll pre[N], arr[N], k, n; int main() { fast cin >> n >> k; for (int i = 1; i <= n; i++) cin >> arr[i]; while (k--) { for (ll i = 1; i <= n; i++) { ll x = max(1ll, i - arr[i]); ll y = min(n, arr[i] + i); pre[x] += 1; pre[y + 1] -= 1; } for (ll i = 1; i <= n; i++) pre[i] += pre[i - 1]; for (int i = 1; i <= n; i++) { arr[i] = pre[i]; pre[i] = 0; } } for (ll i = 1; i <= n; i++) cout << arr[i] << " "; }
#include <bits/stdc++.h> using namespace std; #define fi first #define endl "\n" #define se second #define ll long long #define inf 0x3f3f3f3f #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int N = 3e5 + 10; const ll mod = 1e9 + 7; ll pre[N], arr[N], k, n; int main() { fast cin >> n >> k; for (int i = 1; i <= n; i++) cin >> arr[i]; while (k--) { bool ans = true; for (int i = 1; i <= n; i++) if (arr[i] != n) ans = false; if (ans) break; for (ll i = 1; i <= n; i++) { ll x = max(1ll, i - arr[i]); ll y = min(n, arr[i] + i); pre[x] += 1; pre[y + 1] -= 1; } for (ll i = 1; i <= n; i++) pre[i] += pre[i - 1]; for (int i = 1; i <= n; i++) { arr[i] = pre[i]; pre[i] = 0; } } for (ll i = 1; i <= n; i++) cout << arr[i] << " "; }
replace
19
20
19
25
TLE
p02647
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; 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; } // Write From this Line int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; k = min(1000, k); rep(j, k) { vector<int> l(n), r(n); priority_queue<int, vector<int>, greater<int>> que; int L = 0, R = 0; rep(i, n) { while (que.size() && que.top() < (i + 1)) { L--; que.pop(); } l[i] = L; L++; que.push((i + 1) + a[i]); } priority_queue<int> que2; for (int i = n - 1; i >= 0; i--) { while (que2.size() && que2.top() > (i + 1)) { R--; que2.pop(); } r[i] = R; R++; que2.push((i + 1) - a[i]); } rep(i, n) { a[i] = l[i] + r[i] + 1; } } for (auto x : a) { cout << x << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; 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; } // Write From this Line int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; k = min(50, k); rep(j, k) { vector<int> l(n), r(n); priority_queue<int, vector<int>, greater<int>> que; int L = 0, R = 0; rep(i, n) { while (que.size() && que.top() < (i + 1)) { L--; que.pop(); } l[i] = L; L++; que.push((i + 1) + a[i]); } priority_queue<int> que2; for (int i = n - 1; i >= 0; i--) { while (que2.size() && que2.top() > (i + 1)) { R--; que2.pop(); } r[i] = R; R++; que2.push((i + 1) - a[i]); } rep(i, n) { a[i] = l[i] + r[i] + 1; } } for (auto x : a) { cout << x << " "; } cout << endl; }
replace
32
33
32
33
TLE
p02647
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define DEBUG #define PI 3.141592653589793238462643383279 #define _GLIBCXX_DEBUG #ifdef DEBUG #define s(...) show(__VA_ARGS__); #define sl(...) \ show(__VA_ARGS__); \ cout << endl; #else #define s(...) #define sl(...) #endif void show() {} template <class Head, class... Args> void show(Head t, Args... args) { std::cout << t << " "; show(args...); } #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define REPR1(i, n) for (ll i = n; i >= 1; i--) #define FOR1(i, m, n) for (ll i = m; i <= n; i++) const ll INF = LLONG_MAX; const ull MOD = 1000000007; #define VEC(type, A, N) vector<type> A(N) #define VECi(type, A, N, i) vector<type> A(N, i) #define VEC2(type, A, N, M) vector<vector<type>> A(N, vector<type>(M)) #define VEC2i(type, A, N, M, i) vector<vector<type>> A(N, vector<type>(M, i)) #define ALL(v) v.begin(), v.end() ll frac(ll k) { int s = 1; for (ll i = 1; i <= k; ++i) s *= i; return s; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll antidiv(ll N, ll C, ll D) { return N - floor(N / C) - floor(N / D) + floor(N / lcm(C, D)); } vector<ll> yakusuu(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(ret.begin(), ret.end()); return ret; } ll digitPoor(ll n) { assert(INT_MAX == 2147483647); assert(n >= 0); if (n < 10) return 1; if (n < 100) return 2; if (n < 1000) return 3; if (n < 10000) return 4; if (n < 100000) return 5; if (n < 1000000) return 6; if (n < 10000000) return 7; if (n < 100000000) return 8; if (n < 1000000000) return 9; return 10; } struct p { ll x; bool end; }; int main() { ll N, K; cin >> N >> K; VEC(ll, A, N); REP(i, N) { cin >> A[i]; } REP(i, K) { bool allN = true; VEC(p, ps, 0); REP(j, N) { ll t = j - A[j] < 0 ? 0 : j - A[j]; ll tt = j + A[j] > N - 1 ? N - 1 : j + A[j]; ps.push_back({t, false}); ps.push_back({tt, true}); } sort(ALL(ps), [](p a, p b) { if (a.x > b.x) { return 0; } else if (a.x < b.x) { return 1; } }); ll cu = 0, nowcu = 0, bef = 0; REP(j, N * 2) { p pp = ps[j]; if (pp.x == bef + 1) { // cout<<nowcu<<" "; // sl(pp.x-1,"=",nowcu) A[pp.x - 1] = nowcu; if (A[pp.x - 1] != N) allN = false; nowcu = cu; } else if (pp.x > bef + 1) { ll tttt = pp.x - bef; // sl(pp.x-tttt,"=",nowcu) A[pp.x - tttt] = nowcu; // cout<<nowcu<<" "; while (--tttt > 0) { // cout<<cu<<" "; // sl(pp.x-tttt,"==",cu) A[pp.x - tttt] = cu; if (A[pp.x - tttt] != N) allN = false; } nowcu = cu; } if (pp.end == false) { cu++; nowcu++; } else { cu--; } bef = pp.x; // sl("nowcu=",nowcu,"cu=",cu) } ll tttt = N - bef; while (--tttt >= 0) { // cout<<nowcu<<" "; // sl(N-tttt-1,nowcu) A[N - tttt - 1] = nowcu; if (A[N - tttt - 1] != N) allN = false; } if (allN) break; } REP(i, N) { cout << A[i] << " "; } // cout<<fixed<<setprecision(32)<<m; // sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];}); // if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No"; cout << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define DEBUG #define PI 3.141592653589793238462643383279 #define _GLIBCXX_DEBUG #ifdef DEBUG #define s(...) show(__VA_ARGS__); #define sl(...) \ show(__VA_ARGS__); \ cout << endl; #else #define s(...) #define sl(...) #endif void show() {} template <class Head, class... Args> void show(Head t, Args... args) { std::cout << t << " "; show(args...); } #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define REPR1(i, n) for (ll i = n; i >= 1; i--) #define FOR1(i, m, n) for (ll i = m; i <= n; i++) const ll INF = LLONG_MAX; const ull MOD = 1000000007; #define VEC(type, A, N) vector<type> A(N) #define VECi(type, A, N, i) vector<type> A(N, i) #define VEC2(type, A, N, M) vector<vector<type>> A(N, vector<type>(M)) #define VEC2i(type, A, N, M, i) vector<vector<type>> A(N, vector<type>(M, i)) #define ALL(v) v.begin(), v.end() ll frac(ll k) { int s = 1; for (ll i = 1; i <= k; ++i) s *= i; return s; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll antidiv(ll N, ll C, ll D) { return N - floor(N / C) - floor(N / D) + floor(N / lcm(C, D)); } vector<ll> yakusuu(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(ret.begin(), ret.end()); return ret; } ll digitPoor(ll n) { assert(INT_MAX == 2147483647); assert(n >= 0); if (n < 10) return 1; if (n < 100) return 2; if (n < 1000) return 3; if (n < 10000) return 4; if (n < 100000) return 5; if (n < 1000000) return 6; if (n < 10000000) return 7; if (n < 100000000) return 8; if (n < 1000000000) return 9; return 10; } struct p { ll x; bool end; }; int main() { ll N, K; cin >> N >> K; VEC(ll, A, N); REP(i, N) { cin >> A[i]; } REP(i, K) { bool allN = true; VEC(p, ps, 0); REP(j, N) { ll t = j - A[j] < 0 ? 0 : j - A[j]; ll tt = j + A[j] > N - 1 ? N - 1 : j + A[j]; ps.push_back({t, false}); ps.push_back({tt, true}); } sort(ALL(ps), [](p a, p b) { if (a.x > b.x) { return 0; } else if (a.x < b.x) { return 1; } return 0; }); ll cu = 0, nowcu = 0, bef = 0; REP(j, N * 2) { p pp = ps[j]; if (pp.x == bef + 1) { // cout<<nowcu<<" "; // sl(pp.x-1,"=",nowcu) A[pp.x - 1] = nowcu; if (A[pp.x - 1] != N) allN = false; nowcu = cu; } else if (pp.x > bef + 1) { ll tttt = pp.x - bef; // sl(pp.x-tttt,"=",nowcu) A[pp.x - tttt] = nowcu; // cout<<nowcu<<" "; while (--tttt > 0) { // cout<<cu<<" "; // sl(pp.x-tttt,"==",cu) A[pp.x - tttt] = cu; if (A[pp.x - tttt] != N) allN = false; } nowcu = cu; } if (pp.end == false) { cu++; nowcu++; } else { cu--; } bef = pp.x; // sl("nowcu=",nowcu,"cu=",cu) } ll tttt = N - bef; while (--tttt >= 0) { // cout<<nowcu<<" "; // sl(N-tttt-1,nowcu) A[N - tttt - 1] = nowcu; if (A[N - tttt - 1] != N) allN = false; } if (allN) break; } REP(i, N) { cout << A[i] << " "; } // cout<<fixed<<setprecision(32)<<m; // sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];}); // if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No"; cout << endl; return 0; }
insert
117
117
117
118
0