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
p02953
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int N = 0; int max = 0; int H[10000] = {0}; cin >> N; for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = N - 1; i > 0; i--) { if (H[i] + 1 == H[i - 1]) { H[i - 1] -= 1; } if (H[i] + 1 < H[i - 1]) { cout << "No"; return 0; } } cout << "Yes"; }
#include <iostream> #include <string> using namespace std; int main() { long long int N = 0; long long int max = 0; long long int H[100000] = {0}; cin >> N; for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = N - 1; i > 0; i--) { if (H[i] + 1 == H[i - 1]) { H[i - 1] -= 1; } if (H[i] + 1 < H[i - 1]) { cout << "No"; return 0; } } cout << "Yes"; }
replace
5
8
5
8
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define oset \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i; cin >> n; vector<long long int> num(n); for (i = 0; i < n; i++) { cin >> num[i]; } long long int l = num[0]; for (i = 1; i < n; i++) { if (num[i] > l) { num[i--]; } else if (num[i] < l) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define oset \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i; cin >> n; vector<long long int> num(n); for (i = 0; i < n; i++) { cin >> num[i]; } long long int maxi = INT_MIN; for (i = 0; i < n; i++) { if (num[i] > maxi) { maxi = num[i]; } else { if (maxi - num[i] >= 2) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
replace
21
28
21
30
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; while (cin >> N) { int a[10005], i, flag = 1; for (i = 0; i < N; i++) scanf("%d", &a[i]); a[0]--; for (i = 1; i < N; i++) { if (a[i] < a[i - 1]) { flag = 0; break; } if (a[i] > a[i - 1]) a[i]--; } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; while (cin >> N) { int a[100005], i, flag = 1; for (i = 0; i < N; i++) scanf("%d", &a[i]); a[0]--; for (i = 1; i < N; i++) { if (a[i] < a[i - 1]) { flag = 0; break; } if (a[i] > a[i - 1]) a[i]--; } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
replace
9
10
9
10
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a[10010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) if (a[i] > a[i + 1]) { if (a[i] - a[i + 1] >= 2) { printf("No"); return 0; } a[i + 1]++; } printf("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) if (a[i] > a[i + 1]) { if (a[i] - a[i + 1] >= 2) { printf("No"); return 0; } a[i + 1]++; } printf("Yes"); return 0; }
replace
2
3
2
3
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { // 整数の入力 int n; int a[100000]; bool flag[100000]; int count, count_s; unsigned int ans = 0; int counts = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { if (flag[i] == false) { a[i] -= 1; flag[i] = true; i = -1; } else { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // 整数の入力 int n; int a[100000]; bool flag[100000]; int count, count_s; unsigned int ans = 0; int counts = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { if (flag[i] == false) { a[i] -= 1; flag[i] = true; i = i - 2; } else { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
replace
21
22
21
22
TLE
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // g++ -g -o yourexe yourfile.cpp //./yourexe < yourinput.in > youroutput.out #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define M 1000000007 #define ll long long #define ld long double #define vi vector<ll> #define pi pair<ll, ll> #define vii vector<pi> #define vvi vector<vi> #define pb push_back #define endl "\n" #define REP(i, s, e) for (ll i = s; i < e; i++) #define RREP(i, s, e) for (ll i = s; i > e; i--) #define all(v) v.begin(), v.end() #define part(v, s, e) v.begin() + s, v.begin() + e #define print(v) \ for (auto i : v) \ cout << i << " "; int main() { fast; ll a = 0, n; cin >> n; vi arr(n); REP(i, 0, n) cin >> arr[i]; vi diff(n - 1); REP(i, 0, n - 1) diff[i] = arr[i + 1] - arr[i]; for (ll i = 0; i < n - 1; i++) { ll j = i, c = 0; while (j < n - 1 && diff[j] <= 0) { c += diff[j]; j++; } a = min(a, c); j = i; } if (a < -1) cout << "No\n"; else cout << "Yes\n"; return 0; }
#include <bits/stdc++.h> using namespace std; // g++ -g -o yourexe yourfile.cpp //./yourexe < yourinput.in > youroutput.out #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define M 1000000007 #define ll long long #define ld long double #define vi vector<ll> #define pi pair<ll, ll> #define vii vector<pi> #define vvi vector<vi> #define pb push_back #define endl "\n" #define REP(i, s, e) for (ll i = s; i < e; i++) #define RREP(i, s, e) for (ll i = s; i > e; i--) #define all(v) v.begin(), v.end() #define part(v, s, e) v.begin() + s, v.begin() + e #define print(v) \ for (auto i : v) \ cout << i << " "; int main() { fast; ll a = 0, n; cin >> n; vi arr(n); REP(i, 0, n) cin >> arr[i]; vi diff(n - 1); REP(i, 0, n - 1) diff[i] = arr[i + 1] - arr[i]; for (ll i = 0; i < n - 1; i++) { ll j = i, c = 0; while (j < n - 1 && diff[j] <= 0) { c += diff[j]; j++; } a = min(a, c); i = j; } if (a < -1) cout << "No\n"; else cout << "Yes\n"; return 0; }
replace
48
49
48
49
TLE
p02953
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <vector> typedef long long LL; #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { LL N; cin >> N; vector<LL> H(N); rep(i, N) { cin >> H[i]; } rep(i, N) { LL comp = H[N - i - 1]; LL max_elem = *max_element(H.begin(), H.end() - i - 1); if (max_elem - 1 <= comp) { continue; } else { cout << "No"; return 0; } } cout << "Yes"; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <vector> typedef long long LL; #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { LL N; cin >> N; vector<LL> H(N); rep(i, N) { cin >> H[i]; } bool noflag = false; for (int i = N - 1; i > 0; i--) { LL comp = H[i] - H[i - 1]; if (comp == -1) { H[i - 1]--; } else if (comp <= -2) { cout << "No"; return 0; } } cout << "Yes"; return 0; }
replace
17
23
17
24
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H.at(i); } int ans = 1; for (int i = N; i > 0; i--) { if (H.at(i) < H.at(i - 1)) { H.at(i - 1) -= 1; if (H.at(i) < H.at(i - 1)) { ans = 0; break; } else continue; } else continue; } if (ans == 1) cout << "Yes" << endl; else if (ans == 0) cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H.at(i); } int ans = 1; for (int i = N - 1; i > 0; i--) { if (H.at(i) < H.at(i - 1)) { H.at(i - 1) -= 1; if (H.at(i) < H.at(i - 1)) { ans = 0; break; } else continue; } else continue; } if (ans == 1) cout << "Yes" << endl; else if (ans == 0) cout << "No" << endl; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <cmath> #include <iostream> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; #ifdef DEBUG #define IFD if (true) #else #define IFD if (false) #endif int main() { int N; int H[10000]; cin >> N; rep(i, N) { cin >> H[i]; } rep(i, N - 1) { if (H[i] < H[i + 1]) { H[i + 1]--; } if (H[i] > H[i + 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <cmath> #include <iostream> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; #ifdef DEBUG #define IFD if (true) #else #define IFD if (false) #endif int main() { int N; int H[100000]; cin >> N; rep(i, N) { cin >> H[i]; } rep(i, N - 1) { if (H[i] < H[i + 1]) { H[i + 1]--; } if (H[i] > H[i + 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
15
16
15
16
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; vector<int> h(n); rep(i, n) { cin >> h.at(i); } h.at(0)--; bool b = true; rep(i, n - 1) { if (h.at(i) < h.at(i + 1)) { h.at(i + 1)--; } if (h.at(i) > h.at(i + 1)) { b = false; break; } // cout<<h.at(i)<<" "; } if (h.at(n - 2) > h.at(n - 1)) b = false; if (b) cout << "Yes"; else { cout << "No"; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; vector<int> h(n); rep(i, n) { cin >> h.at(i); } h.at(0)--; bool b = true; rep(i, n - 1) { if (h.at(i) < h.at(i + 1)) { h.at(i + 1)--; } if (h.at(i) > h.at(i + 1)) { b = false; break; } // cout<<h.at(i)<<" "; } if (n != 1) { if (h.at(n - 2) > h.at(n - 1)) b = false; } if (b) cout << "Yes"; else { cout << "No"; } }
replace
22
24
22
26
0
p02953
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const long long mod = 1000000007; typedef long long ll; int main() { int n; cin >> n; vector<double> a(n); rep(i, n) { cin >> a.at(i); } rep(i, n) { if (n == 1) { cout << "Yes" << endl; break; } if (a.at(i + 1) == a.at(i)) continue; else if (a.at(i + 1) > a.at(i)) a.at(i + 1)--; else if (a.at(i + 1) < a.at(i)) { cout << "No" << endl; break; } if (i == (n - 2)) { cout << "Yes" << endl; break; } } return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const long long mod = 1000000007; typedef long long ll; int main() { int n; cin >> n; vector<double> a(n); rep(i, n) { cin >> a.at(i); } rep(i, n) { if (n == 1) { cout << "Yes" << endl; break; } if (a.at(i + 1) > a.at(i)) a.at(i + 1)--; else if (a.at(i + 1) < a.at(i)) { cout << "No" << endl; break; } if (i == (n - 2)) { cout << "Yes" << endl; break; } } return 0; }
replace
25
28
25
26
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; vector<int> H(N); rep(i, N) cin >> H.at(i); string ans = "Yes"; if (N != 1) { H.at(0)--; for (int i = 1; i < N; i++) { if (H.at(i - 1) == H.at(i)) { if (H.at(i) > H.at(i + 1)) { ans = "No"; break; } } else if (H.at(i - 1) < H.at(i)) H.at(i)--; else if (H.at(i - 1) > H.at(i)) { ans = "No"; break; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; vector<int> H(N); rep(i, N) cin >> H.at(i); string ans = "Yes"; if (N != 1) { H.at(0)--; for (int i = 1; i < N; i++) { if (H.at(i - 1) == H.at(i)) continue; else if (H.at(i - 1) < H.at(i)) H.at(i)--; else if (H.at(i - 1) > H.at(i)) { ans = "No"; break; } } } cout << ans << endl; }
replace
17
23
17
20
0
p02953
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = 0; i < N - 1; i++) { int h = H[i]; int h_min = *min_element(H.begin() + i + 1, H.end()); if (h - h_min >= 2) { cout << "No"; return 0; } } cout << "Yes"; return 0; } int main1() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } /* for (int i = 0; i < N; i++) { cerr << H[i] << " "; } cerr << endl; */ for (int i = 0; i < N - 1; i++) { if (H[i] > H[i + 1]) { H[i]--; } } /* for (int i = 0; i < N; i++) { cerr << H[i] << " "; } cerr << endl; */ for (int i = 0; i < N - 1; i++) { if (H[i] > H[i + 1]) { cout << "No"; return 0; } } cout << "Yes"; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = N - 2; i >= 0; --i) { if (H[i] == (H[i + 1] + 1)) { H[i]--; } else if (H[i] > (H[i + 1] + 1)) { cout << "No"; return 0; } } for (int i = 0; i < N - 1; i++) { if (H[i] > H[i + 1]) { cout << "No"; return 0; } } cout << "Yes"; return 0; } int main2() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } //! �����̉E���̗v�f��2�ȏ㏬�����̂����邩���ׂ� for (int i = 0; i < N - 1; i++) { int h = H[i]; int h_min = *min_element(H.begin() + i + 1, H.end()); if (h - h_min >= 2) { cout << "No"; return 0; } } cout << "Yes"; return 0; } int main1() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) { cin >> H[i]; } /* for (int i = 0; i < N; i++) { cerr << H[i] << " "; } cerr << endl; */ for (int i = 0; i < N - 1; i++) { if (H[i] > H[i + 1]) { H[i]--; } } /* for (int i = 0; i < N; i++) { cerr << H[i] << " "; } cerr << endl; */ for (int i = 0; i < N - 1; i++) { if (H[i] > H[i + 1]) { cout << "No"; return 0; } } cout << "Yes"; return 0; }
insert
14
14
14
43
TLE
p02953
C++
Runtime Error
#include <cstdio> int n, a[10001], i; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = n - 1; i > 0; i--) { if (a[i] < a[i - 1]) a[i - 1]--; if (a[i - 1] == 0 || a[i - 1] > a[i]) { printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
#include <cstdio> int n, a[1000001], i; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = n - 1; i > 0; i--) { if (a[i] < a[i - 1]) a[i - 1]--; if (a[i - 1] == 0 || a[i - 1] > a[i]) { printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
replace
2
3
2
3
0
p02953
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; const int N = 100000 + 10; int a[N], n; bool vis[N]; int main() { scanf("%d", &n); a[0] = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { if (i - 1 && a[i - 1] > a[i]) { if (!vis[a[i - 1]]) { a[i - 1]--; vis[i - 1] = 1; if (a[i - 1] > a[i]) { printf("No"); return 0; } else { int k = i - 2; if (k) while (k && a[k] > a[k + 1]) { if (vis[k]) { printf("No"); return 0; } else { a[k]--; vis[k] = 1; if (a[k] > a[k + 1]) { printf("No"); return 0; } } k--; } } } else { printf("No"); return 0; } } } cout << "Yes"; return 0; }
#include <cstdio> #include <iostream> using namespace std; const int N = 100000 + 10; int a[N], n; bool vis[N]; int main() { scanf("%d", &n); a[0] = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { if (i - 1 && a[i - 1] > a[i]) { if (!vis[i - 1]) { a[i - 1]--; vis[i - 1] = 1; if (a[i - 1] > a[i]) { printf("No"); return 0; } else { int k = i - 2; if (k) while (k && a[k] > a[k + 1]) { if (vis[k]) { printf("No"); return 0; } else { a[k]--; vis[k] = 1; if (a[k] > a[k + 1]) { printf("No"); return 0; } } k--; } } } else { printf("No"); return 0; } } } cout << "Yes"; return 0; }
replace
14
15
14
15
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int n; cin >> n; int h[n]; rep(i, n) cin >> h[i]; int max = 0; rep(i, n) { if (h[i] > max) { max = h[i]; for (int j = i; j < n; j++) { if (h[i] - 1 > h[j]) { puts("No"); return 0; } } } } puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int n; cin >> n; int h[n]; rep(i, n) cin >> h[i]; int max = 0; rep(i, n) { if (h[i] > max) { max = h[i]; for (int j = i; j < n; j++) { if (h[j] > max) max = h[j]; if (max - 1 > h[j]) { puts("No"); return 0; } } } } puts("Yes"); return 0; }
replace
16
17
16
19
TLE
p02953
C++
Runtime Error
#include <iostream> using namespace std; int a[10005]; int main() { int n, maxh = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; maxh = a[1]; for (int i = 2; i <= n; i++) { if (a[i] - maxh <= -2) { cout << "No"; return 0; } maxh = max(a[i], maxh); } cout << "Yes"; return 0; }
#include <iostream> using namespace std; int a[100005]; int main() { int n, maxh = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; maxh = a[1]; for (int i = 2; i <= n; i++) { if (a[i] - maxh <= -2) { cout << "No"; return 0; } maxh = max(a[i], maxh); } cout << "Yes"; return 0; }
replace
2
3
2
3
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> h(n); for (int i = 0; i < n; i++) { cin >> h.at(i); } string ans = "Yes"; for (int i = 0; i < n - 1; i++) { if (h.at(i) - 1 > h.at(i + 1)) { ans = "No"; break; } if (i < n - 1 && h.at(i) - 1 > h.at(i + 2)) { ans = "No"; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> h(n); for (int i = 0; i < n; i++) { cin >> h.at(i); } string ans = "Yes"; for (int i = 0; i < n; i++) { if (i == 0) { h.at(i) -= 1; } else { if (h.at(i) < h.at(i - 1)) { ans = "No"; break; } else if (h.at(i) > h.at(i - 1)) { h.at(i) -= 1; } } } cout << ans << endl; }
replace
11
19
11
21
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int N; unsigned long long int H[10000]; cin >> N; H[0] = 0; for (int i = 1; i <= N; ++i) { cin >> H[i]; } for (int i = 1; i <= N; ++i) { int d = H[i] - H[i - 1]; if (d >= 1) { --H[i]; } else if (d == 0) { ; } else { cout << "No"; return 0; } } cout << "Yes"; return 0; }
#include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int N; unsigned long long int H[100000]; cin >> N; H[0] = 0; for (int i = 1; i <= N; ++i) { cin >> H[i]; } for (int i = 1; i <= N; ++i) { int d = H[i] - H[i - 1]; if (d >= 1) { --H[i]; } else if (d == 0) { ; } else { cout << "No"; return 0; } } cout << "Yes"; return 0; }
replace
10
11
10
11
0
p02953
C++
Runtime Error
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; using ll = long long; const ll INF = (ll)1e18 + 1; const ll DIV = 1000000007; // #define TEST int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef TEST chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); #endif long N; cin >> N; vector<long> H(N); for (size_t i = 0; i < N; i++) { cin >> H[i]; } for (long i = N - 1; i >= 0; i--) { if (H[i] < H[i - 1]) H[i - 1]--; } bool ok = true; for (size_t i = 1; i < N; i++) { if (H[i] < H[i - 1]) ok = false; } if (ok) cout << "Yes" << endl; else cout << "No" << endl; #ifdef TEST end = chrono::system_clock::now(); cerr << static_cast<double>( chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl; #endif return 0; }
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; using ll = long long; const ll INF = (ll)1e18 + 1; const ll DIV = 1000000007; // #define TEST int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef TEST chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); #endif long N; cin >> N; vector<long> H(N); for (size_t i = 0; i < N; i++) { cin >> H[i]; } for (long i = N - 1; i >= 1; i--) { if (H[i] < H[i - 1]) H[i - 1]--; } bool ok = true; for (size_t i = 1; i < N; i++) { if (H[i] < H[i - 1]) ok = false; } if (ok) cout << "Yes" << endl; else cout << "No" << endl; #ifdef TEST end = chrono::system_clock::now(); cerr << static_cast<double>( chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl; #endif return 0; }
replace
31
32
31
32
0
p02953
C++
Runtime Error
#include <algorithm> #include <iostream> #include <list> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; stack<long> h; for (int i = 0; i < n; i++) { long n; cin >> n; h.push(n); } long bef = h.top(); h.pop(); for (int i = 0; i < n; i++) { long now = h.top(); h.pop(); if (now <= bef) { bef = now; continue; } if (now - bef == 1) { bef = now - 1; continue; } printf("No"); return 0; } printf("Yes"); return 0; }
#include <algorithm> #include <iostream> #include <list> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; stack<long> h; for (int i = 0; i < n; i++) { long n; cin >> n; h.push(n); } long bef = h.top(); h.pop(); for (int i = 1; i < n; i++) { long now = h.top(); h.pop(); if (now <= bef) { bef = now; continue; } if (now - bef == 1) { bef = now - 1; continue; } printf("No"); return 0; } printf("Yes"); return 0; }
replace
25
26
25
26
-11
p02953
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } for (int i = N - 1; i >= 0; i--) { if (vec[i - 1] > vec[i]) { vec[i - 1] = vec[i - 1] - 1; } } bool higensyou = true; for (int i = 0; i < N - 1; i++) { if (vec[i] > vec[i + 1]) { higensyou = false; break; } } if (higensyou) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } for (int i = N - 1; i > 0; i--) { if (vec[i - 1] > vec[i]) { vec[i - 1] = vec[i - 1] - 1; } } bool higensyou = true; for (int i = 0; i < N - 1; i++) { if (vec[i] > vec[i + 1]) { higensyou = false; break; } } if (higensyou) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
12
13
12
13
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a[10005], ma; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); ma = max(a[i], ma); if (ma - a[i] > 1) { puts("No"); return 0; } } puts("Yes"); }
#include <bits/stdc++.h> using namespace std; int n, a[100005], ma; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); ma = max(a[i], ma); if (ma - a[i] > 1) { puts("No"); return 0; } } puts("Yes"); }
replace
2
3
2
3
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long H[100000]; for (long long i = 0; i < N; i++) { cin >> H[i]; } bool ans = true; for (long long i = 0; i < N - 1; i++) { for (long long j = i + 1; j < N - 1; j++) { if (H[i] - H[j + 1] >= 2) { ans = false; break; } } } if (ans) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long H[100000]; for (long long i = 0; i < N; i++) { cin >> H[i]; } bool ans = true; for (long long i = N - 1; i > 0; i--) { if (H[i - 1] - H[i] > 1) { ans = false; break; } else if (H[i - 1] - H[i] == 1) { H[i - 1] -= 1; } } if (ans) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
12
18
12
19
TLE
p02953
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; int main() { int n; cin >> n; vector<int> h(n); rep(i, n) cin >> h[i]; if (h[0] > h[1]) { cout << "No\n"; return 0; } for (int i = 1; i < n - 1; i++) { if (h[i] - h[i + 1] == 1) { h[i]--; if (h[i - 1] - h[i] > 0) { cout << "No\n"; return 0; } } else if (h[i] - h[i + 1] >= 2) { cout << "No\n"; return 0; } } cout << "Yes\n"; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; int main() { int n; cin >> n; vector<int> h(n); rep(i, n) cin >> h[i]; int pre = -999; rep(i, n) { if (pre <= h[i] - 1) { pre = h[i] - 1; } else if (pre <= h[i]) { pre = h[i]; } else { puts("No"); return 0; } } cout << "Yes\n"; }
replace
15
28
15
23
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #define oo 0x3f3f3f3f #define OO 0x3f3f3f3f3f3f3f3f #define popcount(n) __builtin_popcount(n) #define popcountll(n) __builtin_popcountll(n) using namespace std; // using namespace __gnu_cxx; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const double PI = acos(-1.0), EPS = 1e-6; const long long inf = 2e12 + 12; const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20; int main() { #ifndef ONLINE_JUDGE // freopen("input.txt", "rt", stdin); // freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed; string s; cin >> s; vector<int> lft(s.size()); vector<int> right(s.size()); int lst = 0; for (int i = 0; i < s.size(); ++i) { lst = (s[i] == 'R' ? i : lst); lft[i] = lst; } lst = s.size() - 1; for (int i = s.size() - 1; i >= 0; --i) { lst = (s[i] == 'L' ? i : lst); right[i] = lst; } vector<int> ans(s.size(), 0); for (int i = 0; i < s.size(); ++i) { if (s[i] == 'R') { ans[right[i] - ((right[i] - i) & 1)]++; } else { ans[lft[i] - ((i - lft[i]) & 1)]++; } } for (int i = 0; i < s.size(); ++i) { cout << ans[i] << ' '; } cout << '\n'; return 0; }
#include <bits/stdc++.h> // #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #define oo 0x3f3f3f3f #define OO 0x3f3f3f3f3f3f3f3f #define popcount(n) __builtin_popcount(n) #define popcountll(n) __builtin_popcountll(n) using namespace std; // using namespace __gnu_cxx; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const double PI = acos(-1.0), EPS = 1e-6; const long long inf = 2e12 + 12; const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20; int main() { #ifndef ONLINE_JUDGE // freopen("input.txt", "rt", stdin); // freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed; string s; cin >> s; vector<int> lft(s.size()); vector<int> right(s.size()); int lst = 0; for (int i = 0; i < s.size(); ++i) { lst = (s[i] == 'R' ? i : lst); lft[i] = lst; } lst = s.size() - 1; for (int i = s.size() - 1; i >= 0; --i) { lst = (s[i] == 'L' ? i : lst); right[i] = lst; } vector<int> ans(s.size(), 0); for (int i = 0; i < s.size(); ++i) { if (s[i] == 'R') { ans[right[i] - ((right[i] - i) & 1)]++; } else { ans[lft[i] + ((i - lft[i]) & 1)]++; } } for (int i = 0; i < s.size(); ++i) { cout << ans[i] << ' '; } cout << '\n'; return 0; }
replace
49
50
49
50
0
p02954
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; const int N = 1e3 + 3; int a[N]; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); string s; cin >> s; int l = s.length(); int now = 0; for (int i = 0; i < l; i++) { if (s[i] == 'R') now++; else { if (now & 1) a[i - 1] += now / 2 + 1, a[i] += now / 2; else a[i] += now / 2, a[i - 1] += now / 2; now = 0; } } now = 0; for (int i = l - 1; ~i; i--) { if (s[i] == 'L') now++; else { if (now & 1) a[i + 1] += now / 2 + 1, a[i] += now / 2; else a[i] += now / 2, a[i + 1] += now / 2; now = 0; } } for (int i = 0; i < l; i++) cout << a[i] << ' '; return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; const int N = 1e5 + 3; int a[N]; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); string s; cin >> s; int l = s.length(); int now = 0; for (int i = 0; i < l; i++) { if (s[i] == 'R') now++; else { if (now & 1) a[i - 1] += now / 2 + 1, a[i] += now / 2; else a[i] += now / 2, a[i - 1] += now / 2; now = 0; } } now = 0; for (int i = l - 1; ~i; i--) { if (s[i] == 'L') now++; else { if (now & 1) a[i + 1] += now / 2 + 1, a[i] += now / 2; else a[i] += now / 2, a[i + 1] += now / 2; now = 0; } } for (int i = 0; i < l; i++) cout << a[i] << ' '; return 0; }
replace
4
5
4
5
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; // typedef vector<unsigned int>vec; typedef vector<ll> vec; // typedef vector<vec> mat; typedef vector<vector<int>> Graph; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const ll LINF = 1000000000000000000; // 1e18 const ll MOD = 1000000007; // const ll MOD = 998244353; const double PI = acos(-1.0); const double EPS = 1e-10; 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; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; int to[44][101010]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; int N = S.size(); REP(i, N) { if (S[i] == 'R') to[0][i] = i + 1; else to[0][i] = i - 1; } REP(i, 44) { REP(j, N) to[i + 1][j] = to[i][to[i][j]]; } vector<int> ans(N); REP(i, N) ans[to[40][i]]++; REP(i, N) cout << ans[i] << " "; cout << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; // typedef vector<unsigned int>vec; typedef vector<ll> vec; // typedef vector<vec> mat; typedef vector<vector<int>> Graph; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const ll LINF = 1000000000000000000; // 1e18 const ll MOD = 1000000007; // const ll MOD = 998244353; const double PI = acos(-1.0); const double EPS = 1e-10; 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; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; int to[44][101010]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; int N = S.size(); REP(i, N) { if (S[i] == 'R') to[0][i] = i + 1; else to[0][i] = i - 1; } REP(i, 40) { REP(j, N) to[i + 1][j] = to[i][to[i][j]]; } vector<int> ans(N); REP(i, N) ans[to[40][i]]++; REP(i, N) cout << ans[i] << " "; cout << endl; }
replace
57
58
57
58
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define all(A) begin(A), end(A) #define rall(A) rbegin(A), rend(A) #define sz(A) int(A.size()) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; vector<int> arr; for (int l = 0; l < sz(s);) { int r = l; while (r + 1 < sz(s) and s[l] == s[r + 1]) r++; arr.push_back(r - l + 1); l = r + 1; } vector<int> ans(sz(s)); int cur = 0; for (int pos = 0; pos < sz(s); pos += 2) { cur = cur + arr[pos]; int l = cur - 1; int r = cur; ans[l] += (arr[pos] + 1) / 2; ans[r] += arr[pos] / 2; ans[r] += (arr[pos + 1] + 1) / 2; ans[l] += arr[pos + 1] / 2; cur += arr[pos + 1]; } for (int i = 0; i < sz(s); i++) cout << ans[i] << " \n"[i == sz(s) - 1]; return (0); }
#include <bits/stdc++.h> #define all(A) begin(A), end(A) #define rall(A) rbegin(A), rend(A) #define sz(A) int(A.size()) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; vector<int> arr; for (int l = 0; l < sz(s);) { int r = l; while (r + 1 < sz(s) and s[l] == s[r + 1]) r++; arr.push_back(r - l + 1); l = r + 1; } vector<int> ans(sz(s)); int cur = 0; for (int pos = 0; pos < sz(arr); pos += 2) { cur = cur + arr[pos]; int l = cur - 1; int r = cur; ans[l] += (arr[pos] + 1) / 2; ans[r] += arr[pos] / 2; ans[r] += (arr[pos + 1] + 1) / 2; ans[l] += arr[pos + 1] / 2; cur += arr[pos + 1]; } for (int i = 0; i < sz(s); i++) cout << ans[i] << " \n"[i == sz(s) - 1]; return (0); }
replace
28
29
28
29
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define range 524289 #define mod 1000000007 #define eps 1e-9 #define PI 3.14159265358979323846 #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define ALL(V) V.begin(), V.end() #define _ << " " << using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef pair<int, pair<int, int>> iii; typedef vector<ii> vii; typedef vector<iii> viii; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l; string a; cin >> a; n = a.size(); int rl = 0; int rc = 1; int lc = 0; int turns = 0; char curr = 'R'; int count = 0; vi res(n, 0); int i = 1; int rstart = 0; int lstart = 0; while (i < n) { if (a[i] == curr) { if (curr == 'R') { rc++; } else { lc++; } } else { if (a[i] == 'L') { lstart = i; curr = 'L'; lc++; } else { int lolr = rc + rstart - 1; int loll = lstart; int trns = max(lc, rc) - 1; turns = max(trns, turns); int sum = lc + rc; if (sum % 2) { if (lc > rc) { res[loll] = sum / 2 + sum % 2; res[lolr] = sum / 2; } else { res[lolr] = sum / 2 + sum % 2; res[loll] = sum / 2; } } else { res[loll] = sum / 2; res[lolr] = sum / 2; } if (trns == 0 || trns % 2 == 1) { swap(res[loll], res[lolr]); } rstart = i; lc = 0; rc = 1; curr = 'R'; } } i++; } int lollr = rc + rstart - 1; int lolll = lstart; int trnss = max(lc, rc) - 1; turns = max(trnss, turns); int sums = lc + rc; if (sums % 2) { if (lc > rc) { res[lolll] = sums / 2 + sums % 2; res[lollr] = sums / 2; } else { res[lollr] = sums / 2 + sums % 2; res[lolll] = sums / 2; } } else { res[lolll] = sums / 2; res[lollr] = sums / 2; } if (trnss == 0 || trnss % 2 == 1) { swap(res[lolll], res[lollr]); } for (i = 0; i < n; ++i) { cout << res[i] << " "; } return 0; }
#include <bits/stdc++.h> #define range 524289 #define mod 1000000007 #define eps 1e-9 #define PI 3.14159265358979323846 #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define ALL(V) V.begin(), V.end() #define _ << " " << using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef pair<int, pair<int, int>> iii; typedef vector<ii> vii; typedef vector<iii> viii; int main(int argc, char const *argv[]) { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l; string a; cin >> a; n = a.size(); int rl = 0; int rc = 1; int lc = 0; int turns = 0; char curr = 'R'; int count = 0; vi res(n, 0); int i = 1; int rstart = 0; int lstart = 0; while (i < n) { if (a[i] == curr) { if (curr == 'R') { rc++; } else { lc++; } } else { if (a[i] == 'L') { lstart = i; curr = 'L'; lc++; } else { int lolr = rc + rstart - 1; int loll = lstart; int trns = max(lc, rc) - 1; turns = max(trns, turns); int sum = lc + rc; if (sum % 2) { if (lc > rc) { res[loll] = sum / 2 + sum % 2; res[lolr] = sum / 2; } else { res[lolr] = sum / 2 + sum % 2; res[loll] = sum / 2; } } else { res[loll] = sum / 2; res[lolr] = sum / 2; } if (trns == 0 || trns % 2 == 1) { swap(res[loll], res[lolr]); } rstart = i; lc = 0; rc = 1; curr = 'R'; } } i++; } int lollr = rc + rstart - 1; int lolll = lstart; int trnss = max(lc, rc) - 1; turns = max(trnss, turns); int sums = lc + rc; if (sums % 2) { if (lc > rc) { res[lolll] = sums / 2 + sums % 2; res[lollr] = sums / 2; } else { res[lollr] = sums / 2 + sums % 2; res[lolll] = sums / 2; } } else { res[lolll] = sums / 2; res[lollr] = sums / 2; } if (trnss == 0 || trnss % 2 == 1) { swap(res[lolll], res[lollr]); } for (i = 0; i < n; ++i) { cout << res[i] << " "; } return 0; }
replace
25
29
25
29
-11
p02954
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); vector<int> B, C, E; B.push_back(0); for (int i = 1; i < N - 1; i++) { if (S.at(i) == 'R' && S.at(i + 1) == 'L') C.push_back(i); if (S.at(i) == 'L' && S.at(i + 1) == 'R') { E.push_back(i); B.push_back(i + 1); } } E.push_back(N - 1); int A[100010] = {}; for (int i = 0; i < B.size(); i++) { int l = C.at(i) - B.at(i) + 1; int r = E.at(i) - C.at(i); A[C.at(i)] += (l + 1) / 2; A[C.at(i) + 1] += l - (l + 1) / 2; A[C.at(i) + 1] += (r + 1) / 2; A[C.at(i)] += r - (r + 1) / 2; } for (int i = 0; i < N; i++) { cout << A[i] << " "; } cout << endl; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); vector<int> B, C, E; B.push_back(0); for (int i = 0; i < N - 1; i++) { if (S.at(i) == 'R' && S.at(i + 1) == 'L') C.push_back(i); if (S.at(i) == 'L' && S.at(i + 1) == 'R') { E.push_back(i); B.push_back(i + 1); } } E.push_back(N - 1); int A[100010] = {}; for (int i = 0; i < B.size(); i++) { int l = C.at(i) - B.at(i) + 1; int r = E.at(i) - C.at(i); A[C.at(i)] += (l + 1) / 2; A[C.at(i) + 1] += l - (l + 1) / 2; A[C.at(i) + 1] += (r + 1) / 2; A[C.at(i)] += r - (r + 1) / 2; } for (int i = 0; i < N; i++) { cout << A[i] << " "; } cout << endl; }
replace
9
10
9
10
0
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long MOD = 1000000007; long long modpow(long long a, long long n, long long m) { long long ans = 1; while (n) { if (n & 1) { ans = (ans * a) % m; } a = (a * a) % m; n >>= 1; } return ans; } long long combi(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % MOD; ans %= MOD; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % MOD; ans1 = modpow(ans1, MOD - 2, MOD); return ((ans % MOD) * ans1) % MOD; } void dfs(string s, char mx, ll N) { if (s.length() == (size_t)N) { cout << s.c_str() << endl; } else { for (char c = 'a'; c <= mx; c++) { dfs(s + c, ((c == mx) ? (char)(mx) : mx), N); } } } int bfs(int a, int b, int h, int w, char tmp[][101]) { int ans[101][101] = {0}; char c[101][101] = {0}; queue<pair<int, int>> s; for (int i = 0; i <= h; i++) { for (int j = 0; j <= w; j++) { c[i][j] = tmp[i][j]; } } s.push(make_pair(a, b)); while (s.size() > 0) { pair<int, int> tmp = s.front(); s.pop(); c[tmp.first][tmp.second] = '#'; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (tmp.first + i < 1 || tmp.first + i > h) { continue; } if (tmp.second + j < 1 || tmp.second + j > w) { continue; } if (i != 0 && j != 0) { continue; } if (i == 0 && j == 0) { continue; } if (c[tmp.first + i][tmp.second + j] == '#') { continue; } c[tmp.first + i][tmp.second + j] = '#'; if (ans[tmp.first + i][tmp.second + j] == 0) { ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1; } else { ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1); } s.push(make_pair(tmp.first + i, tmp.second + j)); } } } int asd = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { asd = max(a, ans[i][j]); } } return asd; } 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); } int main() { string s; cin >> s; vector<pair<char, ll>> v; bool f = true; ll cnt = 0; for (int i = 0; i < s.length(); i++) { if (f && s[i] == 'R') { cnt++; } else if (!f && s[i] == 'L') { cnt++; } else if (!f && s[i] == 'R') { v.push_back(make_pair('L', cnt)); f = !f; i--; cnt = 0; } else if (f && s[i] == 'L') { v.push_back(make_pair('R', cnt)); f = !f; i--; cnt = 0; } } if (f) v.push_back(make_pair('R', cnt)); else v.push_back(make_pair('L', cnt)); vector<ll> ans(s.length()); ll idx = 0; while (v.size() > 0) { pair<char, ll> r = v.front(); v.erase(v.begin()); pair<char, ll> l = v.front(); v.erase(v.begin()); ans[idx + r.second - 1] = ceil(r.second / 2.0) + floor(l.second / 2.0); ans[idx + r.second] = floor(r.second / 2.0) + ceil(l.second / 2.0); idx += r.second + l.second; } for (int i = 0; i < s.length(); i++) { printf("%lld ", ans[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long MOD = 1000000007; long long modpow(long long a, long long n, long long m) { long long ans = 1; while (n) { if (n & 1) { ans = (ans * a) % m; } a = (a * a) % m; n >>= 1; } return ans; } long long combi(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % MOD; ans %= MOD; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % MOD; ans1 = modpow(ans1, MOD - 2, MOD); return ((ans % MOD) * ans1) % MOD; } void dfs(string s, char mx, ll N) { if (s.length() == (size_t)N) { cout << s.c_str() << endl; } else { for (char c = 'a'; c <= mx; c++) { dfs(s + c, ((c == mx) ? (char)(mx) : mx), N); } } } int bfs(int a, int b, int h, int w, char tmp[][101]) { int ans[101][101] = {0}; char c[101][101] = {0}; queue<pair<int, int>> s; for (int i = 0; i <= h; i++) { for (int j = 0; j <= w; j++) { c[i][j] = tmp[i][j]; } } s.push(make_pair(a, b)); while (s.size() > 0) { pair<int, int> tmp = s.front(); s.pop(); c[tmp.first][tmp.second] = '#'; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (tmp.first + i < 1 || tmp.first + i > h) { continue; } if (tmp.second + j < 1 || tmp.second + j > w) { continue; } if (i != 0 && j != 0) { continue; } if (i == 0 && j == 0) { continue; } if (c[tmp.first + i][tmp.second + j] == '#') { continue; } c[tmp.first + i][tmp.second + j] = '#'; if (ans[tmp.first + i][tmp.second + j] == 0) { ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1; } else { ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1); } s.push(make_pair(tmp.first + i, tmp.second + j)); } } } int asd = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { asd = max(a, ans[i][j]); } } return asd; } 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); } int main() { string s; cin >> s; vector<pair<char, ll>> v; bool f = true; ll cnt = 0; for (int i = 0; i < s.length(); i++) { if (f && s[i] == 'R') { cnt++; } else if (!f && s[i] == 'L') { cnt++; } else if (!f && s[i] == 'R') { v.push_back(make_pair('L', cnt)); f = !f; i--; cnt = 0; } else if (f && s[i] == 'L') { v.push_back(make_pair('R', cnt)); f = !f; i--; cnt = 0; } } if (f) v.push_back(make_pair('R', cnt)); else v.push_back(make_pair('L', cnt)); vector<ll> ans(s.length()); ll idx = 0; for (int i = 0; i < v.size() / 2; i++) { pair<char, ll> r = v[2 * i]; pair<char, ll> l = v[2 * i + 1]; ans[idx + r.second - 1] = ceil(r.second / 2.0) + floor(l.second / 2.0); ans[idx + r.second] = floor(r.second / 2.0) + ceil(l.second / 2.0); idx += r.second + l.second; } for (int i = 0; i < s.length(); i++) { printf("%lld ", ans[i]); } printf("\n"); return 0; }
replace
141
146
141
144
TLE
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif off; int n; string s; vector<II> seg; cin >> s; n = s.length(); char finding = 'R'; char previous = 'R'; int segments = 0; vector<int> rlboundary; int countR = 1; int countL = 0; rep(i, 1, n) { // R.R..LL...L if (previous == 'R') { if (s[i] == 'L') { rlboundary.PB(i - 1); previous = 'L'; countL = 1; } else { countR++; } } else if (previous == 'L') { if (s[i] == 'R') { segments++; seg.PB(MP(countR, countL)); countR = 1; countL = 0; previous = 'R'; } else { countL++; } } } seg.PB(MP(countR, countL)); segments++; vector<int> ans(n, 0); // cout<<"segments "<<segments<<"\n"; rep(i, 0, segments) { int r = seg[i].F; int l = seg[i].S; int su = r + l; if (su & 1) { int decide = max(r, l) - 1; int small = su / 2; int big = su - small; if (r > l) { if (decide & 1) { ans[rlboundary[i]] = small; ans[rlboundary[i] + 1] = big; } else { ans[rlboundary[i]] = big; ans[rlboundary[i] + 1] = small; } } else { if (decide % 2 == 0) { ans[rlboundary[i]] = small; ans[rlboundary[i] + 1] = big; } else { ans[rlboundary[i]] = big; ans[rlboundary[i] + 1] = small; } } } else { ans[rlboundary[i]] = su / 2; ans[rlboundary[i] + 1] = su / 2; } } rep(i, 0, n) cout << ans[i] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif off; int n; string s; vector<II> seg; cin >> s; n = s.length(); char finding = 'R'; char previous = 'R'; int segments = 0; vector<int> rlboundary; int countR = 1; int countL = 0; rep(i, 1, n) { // R.R..LL...L if (previous == 'R') { if (s[i] == 'L') { rlboundary.PB(i - 1); previous = 'L'; countL = 1; } else { countR++; } } else if (previous == 'L') { if (s[i] == 'R') { segments++; seg.PB(MP(countR, countL)); countR = 1; countL = 0; previous = 'R'; } else { countL++; } } } seg.PB(MP(countR, countL)); segments++; vector<int> ans(n, 0); // cout<<"segments "<<segments<<"\n"; rep(i, 0, segments) { int r = seg[i].F; int l = seg[i].S; int su = r + l; if (su & 1) { int decide = max(r, l) - 1; int small = su / 2; int big = su - small; if (r > l) { if (decide & 1) { ans[rlboundary[i]] = small; ans[rlboundary[i] + 1] = big; } else { ans[rlboundary[i]] = big; ans[rlboundary[i] + 1] = small; } } else { if (decide % 2 == 0) { ans[rlboundary[i]] = small; ans[rlboundary[i] + 1] = big; } else { ans[rlboundary[i]] = big; ans[rlboundary[i] + 1] = small; } } } else { ans[rlboundary[i]] = su / 2; ans[rlboundary[i] + 1] = su / 2; } } rep(i, 0, n) cout << ans[i] << " "; return 0; }
replace
83
87
83
87
-11
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MN 100005 char ch[MN], f[MN], tot[MN]; int Find(int a) { return a == f[a] ? a : Find(f[a]); } int main() { scanf("%s", ch + 1); int n = strlen(ch + 1); for (int i = 1; i <= n; ++i) f[i] = i; for (int i = 1; i <= n; ++i) { if (ch[i] == 'L') f[i] = Find(i - 1); if (ch[i] == 'R' && ch[i + 1] == 'R') f[i] = Find(i + 1); } for (int i = 1; i <= n; ++i) { if (ch[i] == 'L') f[i] = Find(i - 1); if (ch[i] == 'R' && ch[i + 1] == 'R') f[i] = Find(i + 1); int ans = ((abs(f[i] - i)) & 1) ? (f[i] + 1) : f[i]; tot[ans]++; } for (int i = 1; i <= n; ++i) printf("%d ", tot[i]); return 0; }
#include <bits/stdc++.h> using namespace std; #define MN 100055 char ch[MN]; int f[MN], tot[MN]; int Find(int a) { return a == f[a] ? a : (f[a] = Find(f[a])); } int main() { scanf("%s", ch + 1); int n = strlen(ch + 1); for (int i = 1; i <= n; ++i) f[i] = i; for (int i = 1; i <= n; ++i) { if (ch[i] == 'L') f[i] = Find(i - 1); if (ch[i] == 'R' && ch[i + 1] == 'R') f[i] = Find(i + 1); } for (int i = 1; i <= n; ++i) { if (ch[i] == 'L') f[i] = Find(i - 1); if (ch[i] == 'R' && ch[i + 1] == 'R') f[i] = Find(i + 1); int ans = ((abs(f[i] - i)) & 1) ? (f[i] + 1) : f[i]; tot[ans]++; } for (int i = 1; i <= n; ++i) printf("%d ", tot[i]); return 0; }
replace
2
5
2
6
0
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); string s; cin >> s; vector<int> v(s.size(), 0); for (int i = 0; i < s.size(); ++i) { int cnt = 0; if (s.at(i) == 'R') { for (int j = i; s.at(j) == s.at(i); ++j) { ++cnt; } } else for (int j = i; s.at(j) == s.at(i); --j) { --cnt; } if (cnt % 2) { if (s.at(i) == 'R') ++v.at(i + cnt - 1); else ++v.at(i + cnt + 1); } else ++v.at(i + cnt); } for (auto &&i : v) cout << " "s << i; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); string s; cin >> s; vector<int> v(s.size(), 0); for (int i = 0;;) { while (i < s.size() && s.at(i) != 'R') ++i; if (i >= s.size()) break; int st = i; while (s.at(i) == 'R') ++i; v.at(i) += (i - st) / 2; v.at(i - 1) += (i - st + 1) / 2; } for (int i = s.size() - 1;;) { while (i >= 0 && s.at(i) != 'L') --i; if (i < 0) break; int st = i; while (s.at(i) == 'L') --i; v.at(i) += (st - i) / 2; v.at(i + 1) += (st - i + 1) / 2; } for (auto &&i : v) cout << " "s << i; }
replace
8
25
8
29
TLE
p02954
C++
Runtime Error
/*==============================================*\ ID: shahidul_brur Name: Md. Shahidul Islam Study: CSE, BRUR Address: Rangpur, Bangladesh mail: shahidul.cse.brur@gmail.com FB : fb.com/shahidul.brur Blog: shahidul-brur.blogspot.com(in Bengali), shahidul-brur-en.blogspot.com(in English) \*===============================================*/ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f2(i, a, b) for (int i = (a); i <= (b); i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const double pi = acos(-1.0); const double eps = 1e-6; const int mod = (int)1e9 + 7; const int maxn = (int)2e5 + 5; const int logn = 20; int c[maxn], n, last[maxn]; string s; int main() { // ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> s; n = s.size(); f0(i, n) { if (s[i] == 'R') { int j = i + 1; while (s[j] != 'L') ++j; f2(k, i, j - 1) last[k] = j; i = j; } } fr(i, n - 1, 0) { if (s[i] == 'L') { int j = i - 1; while (s[j] != 'R') --j; f2(k, j + 1, i) last[k] = j; i = j; } } f0(i, n) { if (abs(i - last[i]) % 2 == 0) c[last[i]]++; else { if (s[i] == 'L') c[last[i] + 1]++; else c[last[i] - 1]++; } } f0(i, n) cout << c[i] << " "; return 0; }
/*==============================================*\ ID: shahidul_brur Name: Md. Shahidul Islam Study: CSE, BRUR Address: Rangpur, Bangladesh mail: shahidul.cse.brur@gmail.com FB : fb.com/shahidul.brur Blog: shahidul-brur.blogspot.com(in Bengali), shahidul-brur-en.blogspot.com(in English) \*===============================================*/ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f2(i, a, b) for (int i = (a); i <= (b); i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const double pi = acos(-1.0); const double eps = 1e-6; const int mod = (int)1e9 + 7; const int maxn = (int)2e5 + 5; const int logn = 20; int c[maxn], n, last[maxn]; string s; int main() { // ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> s; n = s.size(); f0(i, n) { if (s[i] == 'R') { int j = i + 1; while (s[j] != 'L') ++j; f2(k, i, j - 1) last[k] = j; i = j; } } fr(i, n - 1, 0) { if (s[i] == 'L') { int j = i - 1; while (s[j] != 'R') --j; f2(k, j + 1, i) last[k] = j; i = j; } } f0(i, n) { if (abs(i - last[i]) % 2 == 0) c[last[i]]++; else { if (s[i] == 'L') c[last[i] + 1]++; else c[last[i] - 1]++; } } f0(i, n) cout << c[i] << " "; return 0; }
replace
21
24
21
24
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { string s; cin >> s; int sl = sz(s); vector<pair<char, int>> a; vector<int> ans(sl); char tmp = 'R'; int cnt = 1; for (int i = 0; i <= sl; i++) { if (i == sl) a.push_back(make_pair(tmp, cnt)); else if (tmp == s.at(i)) cnt++; else { a.push_back(make_pair(tmp, cnt)); tmp = s.at(i); cnt = 1; } } int ind = -1, i = 0, bl = sz(a); while (i < bl) { cnt = a[i].second + a[i + 1].second; ind += a[i].second; ans.at(ind) = (a[i].second - 1) / 2 + 1; ans.at(ind) += (a[i + 1].second) / 2; ans.at(ind + 1) = cnt - ans.at(ind); ind += a[i + 1].second; i = i + 2; } rep(j, sl) cout << ans.at(j) << " "; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { string s; cin >> s; int sl = sz(s); vector<pair<char, int>> a; vector<int> ans(sl); char tmp = 'R'; int cnt = 1; for (int i = 1; i <= sl; i++) { if (i == sl) a.push_back(make_pair(tmp, cnt)); else if (tmp == s.at(i)) cnt++; else { a.push_back(make_pair(tmp, cnt)); tmp = s.at(i); cnt = 1; } } int ind = -1, i = 0, bl = sz(a); while (i < bl) { cnt = a[i].second + a[i + 1].second; ind += a[i].second; ans.at(ind) = (a[i].second - 1) / 2 + 1; ans.at(ind) += (a[i + 1].second) / 2; ans.at(ind + 1) = cnt - ans.at(ind); ind += a[i + 1].second; i = i + 2; } rep(j, sl) cout << ans.at(j) << " "; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using Int = long long int; template <typename T> void swap(T *t1, T *t2) { T *tmp = t1; t1 = t2; t2 = tmp; } int main() { ios::sync_with_stdio(false); cin.tie(0); char s[10000]; Int a[100000]; cin >> s; Int len = strlen(s); int rl = 0; int l = 0, r = 1; char now = 'R'; for (Int i = 0; i < len; i++) { a[i] = 0; } for (Int i = 1; i < len; i++) { if (now != s[i]) { if (now == 'R') { rl = i; l = 1; now = 'L'; } else { a[rl - 1] = l / 2; a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1; a[rl] = r / 2; a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1; r = 1; l = 0; now = 'R'; } } else { if (now == 'R') { r++; } else { l++; } } } a[rl - 1] = l / 2; a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1; a[rl] = r / 2; a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1; for (Int i = 0; i < len; i++) { cout << a[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long int; template <typename T> void swap(T *t1, T *t2) { T *tmp = t1; t1 = t2; t2 = tmp; } int main() { ios::sync_with_stdio(false); cin.tie(0); char s[100000]; Int a[100000]; cin >> s; Int len = strlen(s); int rl = 0; int l = 0, r = 1; char now = 'R'; for (Int i = 0; i < len; i++) { a[i] = 0; } for (Int i = 1; i < len; i++) { if (now != s[i]) { if (now == 'R') { rl = i; l = 1; now = 'L'; } else { a[rl - 1] = l / 2; a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1; a[rl] = r / 2; a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1; r = 1; l = 0; now = 'R'; } } else { if (now == 'R') { r++; } else { l++; } } } a[rl - 1] = l / 2; a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1; a[rl] = r / 2; a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1; for (Int i = 0; i < len; i++) { cout << a[i] << endl; } return 0; }
replace
13
14
13
14
0
p02954
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> #define M_PI 3.141592653589793238 using namespace std; // long long p = 998244353; long long p = 1000000007; #define upperbound(v, val) upper_bound(v.begin(), v.end(), val) - v.begin() #define lowerbound(v, val) lower_bound(v.begin(), v.end(), val) - v.begin() #define int long long #define ll long long #define vel vector<ll> #define vvel vector<vel> #define rep(i, n) for (int i = 0; i < n; i++) #define sor(v) sort(v.begin(), v.end()) #define mmax(a, b) a = max(a, b) #define mmin(a, b) a = min(a, b) #define mkp(a, b) make_pair(a, b) #define pin pair<ll, ll> #define qin pair<pin, int> #define V vector #define Endl endl #define veb vector<bool> #define fcout cout << fixed << setprecision(15) #define rev(s) reverse(s.begin(), s.end()) #define lower(h, val) (lower_bound(h.begin(), h.end(), val) - h.begin()) #define upper(h, val) (upper_bound(h.begin(), h.end(), val) - h.begin()) #define vveb V<veb> #define omajinai \ cin.tie(0); \ ios::sync_with_stdio(false); #define endl "\n" #define pb push_back vel kai; vel inv_kai; int root(int x, vel &pa) { if (pa[x] == -1) { return x; } int ans = root(pa[x], pa); pa[x] = ans; return ans; } bool mar(int x, int y, vel &pa) { x = root(x, pa); y = root(y, pa); if (x != y) { pa[x] = y; } return (x != y); } int gcd(int x, int y) { if (x < y) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } int lcm(ll x, ll y) { x = abs(x); y = abs(y); return x * (y / gcd(x, y)); } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void make_kai(int max_kai, int p) { kai = vel(max_kai, 1); inv_kai = kai; rep(i, max_kai - 1) { kai[i + 1] = kai[i] * (i + 1); kai[i + 1] %= p; inv_kai[i + 1] = modinv(kai[i + 1], p); } } int com(int n, int r) { if ((n < 0) || (r < 0) || (r > n)) { return 0; } int ans = (kai[n] * inv_kai[r]) % p; return (ans * inv_kai[n - r]) % p; } vel uni(vel x) { if (x.size() == 0) { return x; } sor(x); int n = x.size(); vel ans(1, x[0]); for (int j = 1; j < n; j++) { if (x[j - 1] != x[j]) { ans.push_back(x[j]); } } x = ans; return x; } vel dijk(V<V<pin>> &way, int st, int inf) { int n = way.size(); vel dist(n, inf); dist[st] = 0; priority_queue<pin, vector<pin>, greater<pin>> pq; pq.push(mkp(0, st)); veb is_checked(n, false); while (!pq.empty()) { pin x = pq.top(); pq.pop(); int pot = x.second; if (!is_checked[pot]) { is_checked[pot] = true; for (auto y : way[pot]) { int nex_dist = x.first + y.second; int nex_pot = y.first; if (dist[nex_pot] > nex_dist) { dist[nex_pot] = nex_dist; pq.push(mkp(nex_dist, y.first)); } } } } return dist; } void make_tree(vvel &chi, vel &par, int n) { V<V<pin>> way(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; way[a].push_back(mkp(b, 1)); way[b].push_back(mkp(a, 1)); } vel dist = dijk(way, 0, n + 1); par = vel(n, -1); chi = vvel(n); rep(i, n) { for (auto nex : way[i]) { int pot = nex.first; if (dist[pot] > dist[i]) { chi[i].push_back(pot); } else { par[i] = pot; } } } } void pri(vel &v) { if (v.size() == 0) { return; } cout << v[0]; rep(i, v.size() - 1) { cout << " " << v[i + 1]; } cout << endl; return; } int modpow(int a, int n, int p) { if (n == 0) { return 1; } int m = n / 2; int x = modpow(a, n / 2, p); x *= x; x %= p; if (n % 2 == 1) { x *= a; x %= p; } return x; } vvel ans; void solve(int i, string s) { if (ans[0][i] == -1) { if (s[i] == 'R') { if (s[i + 1] == 'L') { ans[0][i] = i; ans[1][i] = i + 1; ans[0][i + 1] = i + 1; ans[1][i + 1] = i; } else { solve(i + 1, s); ans[0][i] = ans[1][i + 1]; ans[1][i] = ans[0][i + 1]; } } else { solve(i - 1, s); ans[0][i] = ans[1][i - 1]; ans[1][i] = ans[0][i - 1]; } } } signed main() { string s; cin >> s; int n = s.size(); ans = vvel(2, vel(n, -1)); rep(i, n) { solve(i, s); } vel ret(n); rep(i, n) { ret[ans[0][i]]++; } pri(ret); return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> #define M_PI 3.141592653589793238 using namespace std; // long long p = 998244353; long long p = 1000000007; #define upperbound(v, val) upper_bound(v.begin(), v.end(), val) - v.begin() #define lowerbound(v, val) lower_bound(v.begin(), v.end(), val) - v.begin() #define int long long #define ll long long #define vel vector<ll> #define vvel vector<vel> #define rep(i, n) for (int i = 0; i < n; i++) #define sor(v) sort(v.begin(), v.end()) #define mmax(a, b) a = max(a, b) #define mmin(a, b) a = min(a, b) #define mkp(a, b) make_pair(a, b) #define pin pair<ll, ll> #define qin pair<pin, int> #define V vector #define Endl endl #define veb vector<bool> #define fcout cout << fixed << setprecision(15) #define rev(s) reverse(s.begin(), s.end()) #define lower(h, val) (lower_bound(h.begin(), h.end(), val) - h.begin()) #define upper(h, val) (upper_bound(h.begin(), h.end(), val) - h.begin()) #define vveb V<veb> #define omajinai \ cin.tie(0); \ ios::sync_with_stdio(false); #define endl "\n" #define pb push_back vel kai; vel inv_kai; int root(int x, vel &pa) { if (pa[x] == -1) { return x; } int ans = root(pa[x], pa); pa[x] = ans; return ans; } bool mar(int x, int y, vel &pa) { x = root(x, pa); y = root(y, pa); if (x != y) { pa[x] = y; } return (x != y); } int gcd(int x, int y) { if (x < y) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } int lcm(ll x, ll y) { x = abs(x); y = abs(y); return x * (y / gcd(x, y)); } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void make_kai(int max_kai, int p) { kai = vel(max_kai, 1); inv_kai = kai; rep(i, max_kai - 1) { kai[i + 1] = kai[i] * (i + 1); kai[i + 1] %= p; inv_kai[i + 1] = modinv(kai[i + 1], p); } } int com(int n, int r) { if ((n < 0) || (r < 0) || (r > n)) { return 0; } int ans = (kai[n] * inv_kai[r]) % p; return (ans * inv_kai[n - r]) % p; } vel uni(vel x) { if (x.size() == 0) { return x; } sor(x); int n = x.size(); vel ans(1, x[0]); for (int j = 1; j < n; j++) { if (x[j - 1] != x[j]) { ans.push_back(x[j]); } } x = ans; return x; } vel dijk(V<V<pin>> &way, int st, int inf) { int n = way.size(); vel dist(n, inf); dist[st] = 0; priority_queue<pin, vector<pin>, greater<pin>> pq; pq.push(mkp(0, st)); veb is_checked(n, false); while (!pq.empty()) { pin x = pq.top(); pq.pop(); int pot = x.second; if (!is_checked[pot]) { is_checked[pot] = true; for (auto y : way[pot]) { int nex_dist = x.first + y.second; int nex_pot = y.first; if (dist[nex_pot] > nex_dist) { dist[nex_pot] = nex_dist; pq.push(mkp(nex_dist, y.first)); } } } } return dist; } void make_tree(vvel &chi, vel &par, int n) { V<V<pin>> way(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; way[a].push_back(mkp(b, 1)); way[b].push_back(mkp(a, 1)); } vel dist = dijk(way, 0, n + 1); par = vel(n, -1); chi = vvel(n); rep(i, n) { for (auto nex : way[i]) { int pot = nex.first; if (dist[pot] > dist[i]) { chi[i].push_back(pot); } else { par[i] = pot; } } } } void pri(vel &v) { if (v.size() == 0) { return; } cout << v[0]; rep(i, v.size() - 1) { cout << " " << v[i + 1]; } cout << endl; return; } int modpow(int a, int n, int p) { if (n == 0) { return 1; } int m = n / 2; int x = modpow(a, n / 2, p); x *= x; x %= p; if (n % 2 == 1) { x *= a; x %= p; } return x; } vvel ans; void solve(int i, string &s) { if (ans[0][i] == -1) { if (s[i] == 'R') { if (s[i + 1] == 'L') { ans[0][i] = i; ans[1][i] = i + 1; ans[0][i + 1] = i + 1; ans[1][i + 1] = i; } else { solve(i + 1, s); ans[0][i] = ans[1][i + 1]; ans[1][i] = ans[0][i + 1]; } } else { solve(i - 1, s); ans[0][i] = ans[1][i - 1]; ans[1][i] = ans[0][i - 1]; } } } signed main() { string s; cin >> s; int n = s.size(); ans = vvel(2, vel(n, -1)); rep(i, n) { solve(i, s); } vel ret(n); rep(i, n) { ret[ans[0][i]]++; } pri(ret); return 0; }
replace
198
199
198
199
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; const int MOD = (int)1e9 + 7; int main() { string s; cin >> s; if (s.size() == 2) { cout << "1 1" << endl; return 0; } s = s + "R"; int n = s.size(); vector<int> ans(n, 0); int pos = 0; int index = 0; char now = 'R'; while (index <= n) { if (now == s[index]) { index++; continue; } if (now == 'R') { int num = index - pos + 1; ans[index] += (num + 1) / 2; ans[index - 1] += num / 2; now = s[index + 1]; pos = index + 1; index = pos; continue; } if (now == 'L') { int num = index - pos - 1; ans[pos - 2] += num / 2 + 1; ans[pos - 1] += (num + 1) / 2; now = s[index]; pos = index; index = pos; } } rep(i, n - 2) cout << ans[i] << " "; cout << ans[n - 2] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; const int MOD = (int)1e9 + 7; int main() { string s; cin >> s; if (s.size() == 2) { cout << "1 1" << endl; return 0; } s = s + "R"; int n = s.size(); vector<int> ans(n, 0); int pos = 0; int index = 0; char now = 'R'; while (index < n) { if (now == s[index]) { index++; continue; } if (now == 'R') { int num = index - pos + 1; ans[index] += (num + 1) / 2; ans[index - 1] += num / 2; now = s[index + 1]; pos = index + 1; index = pos; continue; } if (now == 'L') { int num = index - pos - 1; ans[pos - 2] += num / 2 + 1; ans[pos - 1] += (num + 1) / 2; now = s[index]; pos = index; index = pos; } } rep(i, n - 2) cout << ans[i] << " "; cout << ans[n - 2] << endl; }
replace
20
21
20
21
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define pb push_back 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; } const int MOD = 1000000007; const int INF = 1e9; #define PI 3.14159265369; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; const int maxn = 2e6 + 5; const int maxs = 1e5; int dub[20][maxn]; int now[maxn]; int ans[maxn]; void solve() { string s; cin >> s; int n = s.length(); for (int i = 0; i < n; i++) { now[i] = i; } for (int i = 0; i < n; i++) { if (s[i] == 'L') dub[0][i] = i - 1; else dub[0][i] = i + 1; } for (int i = 0; i < 20; i++) { for (int j = 0; j < n; j++) { dub[i + 1][j] = dub[i][dub[i][j]]; } } for (int i = 20; i >= 0; i--) { if (1LL << i & maxs) { for (int j = 0; j < n; j++) { now[j] = dub[i][now[j]]; } } } for (int i = 0; i < n; i++) { ans[now[i]]++; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define pb push_back 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; } const int MOD = 1000000007; const int INF = 1e9; #define PI 3.14159265369; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; const int maxn = 2e6 + 5; const int maxs = 1e5; int dub[21][maxn]; int now[maxn]; int ans[maxn]; void solve() { string s; cin >> s; int n = s.length(); for (int i = 0; i < n; i++) { now[i] = i; } for (int i = 0; i < n; i++) { if (s[i] == 'L') dub[0][i] = i - 1; else dub[0][i] = i + 1; } for (int i = 0; i < 20; i++) { for (int j = 0; j < n; j++) { dub[i + 1][j] = dub[i][dub[i][j]]; } } for (int i = 20; i >= 0; i--) { if (1LL << i & maxs) { for (int j = 0; j < n; j++) { now[j] = dub[i][now[j]]; } } } for (int i = 0; i < n; i++) { ans[now[i]]++; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); }
replace
36
37
36
37
-11
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define EPS 0.0000000001 #define INF 1000000000 #define MOD 1000000007 typedef long long ll; string s; int main() { cin >> s; int n = s.size(); vector<int> ans(n); int c = 0; int memo = 0; string sss; int sw; int fff; for (int i = 0; i < n; i++) { sw = 0; if (i == 0) { memo = 0; } else if (s[i - 1] == 'L' && s[i] == 'R' || i == n - 1) { if (i == n - 1) { i++; // fff=n-3; } c = i - memo; sss = s.substr(memo, c); sw = 1; memo = i; // fff--; } if (s[i - 1] == 'R' && s[i] == 'L') { fff = i - 1; } if (sw == 1) { int nnn = sss.size(); // cout << nnn << endl; int a = nnn / 2; int b = a; if (nnn % 2 == 1) { a++; } int f; for (int j = 0; j < nnn; j++) { if (sss[j] == 'L') { if (j % 2 == 0) { int ccc = b; b = a; a = ccc; } f = j; break; } } // cout<<"f"<<f<<endl; // cout<<"fff"<<fff<<endl; ans[fff] = a; ans[fff + 1] = b; } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define EPS 0.0000000001 #define INF 1000000000 #define MOD 1000000007 typedef long long ll; string s; int main() { cin >> s; int n = s.size(); vector<int> ans(n); int c = 0; int memo = 0; string sss; int sw; int fff; for (int i = 0; i < n; i++) { sw = 0; if (i == 0) { memo = 0; } else if (s[i - 1] == 'L' && s[i] == 'R' || i == n - 1) { if (i == n - 1) { i++; // fff=n-3; } c = i - memo; sss = s.substr(memo, c); sw = 1; memo = i; // fff--; } if (s[i - 1] == 'R' && s[i] == 'L') { fff = i - 1; } if (s[i - 2] == 'R' && s[i - 1] == 'L' && i == n) { fff = i - 2; } if (sw == 1) { int nnn = sss.size(); // cout << nnn << endl; int a = nnn / 2; int b = a; if (nnn % 2 == 1) { a++; } int f; for (int j = 0; j < nnn; j++) { if (sss[j] == 'L') { if (j % 2 == 0) { int ccc = b; b = a; a = ccc; } f = j; break; } } // cout<<"f"<<f<<endl; // cout<<"fff"<<fff<<endl; ans[fff] = a; ans[fff + 1] = b; } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; }
insert
42
42
42
46
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep_i(i, n) for (int i = 0; i < (n); ++i) #define rep_ll(i, n) for (long long i = 0; i < (n); ++i) #define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i) #define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i) #define debug_vi(v) \ copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " ")); #define debug_vll(v) \ copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " ")); #define debug_vd(v) \ copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " ")); #define sort_v(v) sort((v).begin(), (v).end()); // 昇順 #define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); // 降 #define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順 #define say(t) cout << (t) << endl; #define sum_vi(v) accumulate((v).begin(), (v).end(), 0); #define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL); 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; } const int IINF = (1 << 30); const ll LLINF = 1LL << 60; int main() { ifstream in("input.txt"); cin.rdbuf(in.rdbuf()); // cin.tie(0); // ios::sync_with_stdio(0); string s; cin >> s; vector<double> poRL; vector<double> poLR; rep_i(i, s.length() - 1) { if (s[i] == 'R' && s[i + 1] == 'L') { poRL.push_back(i); } } rep_i(i, s.length() - 1) { if (s[i] == 'L' && s[i + 1] == 'R') { poLR.push_back(i); } } vector<int> ans(s.length()); if (poLR.empty()) { // R ans[int(poRL[0])] = round((poRL[0] + 1) / 2) + int(s.length() - poRL[0] - 1) / 2; // L ans[int(poRL[0] + 1)] = (int(poRL[0] + 1) - round((poRL[0] + 1) / 2)) + (int(s.length() - poRL[0] - 1) - int(s.length() - poRL[0] - 1) / 2); debug_vi(ans); cout << endl; } else { for (int i = 0; i < poRL.size(); i++) { if (i == 0) { // R ans[int(poRL[i])] = round((poRL[i] + 1) / 2) + int(poLR[0] - poRL[0]) / 2; // L ans[int(poRL[i] + 1)] = (int(poRL[i] + 1) - round((poRL[i] + 1) / 2)) + (int(poLR[0] - poRL[0]) - int(poLR[0] - poRL[0]) / 2); } else if (i == poRL.size() - 1) { // L ans[int(poRL[i] + 1)] = round((s.length() - (poRL[i] + 1)) / 2) + int(poRL[i] - poLR[i - 1]) / 2; // R ans[int(poRL[i])] = ((s.length() - int(poRL[i] + 1)) - round((s.length() - (poRL[i] + 1)) / 2)) + (int(poRL[i] - poLR[i - 1]) - int(poRL[i] - poLR[i - 1]) / 2); } else { // R // if(i == 1){ // cout << round((poRL[i] - poLR[i - 1])/2) << endl; // cout << int(poLR[i] - poRL[i])/2 << endl; // } ans[int(poRL[i])] = round((poRL[i] - poLR[i - 1]) / 2) + int(poLR[i] - poRL[i]) / 2; // L ans[int(poRL[i] + 1)] = (int(poRL[i] - poLR[i - 1]) - round((poRL[i] - poLR[i - 1]) / 2)) + (int(poLR[i] - poRL[i]) - int(poLR[i] - poRL[i]) / 2); } } debug_vi(ans); cout << endl; } }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep_i(i, n) for (int i = 0; i < (n); ++i) #define rep_ll(i, n) for (long long i = 0; i < (n); ++i) #define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i) #define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i) #define debug_vi(v) \ copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " ")); #define debug_vll(v) \ copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " ")); #define debug_vd(v) \ copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " ")); #define sort_v(v) sort((v).begin(), (v).end()); // 昇順 #define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); // 降 #define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順 #define say(t) cout << (t) << endl; #define sum_vi(v) accumulate((v).begin(), (v).end(), 0); #define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL); 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; } const int IINF = (1 << 30); const ll LLINF = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(0); string s; cin >> s; vector<double> poRL; vector<double> poLR; rep_i(i, s.length() - 1) { if (s[i] == 'R' && s[i + 1] == 'L') { poRL.push_back(i); } } rep_i(i, s.length() - 1) { if (s[i] == 'L' && s[i + 1] == 'R') { poLR.push_back(i); } } vector<int> ans(s.length()); if (poLR.empty()) { // R ans[int(poRL[0])] = round((poRL[0] + 1) / 2) + int(s.length() - poRL[0] - 1) / 2; // L ans[int(poRL[0] + 1)] = (int(poRL[0] + 1) - round((poRL[0] + 1) / 2)) + (int(s.length() - poRL[0] - 1) - int(s.length() - poRL[0] - 1) / 2); debug_vi(ans); cout << endl; } else { for (int i = 0; i < poRL.size(); i++) { if (i == 0) { // R ans[int(poRL[i])] = round((poRL[i] + 1) / 2) + int(poLR[0] - poRL[0]) / 2; // L ans[int(poRL[i] + 1)] = (int(poRL[i] + 1) - round((poRL[i] + 1) / 2)) + (int(poLR[0] - poRL[0]) - int(poLR[0] - poRL[0]) / 2); } else if (i == poRL.size() - 1) { // L ans[int(poRL[i] + 1)] = round((s.length() - (poRL[i] + 1)) / 2) + int(poRL[i] - poLR[i - 1]) / 2; // R ans[int(poRL[i])] = ((s.length() - int(poRL[i] + 1)) - round((s.length() - (poRL[i] + 1)) / 2)) + (int(poRL[i] - poLR[i - 1]) - int(poRL[i] - poLR[i - 1]) / 2); } else { // R // if(i == 1){ // cout << round((poRL[i] - poLR[i - 1])/2) << endl; // cout << int(poLR[i] - poRL[i])/2 << endl; // } ans[int(poRL[i])] = round((poRL[i] - poLR[i - 1]) / 2) + int(poLR[i] - poRL[i]) / 2; // L ans[int(poRL[i] + 1)] = (int(poRL[i] - poLR[i - 1]) - round((poRL[i] - poLR[i - 1]) / 2)) + (int(poLR[i] - poRL[i]) - int(poLR[i] - poRL[i]) / 2); } } debug_vi(ans); cout << endl; } }
replace
26
30
26
28
-11
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int ans[10010], n, rr, ll, cr, cl; string s; int main() { cin >> s; n = s.size(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { rr = i; cr = 0; } else { cr++; if (cr % 2 == 0) ans[rr]++; else ans[rr + 1]++; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'L') { ll = i; cl = 0; } else { cl++; if (cl % 2 == 0) ans[ll]++; else ans[ll - 1]++; } } cout << ans[0]; for (int i = 1; i < n; i++) cout << ' ' << ans[i]; cout << endl; }
#include <bits/stdc++.h> using namespace std; int ans[100010], n, rr, ll, cr, cl; string s; int main() { cin >> s; n = s.size(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { rr = i; cr = 0; } else { cr++; if (cr % 2 == 0) ans[rr]++; else ans[rr + 1]++; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'L') { ll = i; cl = 0; } else { cl++; if (cl % 2 == 0) ans[ll]++; else ans[ll - 1]++; } } cout << ans[0]; for (int i = 1; i < n; i++) cout << ' ' << ans[i]; cout << endl; }
replace
3
4
3
4
0
p02954
Python
Runtime Error
S = input() count = 1 answer = [0] * len(S) # RLの切り替わるインデックスをマーク n = 0 for i in range(len(S) - 1): if S[i] == S[i + 1]: count += 1 else: if S[i + 1] == "R": # Lを割り振る answer[n] += count // 2 answer[n + 1] += -(-count // 2) count = 1 else: # Rを割り振る answer[i] += -(-count // 2) answer[i + 1] += count // 2 count = 1 n = i # 右端のLを割り振る if i == len(S) - 2: answer[n] += count // 2 answer[n + 1] += -(-count // 2) for i, c in enumerate(answer): if i == 0: print(c, end="") else: print(f" {c}", end="")
S = input() count = 1 answer = [0] * len(S) # RLの切り替わるインデックスをマーク n = 0 for i in range(len(S) - 1): if S[i] == S[i + 1]: count += 1 else: if S[i + 1] == "R": # Lを割り振る answer[n] += count // 2 answer[n + 1] += -(-count // 2) count = 1 else: # Rを割り振る answer[i] += -(-count // 2) answer[i + 1] += count // 2 count = 1 n = i # 右端のLを割り振る if i == len(S) - 2: answer[n] += count // 2 answer[n + 1] += -(-count // 2) for i, c in enumerate(answer): print(c, end="") print(" ", end="")
replace
27
31
27
29
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { string s; cin >> s; int n = s.size(); vi r, l; rep0(n) if (s[i] == 'L') l.pb(i); else r.pb(-i); // FORE(it,l) cout<<*it<<" ";cout<<endl; // FORE(it,r) cout<<*it<<" "; sort(all(r)); vi ans(n + 1, 0); rep0(n) { if (s[i] == 'R') { int k = upper_bound(all(l), i) - l.begin(); // cout<<k<<" "; if ((l[k] - i) % 2) ans[l[k] - 1]++; else ans[l[k]]++; } else { int k = upper_bound(all(r), -i) - r.begin(); if ((-r[k] - i) % 2) ans[-r[k] + 1]++; else ans[-r[k]]++; } } rep0(n) cout << ans[i] << " "; r0 } signed main() { inputoutput asdf int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { string s; cin >> s; int n = s.size(); vi r, l; rep0(n) if (s[i] == 'L') l.pb(i); else r.pb(-i); // FORE(it,l) cout<<*it<<" ";cout<<endl; // FORE(it,r) cout<<*it<<" "; sort(all(r)); vi ans(n + 1, 0); rep0(n) { if (s[i] == 'R') { int k = upper_bound(all(l), i) - l.begin(); // cout<<k<<" "; if ((l[k] - i) % 2) ans[l[k] - 1]++; else ans[l[k]]++; } else { int k = upper_bound(all(r), -i) - r.begin(); if ((-r[k] - i) % 2) ans[-r[k] + 1]++; else ans[-r[k]]++; } } rep0(n) cout << ans[i] << " "; r0 } signed main() { // inputoutput asdf int t = 1; // cin>>t; while (t--) { solve(); } }
replace
93
95
93
95
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int ltoR[100005]; int ans[10005]; int main() { string S; cin >> S; memset(ans, 0, sizeof(ans)); memset(ltoR, 0, sizeof(ltoR)); int lrCounter = 0; // 移動する距離をメモ // 右からなめる for (int i = S.size() - 1; i >= 0; i--) { if (S[i] == 'R') { lrCounter++; ltoR[i] = lrCounter; } else { lrCounter = 0; } } // 左からなめる for (int i = 0; i < S.size(); i++) { if (S[i] == 'L') { lrCounter--; ltoR[i] = lrCounter; } else { lrCounter = 0; } } // 計算 for (int i = 0; i < S.size(); i++) { if (ltoR[i] % 2 == 0) { ans[i + ltoR[i]] += 1; } else if (ltoR[i] < 0) { ans[i + ltoR[i] + 1] += 1; } else { ans[i + ltoR[i] - 1] += 1; } } // 出力 for (int i = 0; i < S.size(); i++) { cout << ans[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int ltoR[100005]; int ans[100005]; int main() { string S; cin >> S; memset(ans, 0, sizeof(ans)); memset(ltoR, 0, sizeof(ltoR)); int lrCounter = 0; // 移動する距離をメモ // 右からなめる for (int i = S.size() - 1; i >= 0; i--) { if (S[i] == 'R') { lrCounter++; ltoR[i] = lrCounter; } else { lrCounter = 0; } } // 左からなめる for (int i = 0; i < S.size(); i++) { if (S[i] == 'L') { lrCounter--; ltoR[i] = lrCounter; } else { lrCounter = 0; } } // 計算 for (int i = 0; i < S.size(); i++) { if (ltoR[i] % 2 == 0) { ans[i + ltoR[i]] += 1; } else if (ltoR[i] < 0) { ans[i + ltoR[i] + 1] += 1; } else { ans[i + ltoR[i] - 1] += 1; } } // 出力 for (int i = 0; i < S.size(); i++) { cout << ans[i] << " "; } cout << endl; return 0; }
replace
4
5
4
5
0
p02954
C++
Runtime Error
#include <algorithm> // sort(ALL()) #include <iomanip> #include <iostream> #include <map> // 連想配列 map<string, int> #include <math.h> #include <queue> // push(), front(), pop() 先入れ先出し #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define pb push_back #define mp make_pair #define scan(argument) cin >> argument #define prin(argument) cout << argument << endl #define kaigyo cout << endl #define EPS 1e-7 #define ALL(obj) (obj).begin(), (obj).end() using ul = unsigned long; using ll = long long; using ld = long double; using vint = vector<int>; using vll = vector<ll>; using pint = pair<int, int>; using pll = pair<ll, ll>; using vpint = vector<pint>; using vpll = vector<pll>; const int INF = (int)1e9 + 1; const int MOD = (int)1e9 + 7; #define INT(argu) (int)(argu + eps) int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); int dp[18][n]; REP(i, n) { dp[0][i] = i; } REP(i, n) { if (s[i] == 'R') dp[1][i] = i + 1; else dp[1][i] = i - 1; } REP1(j, 17) { REP(i, n) { dp[j + 1][i] = dp[j][dp[j][i]]; } } vint ans(n); REP(i, n) { ans[dp[18][i]]++; } REP(i, n) { cout << ans[i] << " "; } return 0; }
#include <algorithm> // sort(ALL()) #include <iomanip> #include <iostream> #include <map> // 連想配列 map<string, int> #include <math.h> #include <queue> // push(), front(), pop() 先入れ先出し #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define pb push_back #define mp make_pair #define scan(argument) cin >> argument #define prin(argument) cout << argument << endl #define kaigyo cout << endl #define EPS 1e-7 #define ALL(obj) (obj).begin(), (obj).end() using ul = unsigned long; using ll = long long; using ld = long double; using vint = vector<int>; using vll = vector<ll>; using pint = pair<int, int>; using pll = pair<ll, ll>; using vpint = vector<pint>; using vpll = vector<pll>; const int INF = (int)1e9 + 1; const int MOD = (int)1e9 + 7; #define INT(argu) (int)(argu + eps) int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); int dp[19][n]; REP(i, n) { dp[0][i] = i; } REP(i, n) { if (s[i] == 'R') dp[1][i] = i + 1; else dp[1][i] = i - 1; } REP1(j, 17) { REP(i, n) { dp[j + 1][i] = dp[j][dp[j][i]]; } } vint ans(n); REP(i, n) { ans[dp[18][i]]++; } REP(i, n) { cout << ans[i] << " "; } return 0; }
replace
46
47
46
47
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string s; int n, tot = 1, bp[50010] /*break point */, ans[100010]; // r1l0 inline void work(int l, int r, int bpt) { // cout<<l<<" "<<r<<" "<<bpt<<endl; if ((r - l + 1) % 2 == 0) { ans[bpt] = (r - l + 1) / 2; ans[bpt + 1] = (r - l + 1) / 2; } else { if ((bpt - l + 1) % 2 == 0) { ans[bpt] = (r - l + 1) / 2; ans[bpt + 1] = (r - l + 2) / 2; } else { ans[bpt] = (r - l + 2) / 2; ans[bpt + 1] = (r - l + 1) / 2; } } } int main() { cin >> s; n = s.size(); if (n == 2) { cout << "1 1" << endl; return 0; } // fill(ans,ans+n,1); bp[0] = -1; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) { bp[tot++] = i; } } bp[tot++] = n - 1; for (int i = 0; i < tot - 1; i += 2) { work(bp[i] + 1, bp[i + 2], bp[i + 1]); } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n, tot = 1, bp[100010] /*break point */, ans[100010]; // r1l0 inline void work(int l, int r, int bpt) { // cout<<l<<" "<<r<<" "<<bpt<<endl; if ((r - l + 1) % 2 == 0) { ans[bpt] = (r - l + 1) / 2; ans[bpt + 1] = (r - l + 1) / 2; } else { if ((bpt - l + 1) % 2 == 0) { ans[bpt] = (r - l + 1) / 2; ans[bpt + 1] = (r - l + 2) / 2; } else { ans[bpt] = (r - l + 2) / 2; ans[bpt + 1] = (r - l + 1) / 2; } } } int main() { cin >> s; n = s.size(); if (n == 2) { cout << "1 1" << endl; return 0; } // fill(ans,ans+n,1); bp[0] = -1; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) { bp[tot++] = i; } } bp[tot++] = n - 1; for (int i = 0; i < tot - 1; i += 2) { work(bp[i] + 1, bp[i + 2], bp[i + 1]); } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; return 0; }
replace
3
4
3
4
0
p02954
C++
Time Limit Exceeded
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; string s; vector<pii> v; int n; pii f(int now) { if (now == -1) return {0, 0}; if (now == n) return {n - 1, n - 1}; if (now != n - 1 && s[now] == 'R' && s[now + 1] == 'L') { v[now] = {now, now + 1}; v[now + 1] = {now + 1, now}; return v[now]; } v[now] = f(now + ((s[now] == 'R') ? 1 : -1)); swap(v[now].first, v[now].second); return v[now]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> s; n = s.length(); v.resize(n, {-2, -2}); for (int i = 0; i < n; i++) if (v[i].first == -2) f(i); vector<int> answer(n); for (int i = 0; i < n; i++) answer[v[i].first] += 1; for (int ans : answer) cout << ans << " "; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; string s; vector<pii> v; int n; pii f(int now) { if (v[now].first != -2) return v[now]; if (now == -1) return {0, 0}; if (now == n) return {n - 1, n - 1}; if (now != n - 1 && s[now] == 'R' && s[now + 1] == 'L') { v[now] = {now, now + 1}; v[now + 1] = {now + 1, now}; return v[now]; } v[now] = f(now + ((s[now] == 'R') ? 1 : -1)); swap(v[now].first, v[now].second); return v[now]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> s; n = s.length(); v.resize(n, {-2, -2}); for (int i = 0; i < n; i++) if (v[i].first == -2) f(i); vector<int> answer(n); for (int i = 0; i < n; i++) answer[v[i].first] += 1; for (int ans : answer) cout << ans << " "; return 0; }
insert
21
21
21
23
TLE
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = pow(10, 9) + 7; // const int MOD = 998244353; // const int MOD = ; int mod(int A, int M) { return (A % M + M) % M; } const int INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int divCeil(int A, int B) { return (A + (B - 1)) / B; } int myctoi(char C) { return C - 48; } char myitoc(int N) { return '0' + N; } signed main() { string S; cin >> S; int N = S.size(); vector<int> V(N, 1); for (int i = 0; i < 2 * N; i++) { vector<int> v(N, 0); for (int j = 0; j < N; j++) { if (S.at(j) == 'R') v.at(j + 1) += V.at(j); else v.at(j - 1) += V.at(j); } for (int j = 0; j < N; j++) { V.at(j) = v.at(j); } } for (int i = 0; i < N; i++) { cout << V.at(i); if (i == N - 1) cout << endl; else cout << " "; } }
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = pow(10, 9) + 7; // const int MOD = 998244353; // const int MOD = ; int mod(int A, int M) { return (A % M + M) % M; } const int INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int divCeil(int A, int B) { return (A + (B - 1)) / B; } int myctoi(char C) { return C - 48; } char myitoc(int N) { return '0' + N; } signed main() { string S; cin >> S; int N = S.size(); S += "R"; vector<int> V(N, 0); int r = 0, l = 0; int mark = -1; for (int i = 0; i < N; i++) { if (S.at(i) == 'L') l++; else r++; if (S.substr(i, 2) == "RL") mark = i; if (S.substr(i, 2) == "LR") { V.at(mark) = (r % 2 == 0) ? (r + l) / 2 : divCeil(r + l, 2); V.at(mark + 1) = l + r - V.at(mark); l = 0; r = 0; } } for (int i = 0; i < N; i++) { cout << V.at(i); if (i == N - 1) cout << endl; else cout << " "; } }
replace
31
42
31
48
TLE
p02954
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> 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; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-14) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); using Graph = vector<VE>; 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 { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= 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 { mint res(*this); return res /= 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]; } } com(300010); struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); 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)]; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } 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; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(15); string s; cin >> s; int n = s.size(); auto p = RunLength(s); VE ans(n); int now = 0; rep(i, s.size()) { now += p[i].second; int tmp = p[i].second + p[i + 1].second; if (tmp % 2) { if (p[i].second % 2) { ans[now - 1] = (tmp + 1) / 2; ans[now] = tmp / 2; } else { ans[now - 1] = tmp / 2; ans[now] = (tmp + 1) / 2; } } else { ans[now - 1] = tmp / 2; ans[now] = tmp / 2; } now += p[i + 1].second; i++; } rep(i, n) cout << ans[i] << " "; cout << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> 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; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-14) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); using Graph = vector<VE>; 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 { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= 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 { mint res(*this); return res /= 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]; } } com(300010); struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); 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)]; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } 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; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(15); string s; cin >> s; int n = s.size(); auto p = RunLength(s); VE ans(n); int now = 0; rep(i, p.size()) { now += p[i].second; int tmp = p[i].second + p[i + 1].second; if (tmp % 2) { if (p[i].second % 2) { ans[now - 1] = (tmp + 1) / 2; ans[now] = tmp / 2; } else { ans[now - 1] = tmp / 2; ans[now] = (tmp + 1) / 2; } } else { ans[now - 1] = tmp / 2; ans[now] = tmp / 2; } now += p[i + 1].second; i++; } rep(i, n) cout << ans[i] << " "; cout << endl; return 0; }
replace
306
307
306
307
-11
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const int mx = 200010; const ll mod = 1e9 + 7; string s; int main() { cin >> s; int n = s.size(); vector<int> next(n), ans(n); for (int i = 0; i < n; i++) { if (s[i] == 'R') { next[i] = i + 1; } else { next[i] = i - 1; } } for (int t = 0; t < 100000; t++) { vector<int> dnext(n); for (int i = 0; i < n; i++) { dnext[i] = next[next[i]]; } dnext.swap(next); } for (int i = 0; i < n; i++) { ans[next[i]]++; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const int mx = 200010; const ll mod = 1e9 + 7; string s; int main() { cin >> s; int n = s.size(); vector<int> next(n), ans(n); for (int i = 0; i < n; i++) { if (s[i] == 'R') { next[i] = i + 1; } else { next[i] = i - 1; } } for (int t = 0; t < 1000; t++) { vector<int> dnext(n); for (int i = 0; i < n; i++) { dnext[i] = next[next[i]]; } dnext.swap(next); } for (int i = 0; i < n; i++) { ans[next[i]]++; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
replace
26
27
26
27
TLE
p02954
C++
Runtime Error
#include <stdio.h> #include <string.h> int main() { static char S[100001]; scanf("%s", S); int N = (int)strlen(S); static char len[100000]; int left = 0; for (int i = 0; i < N;) { if (S[i] == 'R') { i++; continue; } // find L for (int k = left; k < i; k++) { len[k] = i - k; } while (i < N && S[i] == 'L') { i++; } left = i; } int right = N - 1; for (int i = N - 1; i >= 0;) { if (S[i] == 'L') { i--; continue; } // find R for (int k = right; k > i; k--) { len[k] = k - i; } while (i >= 0 && S[i] == 'R') { i--; } right = i; } static int ans[100000]; for (int i = 0; i < N; i++) { if (S[i] == 'R') { int p = i + len[i]; if (len[i] % 2 == 0) { ans[p]++; } else { ans[p - 1]++; } } // L else { int p = i - len[i]; if (len[i] % 2 == 0) { ans[p]++; } else { ans[p + 1]++; } } } for (int i = 0; i < N; i++) { printf("%d%c", ans[i], (i == N - 1) ? '\n' : ' '); } return 0; }
#include <stdio.h> #include <string.h> int main() { static char S[100001]; scanf("%s", S); int N = (int)strlen(S); static int len[100000]; int left = 0; for (int i = 0; i < N;) { if (S[i] == 'R') { i++; continue; } // find L for (int k = left; k < i; k++) { len[k] = i - k; } while (i < N && S[i] == 'L') { i++; } left = i; } int right = N - 1; for (int i = N - 1; i >= 0;) { if (S[i] == 'L') { i--; continue; } // find R for (int k = right; k > i; k--) { len[k] = k - i; } while (i >= 0 && S[i] == 'R') { i--; } right = i; } static int ans[100000]; for (int i = 0; i < N; i++) { if (S[i] == 'R') { int p = i + len[i]; if (len[i] % 2 == 0) { ans[p]++; } else { ans[p - 1]++; } } // L else { int p = i - len[i]; if (len[i] % 2 == 0) { ans[p]++; } else { ans[p + 1]++; } } } for (int i = 0; i < N; i++) { printf("%d%c", ans[i], (i == N - 1) ? '\n' : ' '); } return 0; }
replace
8
9
8
9
0
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long mod = 1e9 + 7; // 10^9+7 int main() { string ss; cin >> ss; int s[100002]; int g[100002]; // R = 0 L = 1 int n = (int)ss.length(); for (int i = 0; i < n; i++) { if (ss[i] == 'R') s[i] = 0; else s[i] = 1; g[i] = 0; } vector<int> c; c.push_back(-1); for (int i = 0; i < n - 1; i++) { if (s[i] == 0) { if (s[i + 1] == 1) { c.push_back(i); } } } c.push_back(n + 1); for (int i = 0; i < n; i++) { int x, y; for (int j = 0; j < (int)c.size(); j++) { if (c[j] <= i && i <= c[j + 1]) { x = c[j]; y = c[j + 1]; break; } } if (s[i] == 0) x = y; int dis = abs(i - x); if (dis % 2 == 0) g[x]++; else g[x + 1]++; } for (int i = 0; i < n; i++) { cout << g[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long mod = 1e9 + 7; // 10^9+7 int main() { string ss; cin >> ss; int s[100002]; int g[100002]; // R = 0 L = 1 int n = (int)ss.length(); for (int i = 0; i < n; i++) { if (ss[i] == 'R') s[i] = 0; else s[i] = 1; g[i] = 0; } vector<int> c; c.push_back(-1); for (int i = 0; i < n - 1; i++) { if (s[i] == 0) { if (s[i + 1] == 1) { c.push_back(i); } } } c.push_back(n + 1); for (int i = 0; i < n; i++) { int x, y; int left = 0, right = (int)c.size(); int mid = (right + left) / 2; if (c[mid] >= i) { mid = 0; } for (int j = mid; j < (int)c.size() - 1; j++) { if (c[j] <= i && i <= c[j + 1]) { x = c[j]; y = c[j + 1]; break; } } if (s[i] == 0) x = y; int dis = abs(i - x); if (dis % 2 == 0) g[x]++; else g[x + 1]++; } for (int i = 0; i < n; i++) { cout << g[i] << " "; } cout << endl; return 0; }
replace
35
36
35
44
TLE
p02954
C++
Time Limit Exceeded
/* #region Head */ //============================================================================ // Name : filename.cpp // Author : abb // Version : // Copyright : [My copyright notice] // Description : test program //============================================================================ #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll, ll>; using vll = vector<ll>; using vvll = vector<vll>; using vd = vector<double>; using vvd = vector<vd>; using vs = vector<string>; using vvs = vector<vs>; #define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i)) #define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i)) #define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i)) #define REPD(i, m, n, d) \ for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d)) #define REPMD(i, m, n, d) \ for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d)) #define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define ALL(x) begin(x), end(x) #define SIZE(x) ((ll)(x).size()) constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7 constexpr double EPS = 1e-12; constexpr double PI = 3.14159265358979323846; // vector入力 template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // vector出力 template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { ll len = SIZE(vec); os << "{"; for (int i = 0; i < len; i++) os << vec[i] << (i == len - 1 ? "" : ", "); os << "}"; return os; } // pair出力 template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map出力 template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; REPI(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; REPI(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // dump #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(move(tail)...); } // chmax (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } // chmin (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // container 内の最初の element のインデックスを探す template <class Container> ll indexof(const Container &container, const typename Container::value_type &element) { auto iter = find(container.begin(), container.end(), element); size_t index = distance(container.begin(), iter); if (index == container.size()) { index = -1; } return index; } // ローカル用 #define DEBUG_ #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif struct AtCoderInitialize { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; AtCoderInitialize() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } ATCODER_INITIALIZE; /* #endregion */ /** D - Gathering Children 実行時間制限: 2 sec / メモリ制限: 1024 MB 配点 : 400 点 問題文 マスの情報を表す、'L' と 'R' で構成された文字列 S が与えられます。 文字列 S の長さを N としたとき、N 個のマスが左右一列に並んでおり、左から i 番目のマスには S の左から i 番目の文字が書かれています。 ただし、左端のマスには必ず 'R'、右端のマスには必ず 'L' が書かれています。 はじめ、各マスには 1 人の子どもが居ます。 子どもたちはそれぞれ次の規則に従った移動を 10^{100} 回行います。 ・今居るマスに書かれた文字に従って 1 マス移動する。すなわち、今居るマスに書かれた文字が 'L' のとき左隣のマスに、'R' のとき右隣のマスに移動する。 10^{100} 回の移動の後に各マスに居る子どもの人数を求めてください。 制約 ・S は長さ 2 以上 10^5 以下の文字列であり、S の各文字は 'L' または 'R' である。 ・S の 1 文字目は 'R'、N 文字目は 'L' である。 */ void solve() { string s; cin >> s; // 10^(100)回=無限偶数回 // 右隣がRになっているRなら0 // 左隣がLになっているLなら0 // RRRRL のように R が偶数個なら,[0,0,0,(R個数/2),(R個数/2)]が足される // RRRL のように R が奇数個なら,[0,0,(R個数/2+1),(R個数/2)]が足される // RLLLL のように L が偶数個なら,[(L個数/2),(L個数/2),0,0,0]が足される // RLLL のように L が奇数個なら,[(L個数/2),(L個数/2+1),0,0]が足される s.push_back('E'); vll ret(SIZE(s), 0); char mode = 'R'; ll length = 0; REP(i, 0, SIZE(s)) { if (s[i] == mode) { length++; } else { // mode の文字が length 個 あった if (mode == 'R') { ret[i] += length / 2; ret[i - 1] += length % 2 == 0 ? length / 2 : length / 2 + 1; } else { ret[i - length - 1] += length / 2; ret[i - length] += length % 2 == 0 ? length / 2 : length / 2 + 1; } dump(i, length, ret); mode = s[i]; length = 1; } } dump(ret); REP(i, 0, SIZE(s) - 1) { cout << ret[i] << (i == SIZE(s) - 2 ? "" : " "); } cout << endl; } /** * エントリポイント. * @return 0. */ int main() { solve(); return 0; }
/* #region Head */ //============================================================================ // Name : filename.cpp // Author : abb // Version : // Copyright : [My copyright notice] // Description : test program //============================================================================ #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll, ll>; using vll = vector<ll>; using vvll = vector<vll>; using vd = vector<double>; using vvd = vector<vd>; using vs = vector<string>; using vvs = vector<vs>; #define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i)) #define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i)) #define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i)) #define REPD(i, m, n, d) \ for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d)) #define REPMD(i, m, n, d) \ for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d)) #define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define ALL(x) begin(x), end(x) #define SIZE(x) ((ll)(x).size()) constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7 constexpr double EPS = 1e-12; constexpr double PI = 3.14159265358979323846; // vector入力 template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // vector出力 template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { ll len = SIZE(vec); os << "{"; for (int i = 0; i < len; i++) os << vec[i] << (i == len - 1 ? "" : ", "); os << "}"; return os; } // pair出力 template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map出力 template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; REPI(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; REPI(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // dump #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(move(tail)...); } // chmax (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } // chmin (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // container 内の最初の element のインデックスを探す template <class Container> ll indexof(const Container &container, const typename Container::value_type &element) { auto iter = find(container.begin(), container.end(), element); size_t index = distance(container.begin(), iter); if (index == container.size()) { index = -1; } return index; } // ローカル用 // #define DEBUG_ #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif struct AtCoderInitialize { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; AtCoderInitialize() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } ATCODER_INITIALIZE; /* #endregion */ /** D - Gathering Children 実行時間制限: 2 sec / メモリ制限: 1024 MB 配点 : 400 点 問題文 マスの情報を表す、'L' と 'R' で構成された文字列 S が与えられます。 文字列 S の長さを N としたとき、N 個のマスが左右一列に並んでおり、左から i 番目のマスには S の左から i 番目の文字が書かれています。 ただし、左端のマスには必ず 'R'、右端のマスには必ず 'L' が書かれています。 はじめ、各マスには 1 人の子どもが居ます。 子どもたちはそれぞれ次の規則に従った移動を 10^{100} 回行います。 ・今居るマスに書かれた文字に従って 1 マス移動する。すなわち、今居るマスに書かれた文字が 'L' のとき左隣のマスに、'R' のとき右隣のマスに移動する。 10^{100} 回の移動の後に各マスに居る子どもの人数を求めてください。 制約 ・S は長さ 2 以上 10^5 以下の文字列であり、S の各文字は 'L' または 'R' である。 ・S の 1 文字目は 'R'、N 文字目は 'L' である。 */ void solve() { string s; cin >> s; // 10^(100)回=無限偶数回 // 右隣がRになっているRなら0 // 左隣がLになっているLなら0 // RRRRL のように R が偶数個なら,[0,0,0,(R個数/2),(R個数/2)]が足される // RRRL のように R が奇数個なら,[0,0,(R個数/2+1),(R個数/2)]が足される // RLLLL のように L が偶数個なら,[(L個数/2),(L個数/2),0,0,0]が足される // RLLL のように L が奇数個なら,[(L個数/2),(L個数/2+1),0,0]が足される s.push_back('E'); vll ret(SIZE(s), 0); char mode = 'R'; ll length = 0; REP(i, 0, SIZE(s)) { if (s[i] == mode) { length++; } else { // mode の文字が length 個 あった if (mode == 'R') { ret[i] += length / 2; ret[i - 1] += length % 2 == 0 ? length / 2 : length / 2 + 1; } else { ret[i - length - 1] += length / 2; ret[i - length] += length % 2 == 0 ? length / 2 : length / 2 + 1; } dump(i, length, ret); mode = s[i]; length = 1; } } dump(ret); REP(i, 0, SIZE(s) - 1) { cout << ret[i] << (i == SIZE(s) - 2 ? "" : " "); } cout << endl; } /** * エントリポイント. * @return 0. */ int main() { solve(); return 0; }
replace
140
141
140
141
TLE
p02954
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define Rep(i, m, n) for (int i = m; i < n; i++) #define repeatrev(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define itn int using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef priority_queue<int> Pr; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int left = 0; rep(i, s.size()) if (s[i] == 'L') left++; int a[s.size()], b[s.size()]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); if (s.size() - left > left) { repeatrev(i, s.size() - 1, 0) { int count = 0; if (s[i] == 'L') { if (i < s.size() - 1 && s[i + 1] == 'L') { if (s[b[i + 1]] == 'R') { a[b[i + 1] + 1]++; b[i] = b[i + 1] + 1; } else { a[b[i + 1] - 1]++; b[i] = b[i + 1] - 1; } } else { int j = i; while (s[j] != 'R') { j--; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j + 1]++; b[i] = j + 1; } } } else { int j = i; while (s[j] != 'L') { j++; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j - 1]++; b[i] = j - 1; } } } } else { rep(i, s.size()) { int count = 0; if (s[i] == 'L') { int j = i; while (s[j] != 'R') { j--; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j + 1]++; b[i] = j + 1; } } else { if (i >= 1 && s[i - 1] == 'R') { if (s[b[i - 1]] == 'L') { a[b[i - 1] - 1]++; b[i] = b[i - 1] - 1; } else { a[b[i - 1] + 1]++; b[i] = b[i - 1] + 1; } } else { int j = i; while (s[j] != 'L') { j++; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j - 1]++; b[i] = j - 1; } } } } } rep(i, s.size()) cout << a[i] << " "; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define Rep(i, m, n) for (int i = m; i < n; i++) #define repeatrev(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define itn int using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef priority_queue<int> Pr; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int left = 0; rep(i, s.size()) if (s[i] == 'L') left++; int a[s.size()], b[s.size()]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); if (s.size() - left < left) { repeatrev(i, s.size() - 1, 0) { int count = 0; if (s[i] == 'L') { if (i < s.size() - 1 && s[i + 1] == 'L') { if (s[b[i + 1]] == 'R') { a[b[i + 1] + 1]++; b[i] = b[i + 1] + 1; } else { a[b[i + 1] - 1]++; b[i] = b[i + 1] - 1; } } else { int j = i; while (s[j] != 'R') { j--; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j + 1]++; b[i] = j + 1; } } } else { int j = i; while (s[j] != 'L') { j++; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j - 1]++; b[i] = j - 1; } } } } else { rep(i, s.size()) { int count = 0; if (s[i] == 'L') { int j = i; while (s[j] != 'R') { j--; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j + 1]++; b[i] = j + 1; } } else { if (i >= 1 && s[i - 1] == 'R') { if (s[b[i - 1]] == 'L') { a[b[i - 1] - 1]++; b[i] = b[i - 1] - 1; } else { a[b[i - 1] + 1]++; b[i] = b[i - 1] + 1; } } else { int j = i; while (s[j] != 'L') { j++; count++; } if (count % 2 == 0) { a[j]++; b[i] = j; } else { a[j - 1]++; b[i] = j - 1; } } } } } rep(i, s.size()) cout << a[i] << " "; }
replace
32
33
32
33
TLE
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define MAX 99999999999ll #define MIN -99999999999ll #define setbit bitset<8> #define flagcount __builtin_popcount #define flag(x) (1 << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1 << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define count2way(v, x) high2way(v, x) - low2way(v, x) #define lower(v, x) \ low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならnを出力 #define higher(v, x) \ high2way(v, x) - v.begin() - \ 1 // 1番左が0、もし見つからないならn-1を出力(注意) #define putout(a) cout << a << endl #define putout2(a, b) \ putout(a); \ putout(b) #define putout3(a, b, c) \ putout(a); \ putout(b); \ putout(c) #define putout4(a, b, c, d) \ putout(a); \ putout(b); \ putout(c); \ putout(d) #define putout5(a, b, c, d, e) \ putout(a); \ putout(b); \ putout(c); \ putout(d); \ putout(e) #define Gput(a, b) G[a].push_back(b) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e #define sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) #define erase(s) s.erase(s.end() - 1) // 文字列sの末尾削除 ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } ll lcm(ll x, ll y) { ll z = gcd(x, y); return x * y / z; } ll primejudge(ll n) { if (n < 2) return 0; else if (n == 2) return 1; else if (n % 2 == 0) return 0; double sqrtn = sqrt(n); Loop(i, 3, sqrtn + 1) { if (n % i == 0) { return 0; } i++; } return 1; } string RLE(string s) { ll n = s.size(); char now = '.'; ll count = 1; string press; loop(i, n) { if (s[i] != now) { if (i) { press += now; press += to_string(count); } now = s[i]; count = 1; continue; } else count++; } press += now; press += to_string(count); return press; } int main() { cout << fixed << setprecision(30); string s; cin >> s; string x = RLE(s); ll n = x.size(); ll rcount = 0; loop(i, n) if (x[i] == 'R') rcount++; ll area = 0; loop(i, rcount) { string a, b; ll p1 = 0, p2 = 0; Loop(j, area, n) { if (x[j] == 'L') { p1 = j - 1; break; } } Loop(j, p1, n) if (x[j] == 'R') { p2 = j - 1; break; } Loop(j, area + 1, p1 + 1) a += x[j]; Loop(j, p1 + 2, p2 + 1) b += x[j]; ll r = stoll(a); ll l = stoll(b); loop(j, r - 1) putout(0); ll k = (r + 1) / 2 + l / 2; putout(k); putout(r + l - k); loop(j, l - 1) putout(0); Loop(j, area + 1, n) { if (x[j] == 'R') { area = j; break; } } } }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define MAX 99999999999ll #define MIN -99999999999ll #define setbit bitset<8> #define flagcount __builtin_popcount #define flag(x) (1 << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1 << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define count2way(v, x) high2way(v, x) - low2way(v, x) #define lower(v, x) \ low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならnを出力 #define higher(v, x) \ high2way(v, x) - v.begin() - \ 1 // 1番左が0、もし見つからないならn-1を出力(注意) #define putout(a) cout << a << endl #define putout2(a, b) \ putout(a); \ putout(b) #define putout3(a, b, c) \ putout(a); \ putout(b); \ putout(c) #define putout4(a, b, c, d) \ putout(a); \ putout(b); \ putout(c); \ putout(d) #define putout5(a, b, c, d, e) \ putout(a); \ putout(b); \ putout(c); \ putout(d); \ putout(e) #define Gput(a, b) G[a].push_back(b) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e #define sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) #define erase(s) s.erase(s.end() - 1) // 文字列sの末尾削除 ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } ll lcm(ll x, ll y) { ll z = gcd(x, y); return x * y / z; } ll primejudge(ll n) { if (n < 2) return 0; else if (n == 2) return 1; else if (n % 2 == 0) return 0; double sqrtn = sqrt(n); Loop(i, 3, sqrtn + 1) { if (n % i == 0) { return 0; } i++; } return 1; } string RLE(string s) { ll n = s.size(); char now = '.'; ll count = 1; string press; loop(i, n) { if (s[i] != now) { if (i) { press += now; press += to_string(count); } now = s[i]; count = 1; continue; } else count++; } press += now; press += to_string(count); return press; } int main() { cout << fixed << setprecision(30); string s; cin >> s; string x = RLE(s); ll n = x.size(); ll rcount = 0; loop(i, n) if (x[i] == 'R') rcount++; ll area = 0; loop(i, rcount) { string a, b; ll p1 = 0, p2 = 0; Loop(j, area, n) { if (x[j] == 'L') { p1 = j - 1; break; } } Loop(j, p1, n) if (x[j] == 'R') { p2 = j - 1; break; } if (i == rcount - 1) p2 = n - 1; Loop(j, area + 1, p1 + 1) a += x[j]; Loop(j, p1 + 2, p2 + 1) b += x[j]; ll r = stoll(a); ll l = stoll(b); loop(j, r - 1) putout(0); ll k = (r + 1) / 2 + l / 2; putout(k); putout(r + l - k); loop(j, l - 1) putout(0); Loop(j, area + 1, n) { if (x[j] == 'R') { area = j; break; } } } }
insert
127
127
127
129
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoll
p02954
C++
Runtime Error
#include <bits/stdc++.h> #define fu(i, a, b) for (long long i = a; i <= b; i++) using namespace std; string s; int n, a[1111111]; int ans[1111111]; int main() { #ifndef ONLINE_JUDGE freopen("input.inp", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; n = s.size(); fu(i, 1, n) { if (s[i - 1] == 'L') a[i] = 1; } int slL = 0, slR = 1; fu(i, 2, n + 1) { if (!a[i] && a[i - 1]) { ans[i - slL] = (slL + 1) / 2 + (slR) / 2; ans[i - slL - 1] = (slL) / 2 + (slR + 1) / 2; slL = 0; slR = 0; } slL += a[i]; slR += !a[i]; } fu(i, 1, n) { cout << ans[i] << " "; } }
#include <bits/stdc++.h> #define fu(i, a, b) for (long long i = a; i <= b; i++) using namespace std; string s; int n, a[1111111]; int ans[1111111]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; n = s.size(); fu(i, 1, n) { if (s[i - 1] == 'L') a[i] = 1; } int slL = 0, slR = 1; fu(i, 2, n + 1) { if (!a[i] && a[i - 1]) { ans[i - slL] = (slL + 1) / 2 + (slR) / 2; ans[i - slL - 1] = (slL) / 2 + (slR + 1) / 2; slL = 0; slR = 0; } slL += a[i]; slR += !a[i]; } fu(i, 1, n) { cout << ans[i] << " "; } }
delete
7
10
7
7
0
p02954
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; ll len = s.size(); vector<ll> con; REP(i, len - 1) { if (s[i] == 'R' && s[i + 1] == 'L') con.push_back(i + 1); } vector<ll> ans(len, 0); ll j = 0; REP(i, len) { if (s[i] == 'R') { if (i > con[j]) j++; ll tmp = con[j] - i; if (tmp % 2 == 0) ans[con[j]]++; else ans[con[j] - 1]++; } else { if (i >= con[j]) j++; ll tmp = i - con[j - 1]; if (tmp % 2 == 0) ans[con[j - 1]]++; else ans[con[j - 1] - 1]++; } } REP(i, len) cout << ans[i] << " "; cout << endl; return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; ll len = s.size(); vector<ll> con; REP(i, len - 1) { if (s[i] == 'R' && s[i + 1] == 'L') con.push_back(i + 1); } con.push_back(len); vector<ll> ans(len, 0); ll j = 0; REP(i, len) { if (s[i] == 'R') { if (i > con[j]) j++; ll tmp = con[j] - i; if (tmp % 2 == 0) ans[con[j]]++; else ans[con[j] - 1]++; } else { if (i >= con[j]) j++; ll tmp = i - con[j - 1]; if (tmp % 2 == 0) ans[con[j - 1]]++; else ans[con[j - 1] - 1]++; } } REP(i, len) cout << ans[i] << " "; cout << endl; return 0; }
insert
35
35
35
36
0
p02954
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) long long int mod = 1e9 + 7; bool debug = false; typedef long long ll; int rf(int x, string s) { int i = 0; for (i = x; i < s.size(); i++) { if (s[i] == 'L') break; } if ((i - x) % 2 == 0) return i; else return i - 1; } int lf(int x, string s) { int i = 0; for (i = x; i >= 0; i--) { if (s[i] == 'R') break; } if ((x - i) % 2 == 0) return i; else return i + 1; } int main() { string s; cin >> s; vector<int> p(s.size(), -1); vector<int> map(s.size(), 0); rep(i, s.size()) { if (p[i] == -1) { if (s[i] == 'R') { if (i >= 2) { if (s[i - 2] == 'R' && s[i - 1] == 'R') p[i] = p[i - 2]; else p[i] = rf(i, s); } else p[i] = rf(i, s); } else { p[i] = lf(i, s); if (i < s.size() - 2) { if (s[i + 1] == 'L' && s[i + 2] == 'L') { p[i + 2] = p[i]; } } } } } rep(i, s.size()) map[p[i]] += 1; rep(i, s.size()) { cout << map[i]; if (i != s.size() - 1) cout << " "; } cout << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) long long int mod = 1e9 + 7; bool debug = false; typedef long long ll; int rf(int x, string s) { int i = 0; for (i = x; i < s.size(); i++) { if (s[i] == 'L') break; } if ((i - x) % 2 == 0) return i; else return i - 1; } int lf(int x, string s) { int i = 0; for (i = x; i >= 0; i--) { if (s[i] == 'R') break; } if ((x - i) % 2 == 0) return i; else return i + 1; } int main() { string s; cin >> s; vector<int> p(s.size(), -1); vector<int> map(s.size(), 0); rep(i, s.size()) { if (p[i] == -1) { if (s[i] == 'R') { if (i >= 2) { if (s[i - 2] == 'R' && s[i - 1] == 'R') p[i] = p[i - 2]; else p[i] = rf(i, s); } else p[i] = rf(i, s); } else { if (i >= 2) { if (s[i - 2] == 'L' && s[i - 1] == 'L') p[i] = p[i - 2]; else p[i] = lf(i, s); } else p[i] = lf(i, s); } } } rep(i, s.size()) map[p[i]] += 1; rep(i, s.size()) { cout << map[i]; if (i != s.size() - 1) cout << " "; } cout << endl; return 0; }
replace
48
54
48
55
TLE
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[s.size()]; int ans[10005] = {0}; int k = s.size() - 1; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'L') k = i; if (s[i] == 'R') a[i] = k; } k = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') k = i; if (s[i] == 'L') a[i] = k; } for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { if ((a[i] - i) % 2 == 0) ans[a[i]]++; if ((a[i] - i) % 2 != 0) ans[a[i] - 1]++; } if (s[i] == 'L') { if ((i - a[i]) % 2 != 0) ans[a[i] + 1]++; if ((i - a[i]) % 2 == 0) ans[a[i]]++; } } cout << ans[0]; for (int i = 1; i < s.size(); i++) { cout << ' ' << ans[i]; } cout << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[100005] = {0}; int ans[100005] = {0}; int k = s.size() - 1; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'L') k = i; if (s[i] == 'R') a[i] = k; } k = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') k = i; if (s[i] == 'L') a[i] = k; } for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { if ((a[i] - i) % 2 == 0) ans[a[i]]++; if ((a[i] - i) % 2 != 0) ans[a[i] - 1]++; } if (s[i] == 'L') { if ((i - a[i]) % 2 != 0) ans[a[i] + 1]++; if ((i - a[i]) % 2 == 0) ans[a[i]]++; } } cout << ans[0]; for (int i = 1; i < s.size(); i++) { cout << ' ' << ans[i]; } cout << endl; }
replace
6
8
6
8
0
p02954
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // TYPEDEF // ---------------------------------------- typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; // REPEAT // ---------------------------------------- #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define REPA(i, a) \ for (ll i = 0; i < (ll)(a.size()); i++) \ ; #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define COUT(a) cout << (a) << endl; #define ENDL(a) cout << endl; #define COUTA(i, a) \ for (ll i = 0; i < (ll)(a.size()); i++) { \ cout << (a)[i] << " "; \ } \ cout << endl; // UTIL // ---------------------------------------- #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort((a).begin(), (a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) // DEBUG // ---------------------------------------- #ifdef _DEBUG #define debug(x) cout << "[debug] " << #x << ": " << x << endl #else #define debug(x) #endif template <typename T> void debugV(const vector<T> v) { #ifdef _DEBUG rep(i, v.size()) { cout << i << ":" << v[i] << " "; } cout << endl; #else (void)v; #endif } // BIT FLAG // ---------------------------------------- const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001 const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010 const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100 const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000 const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000 const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000 const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000 const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000 const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000 const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000 const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000 const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000 // CONST // ---------------------------------------- constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr double PI = 3.14159265358979323846; // or M_PI constexpr int MOD = 1000000007; void Main() { string s; cin >> s; // RRLLLLRLRRLL vector<ll> r_index; // RLのRの方のindex vector<ll> kireme_index; // 切れ目のindex char left = 'R'; // kireme_index.pb(0); FOR(i, 1, s.length() - 1) { if (left == 'R') { if (s[i] == 'L') { r_index.pb(i - 1); left = 'L'; } } else { if (s[i] == 'R') { kireme_index.pb(i); left = 'R'; } } } // COUTA(i, kireme_index); // COUTA(i, r_index); vll ans(s.length(), 0); ll index = 0; REP(i, s.length()) { if (i == kireme_index[index]) { index++; } ll de = abs(r_index[index] - i); if (de % 2 == 0) { ans[r_index[index]]++; } else { ans[r_index[index] + 1]++; } } COUTA(i, ans); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); } /* 4 3 1 2 2 3 2 4 2 10 1 100 3 1 */
#include <bits/stdc++.h> using namespace std; // TYPEDEF // ---------------------------------------- typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; // REPEAT // ---------------------------------------- #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define REPA(i, a) \ for (ll i = 0; i < (ll)(a.size()); i++) \ ; #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define COUT(a) cout << (a) << endl; #define ENDL(a) cout << endl; #define COUTA(i, a) \ for (ll i = 0; i < (ll)(a.size()); i++) { \ cout << (a)[i] << " "; \ } \ cout << endl; // UTIL // ---------------------------------------- #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define SORT(a) sort((a).begin(), (a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) // DEBUG // ---------------------------------------- #ifdef _DEBUG #define debug(x) cout << "[debug] " << #x << ": " << x << endl #else #define debug(x) #endif template <typename T> void debugV(const vector<T> v) { #ifdef _DEBUG rep(i, v.size()) { cout << i << ":" << v[i] << " "; } cout << endl; #else (void)v; #endif } // BIT FLAG // ---------------------------------------- const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001 const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010 const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100 const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000 const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000 const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000 const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000 const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000 const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000 const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000 const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000 const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000 // CONST // ---------------------------------------- constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr double PI = 3.14159265358979323846; // or M_PI constexpr int MOD = 1000000007; void Main() { string s; cin >> s; // RRLLLLRLRRLL vector<ll> r_index; // RLのRの方のindex vector<ll> kireme_index; // 切れ目のindex char left = 'R'; // kireme_index.pb(0); FOR(i, 1, s.length() - 1) { if (left == 'R') { if (s[i] == 'L') { r_index.pb(i - 1); left = 'L'; } } else { if (s[i] == 'R') { kireme_index.pb(i); left = 'R'; } } } // COUTA(i, kireme_index); // COUTA(i, r_index); vll ans(s.length(), 0); ll index = 0; REP(i, s.length()) { if ((kireme_index.size() != 0) and (i == kireme_index[index])) { index++; } ll de = abs(r_index[index] - i); if (de % 2 == 0) { ans[r_index[index]]++; } else { ans[r_index[index] + 1]++; } } COUTA(i, ans); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); } /* 4 3 1 2 2 3 2 4 2 10 1 100 3 1 */
replace
107
108
107
108
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n); int sum = 0; for (auto &x : a) { cin >> x; sum += x; } vector<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.emplace_back(i); if (i * i < sum) { d.emplace_back(sum / i); } } } sort(d.begin(), d.end(), greater<int>()); for (int x : d) { auto r = a; for (auto &y : r) { y %= x; } sort(r.begin(), r.end()); vector<int> pre(n), suf(n); int tmp = 0; for (int i = 0; i < n; i++) { pre[i] = tmp += r[i]; } tmp = 0; for (int i = n - 1; i >= 0; i--) { suf[i] = tmp += r[i]; } int least = -1; for (int i = n - 2; i >= 0; i--) { if (pre[i] + suf[i + 1] == x * (n - i - 1)) { least = pre[i]; break; } } assert(least > -1); if (least <= k) { cout << x; break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); cout << endl; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n); int sum = 0; for (auto &x : a) { cin >> x; sum += x; } vector<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.emplace_back(i); if (i * i < sum) { d.emplace_back(sum / i); } } } sort(d.begin(), d.end(), greater<int>()); for (int x : d) { auto r = a; for (auto &y : r) { y %= x; } sort(r.begin(), r.end()); vector<int> pre(n), suf(n); int tmp = 0; for (int i = 0; i < n; i++) { pre[i] = tmp += r[i]; } tmp = 0; for (int i = n - 1; i >= 0; i--) { suf[i] = tmp += r[i]; } int least = -1; int tot = suf[0]; for (int i = n - 1; i >= 0; i--) { if (tot == x * (n - i - 1)) { least = pre[i]; break; } } assert(least > -1); if (least <= k) { cout << x; break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); cout << endl; }
replace
39
41
39
42
0
p02955
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; template <typename T> istream &operator>>(istream &is, vector<T> &vs) { for (T &v : vs) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) { for (const T &v : vs) os << v << " "; return os; } int main() { int N, K; cin >> N >> K; vector<int> A(N); cin >> A; int S = accumulate(A.begin(), A.end(), 0); // Enumerate common divisors, and sort descent. vector<int> d; for (int i = 1; i * i <= S; ++i) { if (S % i == 0) { d.push_back(i); d.push_back(S / i); } } sort(d.rbegin(), d.rend()); for (int x : d) { vector<int> d2; for (int v : A) { if (v % x != 0) d2.push_back(v % x); } int N2 = d2.size(); if (N2 == 0) { cout << x << endl; return 0; } sort(d2.begin(), d2.end()); vector<int> S1(N2 + 1), S2(N2 + 1); S1[0] = 0, S2[N2] = 0; for (int i = 0; i <= N2; ++i) S1[i + 1] = S1[i] + d2[i]; for (int i = N2; i > 0; --i) S2[i - 1] = S2[i] + (x - d2[i - 1]); for (int i = 0; i < N2; ++i) { if (S1[i] == S2[i] && S1[i] <= K) { cout << x << endl; return 0; } } } }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; template <typename T> istream &operator>>(istream &is, vector<T> &vs) { for (T &v : vs) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) { for (const T &v : vs) os << v << " "; return os; } int main() { int N, K; cin >> N >> K; vector<int> A(N); cin >> A; int S = accumulate(A.begin(), A.end(), 0); // Enumerate common divisors, and sort descent. vector<int> d; for (int i = 1; i * i <= S; ++i) { if (S % i == 0) { d.push_back(i); d.push_back(S / i); } } sort(d.rbegin(), d.rend()); for (int x : d) { vector<int> d2; for (int v : A) { if (v % x != 0) d2.push_back(v % x); } int N2 = d2.size(); if (N2 == 0) { cout << x << endl; return 0; } sort(d2.begin(), d2.end()); vector<int> S1(N2 + 1), S2(N2 + 1); S1[0] = 0, S2[N2] = 0; for (int i = 0; i < N2; ++i) S1[i + 1] = S1[i] + d2[i]; for (int i = N2; i > 0; --i) S2[i - 1] = S2[i] + (x - d2[i - 1]); for (int i = 0; i < N2; ++i) { if (S1[i] == S2[i] && S1[i] <= K) { cout << x << endl; return 0; } } } }
replace
63
64
63
64
0
p02955
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; int read() { int xx = 0, ff = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar(); } return xx * ff; } long long READ() { long long xx = 0, ff = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar(); } return xx * ff; } char one() { char ch = getchar(); while (ch == ' ' || ch == '\n') ch = getchar(); return ch; } inline long long mymin(long long A, long long B) { if (A < B) return A; return B; } inline long long mymax(long long A, long long B) { if (A > B) return A; return B; } const int maxn = 510; int N, K, a[maxn], sum; int p[maxn], cnt; long long b[maxn]; void div(int x) { for (int i = 1; i * i <= x; i++) if (x % i == 0) { p[++cnt] = i; if (i * i != x) p[++cnt] = x / i; } } bool check(int x) { for (int i = 1; i <= N; i++) b[i] = a[i] % x; sort(b + 1, b + 1 + N); for (int i = 1; i <= N; i++) b[i] += b[i - 1]; long long ret = K + 1; for (int i = 1; i <= N; i++) ret = mymin(ret, mymax(b[i], 1LL * (N - i) * x - (b[N] - b[i]))); return ret <= K; } int main() { // freopen("in","r",stdin); N = read(), K = read(); for (int i = 1; i <= N; i++) a[i] = read(), sum += a[i]; div(sum); int ans = 1; for (int i = 1; i <= cnt; i++) if (p[i] > ans && check(p[i])) ans = max(ans, p[i]); printf("%d\n", ans); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; int read() { int xx = 0, ff = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar(); } return xx * ff; } long long READ() { long long xx = 0, ff = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = xx * 10 + ch - '0'; ch = getchar(); } return xx * ff; } char one() { char ch = getchar(); while (ch == ' ' || ch == '\n') ch = getchar(); return ch; } inline long long mymin(long long A, long long B) { if (A < B) return A; return B; } inline long long mymax(long long A, long long B) { if (A > B) return A; return B; } const int maxn = 510; int N, K, a[maxn], sum; int p[10010], cnt; long long b[maxn]; void div(int x) { for (int i = 1; i * i <= x; i++) if (x % i == 0) { p[++cnt] = i; if (i * i != x) p[++cnt] = x / i; } } bool check(int x) { for (int i = 1; i <= N; i++) b[i] = a[i] % x; sort(b + 1, b + 1 + N); for (int i = 1; i <= N; i++) b[i] += b[i - 1]; long long ret = K + 1; for (int i = 1; i <= N; i++) ret = mymin(ret, mymax(b[i], 1LL * (N - i) * x - (b[N] - b[i]))); return ret <= K; } int main() { // freopen("in","r",stdin); N = read(), K = read(); for (int i = 1; i <= N; i++) a[i] = read(), sum += a[i]; div(sum); int ans = 1; for (int i = 1; i <= cnt; i++) if (p[i] > ans && check(p[i])) ans = max(ans, p[i]); printf("%d\n", ans); return 0; }
replace
61
62
61
62
0
p02955
C++
Runtime Error
#include <algorithm> #include <iostream> #include <set> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; ll sum = 0; rep(i, n) sum += a[i]; set<ll> candidates; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { candidates.insert(i); candidates.insert(i / sum); } } ll ans = 1; for (ll x : candidates) { ll need; { vector<ll> r(n); rep(i, n) r[i] = a[i] % x; sort(r.begin(), r.end()); ll B = 0; rep(i, n) B += x - r[i]; ll A = 0; need = 1e18; rep(i, n) { A += r[i]; B -= x - r[i]; need = min(need, max(A, B)); } } if (need <= k) ans = max(ans, x); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; ll sum = 0; rep(i, n) sum += a[i]; set<ll> candidates; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { candidates.insert(i); candidates.insert(sum / i); } } ll ans = 1; for (ll x : candidates) { ll need; { vector<ll> r(n); rep(i, n) r[i] = a[i] % x; sort(r.begin(), r.end()); ll B = 0; rep(i, n) B += x - r[i]; ll A = 0; need = 1e18; rep(i, n) { A += r[i]; B -= x - r[i]; need = min(need, max(A, B)); } } if (need <= k) ans = max(ans, x); } cout << ans << endl; return 0; }
replace
19
20
19
20
-8
p02955
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; ++i) #define MOD (int)1e9 + 7 int main() { ll n, k; cin >> n >> k; vector<ll> a(n); ll s = 0; rep(i, n) { cin >> a[i]; s += a[i]; } vector<ll> mod; for (ll i = s; i >= sqrt(s); i--) { if (s % i == 0) { mod.emplace_back(i); mod.emplace_back(s / i); } } sort(mod.begin(), mod.end(), greater<>()); for (int i = 0; i < mod.size(); i++) { ll m = mod[i]; ll cnt = 0; vector<ll> amari(n); rep(j, n) { amari[j] = a[j] % m; } sort(amari.begin(), amari.end()); ll l = 0, r = n - 1; while (l < r) { if (amari[l] < m - amari[r]) { cnt += amari[l]; amari[r] += amari[l]; amari[l] = 0; l++; } else { cnt += (m - amari[r]); amari[l] -= (m - amari[r]); amari[r] = m; r--; } } if (cnt <= k) { cout << m << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; ++i) #define MOD (int)1e9 + 7 int main() { ll n, k; cin >> n >> k; vector<ll> a(n); ll s = 0; rep(i, n) { cin >> a[i]; s += a[i]; } vector<ll> mod; for (ll i = 1; i <= sqrt(s); i++) { if (s % i == 0) { mod.emplace_back(i); mod.emplace_back(s / i); } } sort(mod.begin(), mod.end(), greater<>()); for (int i = 0; i < mod.size(); i++) { ll m = mod[i]; ll cnt = 0; vector<ll> amari(n); rep(j, n) { amari[j] = a[j] % m; } sort(amari.begin(), amari.end()); ll l = 0, r = n - 1; while (l < r) { if (amari[l] < m - amari[r]) { cnt += amari[l]; amari[r] += amari[l]; amari[l] = 0; l++; } else { cnt += (m - amari[r]); amari[l] -= (m - amari[r]); amari[r] = m; r--; } } if (cnt <= k) { cout << m << endl; return 0; } } }
replace
18
19
18
19
TLE
p02955
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, x, n) for (int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x.size()) #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define uniq(x) x.erase(unique(x.begin(), x.end()), x.end()) #define F first #define S second #define mp make_pair #define eb emplace_back #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; typedef long long ll; /* --- INFの値が適切か確認する --- */ // const int INF = 1 << 30; // const ll INF = 1LL << 60; // const int MOD = 1000000007; int main() { ll N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A[i]; int sum = 0; rep(i, N) sum += A[i]; vector<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.eb(i); if (sum / i != i) { d.eb(sum / i); } } } sort(rall(d)); rep(i, sz(d)) { int mod = d[i]; vector<int> a = A; rep(j, sz(a)) a[i] %= mod; sort(all(a)); ll m = 0, p = 0; rep(j, sz(a)) p += (mod - a[j]); rep(j, sz(a)) { m += a[j]; p -= (mod - a[j]); if (m == p && m <= K) { cout << mod << endl; return 0; } } } cout << "-1" << endl; }
#include <bits/stdc++.h> #define REP(i, x, n) for (int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x.size()) #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define uniq(x) x.erase(unique(x.begin(), x.end()), x.end()) #define F first #define S second #define mp make_pair #define eb emplace_back #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; typedef long long ll; /* --- INFの値が適切か確認する --- */ // const int INF = 1 << 30; // const ll INF = 1LL << 60; // const int MOD = 1000000007; int main() { ll N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A[i]; int sum = 0; rep(i, N) sum += A[i]; vector<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.eb(i); if (sum / i != i) { d.eb(sum / i); } } } sort(rall(d)); rep(i, sz(d)) { int mod = d[i]; vector<int> a = A; rep(j, sz(a)) a[j] %= mod; sort(all(a)); ll m = 0, p = 0; rep(j, sz(a)) p += (mod - a[j]); rep(j, sz(a)) { m += a[j]; p -= (mod - a[j]); if (m == p && m <= K) { cout << mod << endl; return 0; } } } cout << "-1" << endl; }
replace
50
51
50
51
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef pair<P, int> T; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LLINF 100000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int N, K; int A[595]; bool check(int t) { vector<int> vec; for (int i = 0; i < N; i++) { if (A[i] % t != 0) vec.pb(A[i] % t); } sort(all(vec)); int M = vec.size(); vector<ll> a(M); vector<ll> b(M); for (int i = 0; i < M; i++) { a[i] = vec[i]; b[i] = t - vec[i]; } for (int i = 1; i < M; i++) { a[i] += a[i - 1]; b[M - 1 - i] += b[M - i]; } ll m = min(a[M - 1], b[0]); for (int i = 0; i < M - 1; i++) { m = min(m, max(a[i], b[i + 1])); } return m <= (ll)K; } int main() { cin >> N; cin >> K; int s = 0; for (int i = 0; i < N; i++) { cin >> A[i]; s += A[i]; } vector<int> vec; for (int i = 1; i * i <= s; i++) { if (s % i == 0) { vec.pb(i); if (i != s / i) vec.pb(s / i); } } sort(all(vec)); for (int i = vec.size() - 1; i >= 0; i--) { if (check(vec[i])) { cout << vec[i] << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef pair<P, int> T; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LLINF 100000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int N, K; int A[595]; bool check(int t) { vector<int> vec; for (int i = 0; i < N; i++) { if (A[i] % t != 0) vec.pb(A[i] % t); } sort(all(vec)); int M = vec.size(); if (M == 0) return true; vector<ll> a(M); vector<ll> b(M); for (int i = 0; i < M; i++) { a[i] = vec[i]; b[i] = t - vec[i]; } for (int i = 1; i < M; i++) { a[i] += a[i - 1]; b[M - 1 - i] += b[M - i]; } ll m = min(a[M - 1], b[0]); for (int i = 0; i < M - 1; i++) { m = min(m, max(a[i], b[i + 1])); } return m <= (ll)K; } int main() { cin >> N; cin >> K; int s = 0; for (int i = 0; i < N; i++) { cin >> A[i]; s += A[i]; } vector<int> vec; for (int i = 1; i * i <= s; i++) { if (s % i == 0) { vec.pb(i); if (i != s / i) vec.pb(s / i); } } sort(all(vec)); for (int i = vec.size() - 1; i >= 0; i--) { if (check(vec[i])) { cout << vec[i] << endl; return 0; } } return 0; }
insert
38
38
38
40
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M 1000000007 #define F first #define S second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; #define pb push_back #define M6 1000009 #define M5 500009 #define pi 3.14159265 #define epsilon 1e-6 ll power(ll x, ll n, ll m) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % m; n /= 2; x = (x * x) % m; } return res; } bool same(ld a, ld b) { return fabs(a - b) < epsilon; } // ll sp[M6*10]; // void sieve(){ // for(int i=2;i<M6*10;i++) sp[i]=i; // for(int i=2;i*i<M6*10;i++){ // if(sp[i]!=i) continue; // for(int j=i*2;j<M6*10;j+=i) { // if(sp[j]==j) sp[j]=i; // } // } // } ll n, m, A[M5]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); // sieve(); // init(); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll tc = 1, t = 0, i, j, k, l, r, a, b, c; // cin>>tc; while (t++ < tc) { // cout<<"Case #"<<t<<": "; cin >> n >> k; ll sum = 0; for (i = 1; i <= n; i++) { cin >> A[i]; sum += A[i]; } vector<ll> v; for (i = 1; i * i <= sum; i++) { if (sum % i == 0) { v.pb(i); v.pb(sum / i); } } sort(A + 1, A + n + 1); sort(v.begin(), v.end()); ll ans; for (i = v.size() - 1; i >= 0; i--) { vector<ll> vs; for (j = 1; j <= n; j++) if (A[j] % v[i]) vs.pb(A[j] % v[i]); sort(vs.begin(), vs.end()); ll cur = 0; for (j = 0; j < vs.size(); j++) { if (cur + vs[j] <= k) { cur += vs[j]; vs[j] = 0; } else break; } for (; j < vs.size(); j++) { if ((v[i] - vs[j]) <= cur) { cur -= v[i] - vs[j]; vs[j] = 0; } else break; } if (vs[vs.size() - 1] == 0) { ans = v[i]; break; } } cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; #define M 1000000007 #define F first #define S second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; #define pb push_back #define M6 1000009 #define M5 500009 #define pi 3.14159265 #define epsilon 1e-6 ll power(ll x, ll n, ll m) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % m; n /= 2; x = (x * x) % m; } return res; } bool same(ld a, ld b) { return fabs(a - b) < epsilon; } // ll sp[M6*10]; // void sieve(){ // for(int i=2;i<M6*10;i++) sp[i]=i; // for(int i=2;i*i<M6*10;i++){ // if(sp[i]!=i) continue; // for(int j=i*2;j<M6*10;j+=i) { // if(sp[j]==j) sp[j]=i; // } // } // } ll n, m, A[M5]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); // sieve(); // init(); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll tc = 1, t = 0, i, j, k, l, r, a, b, c; // cin>>tc; while (t++ < tc) { // cout<<"Case #"<<t<<": "; cin >> n >> k; ll sum = 0; for (i = 1; i <= n; i++) { cin >> A[i]; sum += A[i]; } vector<ll> v; for (i = 1; i * i <= sum; i++) { if (sum % i == 0) { v.pb(i); v.pb(sum / i); } } sort(A + 1, A + n + 1); sort(v.begin(), v.end()); ll ans; for (i = v.size() - 1; i >= 0; i--) { vector<ll> vs; for (j = 1; j <= n; j++) if (A[j] % v[i]) vs.pb(A[j] % v[i]); if (vs.size() == 0) { ans = v[i]; break; } sort(vs.begin(), vs.end()); ll cur = 0; for (j = 0; j < vs.size(); j++) { if (cur + vs[j] <= k) { cur += vs[j]; vs[j] = 0; } else break; } for (; j < vs.size(); j++) { if ((v[i] - vs[j]) <= cur) { cur -= v[i] - vs[j]; vs[j] = 0; } else break; } if (vs[vs.size() - 1] == 0) { ans = v[i]; break; } } cout << ans; } return 0; }
insert
67
67
67
71
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int ll; typedef pair<int, int> P; int n, k, a[1000]; int main() { cin >> n >> k; rep(i, n) cin >> a[i]; int sum = 0; rep(i, n) sum += a[i]; vector<int> g(0); for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { g.emplace_back(i); g.emplace_back(sum / i); } } sort(g.begin(), g.end(), greater<int>()); int res = 0; for (auto x : g) { int b[n]; rep(i, n) b[n] = a[n] % x; sort(b, b + n, greater<int>()); int sum = 0; rep(i, n) sum += b[i]; int tmp = 0; rep(i, sum / x) tmp += b[i]; sum -= tmp; if (sum <= k) { cout << x << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int ll; typedef pair<int, int> P; int n, k, a[1000]; int main() { cin >> n >> k; rep(i, n) cin >> a[i]; int sum = 0; rep(i, n) sum += a[i]; vector<int> g(0); for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { g.emplace_back(i); g.emplace_back(sum / i); } } sort(g.begin(), g.end(), greater<int>()); int res = 0; for (auto x : g) { int b[n]; rep(i, n) b[i] = a[i] % x; sort(b, b + n, greater<int>()); int sum = 0; rep(i, n) sum += b[i]; int tmp = 0; rep(i, sum / x) tmp += b[i]; sum -= tmp; if (sum <= k) { cout << x << endl; break; } } return 0; }
replace
26
27
26
27
0
p02955
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int infI = 1e9 + 5; const long long infL = 1e18; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; #define mp make_pair #define pb push_back #define ii pair<int, int> #define ll long long #define pll pair<ll, ll> #define vl vector<vector<ll>> #define vi vector<vector<int>> #define eb emplace_back #define forn(i, a, b) for (int i = a; i < b; i++) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define endl '\n' #define popb pop_back(); #define se second #define fi first int n, k; int a[505]; int main() { fastio; cin >> n >> k; ll sum = 0; forn(i, 0, n) { cin >> a[i]; sum += a[i]; } vector<int> f; forn(i, 1, sqrt(sum)) { f.pb(i); f.pb(sum / i); } ll ans = 0; forn(i, 0, f.size()) { int a1 = f[i]; ll total = 0, used = 0; multiset<int> v; forn(i, 0, n) { v.insert(a[i] % a1); total += (a1 - a[i] % a1); } for (auto itr = v.begin(); itr != v.end(); ++itr) { used += *itr; total -= (a1 - *itr); if (used == total && used <= k) { ans = max(ans, (ll)a1); } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int infI = 1e9 + 5; const long long infL = 1e18; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; #define mp make_pair #define pb push_back #define ii pair<int, int> #define ll long long #define pll pair<ll, ll> #define vl vector<vector<ll>> #define vi vector<vector<int>> #define eb emplace_back #define forn(i, a, b) for (int i = a; i < b; i++) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define endl '\n' #define popb pop_back(); #define se second #define fi first int n, k; int a[505]; int main() { fastio; cin >> n >> k; ll sum = 0; forn(i, 0, n) { cin >> a[i]; sum += a[i]; } vector<int> f; forn(i, 1, sqrt(sum)) { if (sum % i == 0) { f.pb(i); f.pb(sum / i); } } ll ans = 0; forn(i, 0, f.size()) { int a1 = f[i]; ll total = 0, used = 0; multiset<int> v; forn(i, 0, n) { v.insert(a[i] % a1); total += (a1 - a[i] % a1); } for (auto itr = v.begin(); itr != v.end(); ++itr) { used += *itr; total -= (a1 - *itr); if (used == total && used <= k) { ans = max(ans, (ll)a1); } } } cout << ans; return 0; }
replace
39
41
39
43
TLE
p02955
C++
Runtime Error
#include <bits/stdc++.h> #define N 505 #define int long long using namespace std; int n, m, a[N], p[N], tot, cnt, K, L[N], R[N], M = 10000000; bool check(int x) { memset(L, 0, sizeof(L)); memset(R, 0, sizeof(R)); for (int i = 1; i <= n; i++) { int t = a[i] % x; L[i] = t; } sort(L + 1, L + n + 1); R[n] = x - L[n]; for (int i = n - 1; i >= 1; i--) R[i] = R[i + 1] + x - L[i]; for (int i = 2; i <= n; i++) L[i] += L[i - 1]; int res = 1e9; for (int i = 1; i <= n; i++) res = min(res, max(L[i], R[i + 1])); return res <= K; } signed main() { scanf("%lld%lld", &n, &K); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), m += a[i]; for (int i = 1; 1ll * i * i <= 1ll * m; i++) if (m % i == 0) { p[++tot] = i; if (1ll * i * i != 1ll * m) p[++tot] = m / i; } sort(p + 1, p + tot + 1); for (int i = tot; i >= 1; i--) { if (check(p[i])) { printf("%lld\n", p[i]); return 0; } } return 0; }
#include <bits/stdc++.h> #define N 505 #define int long long using namespace std; int n, m, a[N], p[N * N], tot, cnt, K, L[N], R[N]; bool check(int x) { memset(L, 0, sizeof(L)); memset(R, 0, sizeof(R)); for (int i = 1; i <= n; i++) { int t = a[i] % x; L[i] = t; } sort(L + 1, L + n + 1); R[n] = x - L[n]; for (int i = n - 1; i >= 1; i--) R[i] = R[i + 1] + x - L[i]; for (int i = 2; i <= n; i++) L[i] += L[i - 1]; int res = 1e9; for (int i = 1; i <= n; i++) res = min(res, max(L[i], R[i + 1])); return res <= K; } signed main() { scanf("%lld%lld", &n, &K); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), m += a[i]; for (int i = 1; 1ll * i * i <= 1ll * m; i++) if (m % i == 0) { p[++tot] = i; if (1ll * i * i != 1ll * m) p[++tot] = m / i; } sort(p + 1, p + tot + 1); for (int i = tot; i >= 1; i--) { if (check(p[i])) { printf("%lld\n", p[i]); return 0; } } return 0; }
replace
4
5
4
5
0
p02955
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; vector<long long> div(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; ++i) { if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } } return res; } int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> divs = div(accumulate(a.begin(), a.end(), 0LL)); long long ans = 0; for (auto &e : divs) { vector<long long> mods(n); for (int i = 0; i < n; i++) mods[i] = a[i] % e; sort(mods.begin(), mods.end()); vector<long long> minus(n + 1); for (int i = 0; i < n; i++) minus[i + 1] = minus[i] + mods[i]; vector<long long> plus(n + 1); for (int i = n - 1; i >= 0; i++) plus[i] = plus[i + 1] + e - mods[i]; for (long long i = 0; i <= n; ++i) { if (max(plus[i], minus[i]) <= k) ans = max(ans, e); } } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; vector<long long> div(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; ++i) { if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } } return res; } int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> divs = div(accumulate(a.begin(), a.end(), 0LL)); long long ans = 0; for (auto &e : divs) { vector<long long> mods(n); for (int i = 0; i < n; i++) mods[i] = a[i] % e; sort(mods.begin(), mods.end()); vector<long long> minus(n + 1); for (int i = 0; i < n; i++) minus[i + 1] = minus[i] + mods[i]; vector<long long> plus(n + 1); for (int i = n - 1; i >= 0; i--) plus[i] = plus[i + 1] + e - mods[i]; for (long long i = 0; i <= n; ++i) { if (max(plus[i], minus[i]) <= k) ans = max(ans, e); } } cout << ans << endl; }
replace
48
49
48
49
-11
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) #define fi first #define se second template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; template <class T> vector<T> divisor(T x) { vector<T> res; for (T i = 1; i * i <= x; i++) { if (x % i == 0) { res.push_back(i); if (i != x / i) { res.push_back(x / i); } } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); ll sum = 0; rep(i, n) { cin >> a[i]; sum += a[i]; } vector<ll> ret = divisor(sum); sort(begin(ret), end(ret), greater<ll>()); rep(i, len(ret)) { ll now = ret[i]; vector<ll> cnt; rep(j, n) { if (a[j] % now == 0) continue; cnt.push_back(a[j] % now); } sort(begin(cnt), end(cnt)); ll m = len(cnt); // cout<<now<<endl; vector<ll> l(m, 0); l[0] = cnt[0]; FOR(j, 1, m) { l[j] = l[j - 1] + cnt[j]; } // cout_vec(l); rep(j, m) { if (l[j] == (now * (m - 1 - j) - (l[m - 1] - l[j])) && l[j] <= k) { cout << now << endl; return 0; } } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) #define fi first #define se second template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; template <class T> vector<T> divisor(T x) { vector<T> res; for (T i = 1; i * i <= x; i++) { if (x % i == 0) { res.push_back(i); if (i != x / i) { res.push_back(x / i); } } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); ll sum = 0; rep(i, n) { cin >> a[i]; sum += a[i]; } vector<ll> ret = divisor(sum); sort(begin(ret), end(ret), greater<ll>()); rep(i, len(ret)) { ll now = ret[i]; if (now == 1) { cout << now << endl; return 0; } vector<ll> cnt; rep(j, n) { if (a[j] % now == 0) continue; cnt.push_back(a[j] % now); } sort(begin(cnt), end(cnt)); ll m = len(cnt); // cout<<now<<endl; vector<ll> l(m, 0); l[0] = cnt[0]; FOR(j, 1, m) { l[j] = l[j - 1] + cnt[j]; } // cout_vec(l); rep(j, m) { if (l[j] == (now * (m - 1 - j) - (l[m - 1] - l[j])) && l[j] <= k) { cout << now << endl; return 0; } } } }
insert
47
47
47
51
0
p02955
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = int64_t; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } sort(A.rbegin(), A.rend()); auto minOp = [&](ll x) { // Aを全てxで割り切れるようにするときにかかる最小回数 vector<ll> mod(N); for (ll i = 0; i < N; i++) { mod[i] = A[i] % x; } sort(mod.begin(), mod.end()); ll back = N - 1; ll num = 0; for (ll i = 0; i < N; i++) { // mod[i]は減らす,mod[back]は増やす if (mod[i] == x - mod[back]) { ll curr_op_num = mod[i]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; back--; } else if (mod[i] > x - mod[back]) { ll curr_op_num = x - mod[back]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; back--; i--; } else { ll curr_op_num = mod[i]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; } } for (ll i = 0; i < N; i++) { assert(mod[i] % x == 0); } return num; }; ll sum = accumulate(A.begin(), A.end(), (ll)0); ll ans = 0; for (ll i = 1; i * i <= sum; i++) { if (sum % i != 0) { continue; } if (minOp(sum / i) <= K) { ans = max(ans, sum / i); continue; } if (minOp(i) <= K) { ans = max(ans, i); } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; using ll = int64_t; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } sort(A.rbegin(), A.rend()); auto minOp = [&](ll x) { // Aを全てxで割り切れるようにするときにかかる最小回数 vector<ll> mod(N); for (ll i = 0; i < N; i++) { mod[i] = A[i] % x; } sort(mod.begin(), mod.end()); ll back = N - 1; ll num = 0; for (ll i = 0; i < back; i++) { // mod[i]は減らす,mod[back]は増やす if (mod[i] == x - mod[back]) { ll curr_op_num = mod[i]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; back--; } else if (mod[i] > x - mod[back]) { ll curr_op_num = x - mod[back]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; back--; i--; } else { ll curr_op_num = mod[i]; num += curr_op_num; mod[i] -= curr_op_num; mod[back] += curr_op_num; } } for (ll i = 0; i < N; i++) { assert(mod[i] % x == 0); } return num; }; ll sum = accumulate(A.begin(), A.end(), (ll)0); ll ans = 0; for (ll i = 1; i * i <= sum; i++) { if (sum % i != 0) { continue; } if (minOp(sum / i) <= K) { ans = max(ans, sum / i); continue; } if (minOp(i) <= K) { ans = max(ans, i); } } cout << ans << endl; }
replace
22
23
22
23
0
p02955
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using ll = long long; // LLONG_MAX #define int long long #define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a) + (size)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a))) #define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a))) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define CONTAINS_MAP(m, a) (m).find((a)) != m.end() using namespace std; int N, K; int A[501]; int func(int n) { int a[501]; for (int i = 0; i < N; i++) { a[i] = A[i] % n; } ARY_SORT(a, N); int cnt = 0; int end = N - 1; for (int i = 0; i <= end; i++) { int end_rest = n - a[end]; if (a[i] == end_rest) { cnt += a[i]; a[end] += a[i]; a[i] = 0; end--; } else if (a[i] < end_rest) { cnt += a[i]; a[end] += a[i]; a[i] = 0; } else if (a[i] > end_rest) { int sub = n - a[end]; cnt += sub; a[i] -= sub; a[end] += sub; end--; i--; } } return cnt; } signed main() { cin >> N >> K; int sum = 0; REP(i, N) { cin >> A[i]; sum += A[i]; } int num = sum; int max = 0; for (int i = 1; i <= num; i++) { if (sum % i == 0) { num = sum / i; int a = func(i); int b = func(num); if (a <= K) max = MAX(max, i); if (b <= K) max = MAX(max, num); } } cout << max << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using ll = long long; // LLONG_MAX #define int long long #define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a) + (size)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a))) #define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a))) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define CONTAINS_MAP(m, a) (m).find((a)) != m.end() using namespace std; int N, K; int A[501]; int func(int n) { int a[501]; for (int i = 0; i < N; i++) { a[i] = A[i] % n; } ARY_SORT(a, N); int cnt = 0; int end = N - 1; for (int i = 0; i <= end; i++) { int end_rest = n - a[end]; if (a[i] == end_rest) { cnt += a[i]; a[end] += a[i]; a[i] = 0; end--; } else if (a[i] < end_rest) { cnt += a[i]; a[end] += a[i]; a[i] = 0; } else if (a[i] > end_rest) { int sub = n - a[end]; cnt += sub; a[i] -= sub; a[end] += sub; end--; i--; } } return cnt; } signed main() { cin >> N >> K; int sum = 0; REP(i, N) { cin >> A[i]; sum += A[i]; } int num = sum; int max = 0; for (int i = 1; i <= num; i++) { if (sum % i == 0) { num = sum / i; int a = func(i); int b = func(num); if (a <= K) max = MAX(max, i); if (b <= K) { cout << num << endl; return 0; } } } cout << max << endl; }
replace
95
97
95
99
TLE
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define PB push_back #define ZERO (1e-10) #define INF int(1e9 + 1) #define CL(A, I) (memset(A, I, sizeof(A))) #define DEB printf("DEB!\n"); #define D(X) cout << " " << #X ": " << X << endl; #define EQ(A, B) (A + ZERO > B && A - ZERO < B) typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; #define IN(n) \ int n; \ scanf("%d", &n); #define FOR(i, m, n) for (int i(m); i < n; i++) #define F(n) FOR(i, 0, n) #define FF(n) FOR(j, 0, n) #define FT(m, n) FOR(k, m, n) #define aa first #define bb second void ga(int N, int *A) { F(N) scanf("%d", A + i); } #define MX (1 << 20) #define IS(A) ((cn[A >> 6] >> (A & 63)) & 1) #define ST(A) (cn[A >> 6] |= 1ULL << ((A & 63))) ll P[MX >> 1] = {2}, L(1), cn[1 + (MX >> 6)]; void gen() { ST(0), ST(1); int Q(1 + sqrt(MX)); for (ll i(4); i < MX; i += 2) ST(i); for (int k(3); k <= Q; k += 2) if (!IS(k)) for (ll h(k << 1), j(k * k); j < MX; j += h) ST(j); for (int i(3); i < MX; i += 2) if (!IS(i)) P[L++] = i; } int fc(int N, int *f, int *c) { int L(0); for (int i(0), h(0); N >= P[i] * P[i]; ++i, h = 0) { while (!(N % P[i])) ++h, N /= P[i]; if (h) f[L] = P[i], c[L++] = h; } if (N > 1) f[L] = N, c[L++] = 1; return L; } void rec(int *f, int *c, int p, int L, vi &o, int S) { if (p == L) o.PB(S); else F(c[p] + 1) rec(f, c, p + 1, L, o, S), S *= f[p]; } void dsr(int N, vi &o) { o.clear(); static int f[64], c[64]; int L(fc(N, f, c)); rec(f, c, 0, L, o, 1); sort(o.begin(), o.end(), greater<int>()); } int N, A[MX], K, T, V[MX]; bool ok(int M) { int I = 0, J = N - 1, q = 0; F(N) V[i] = A[i] % M; sort(V, V + N); while (I < J) { int m = min(V[I], M - V[J]); q += m, V[I] -= m, V[J] += m, V[J] %= M; if (q > K) return 0; I += !V[I]; J -= !V[J]; } return 1; } vi o; int main(void) { gen(), scanf("%d%d", &N, &K), ga(N, A), T = accumulate(A, A + N, 0); dsr(T, o); for (auto &h : o) if (ok(h)) return printf("%d\n", h); assert(0); return 0; }
#include <bits/stdc++.h> using namespace std; #define PB push_back #define ZERO (1e-10) #define INF int(1e9 + 1) #define CL(A, I) (memset(A, I, sizeof(A))) #define DEB printf("DEB!\n"); #define D(X) cout << " " << #X ": " << X << endl; #define EQ(A, B) (A + ZERO > B && A - ZERO < B) typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; #define IN(n) \ int n; \ scanf("%d", &n); #define FOR(i, m, n) for (int i(m); i < n; i++) #define F(n) FOR(i, 0, n) #define FF(n) FOR(j, 0, n) #define FT(m, n) FOR(k, m, n) #define aa first #define bb second void ga(int N, int *A) { F(N) scanf("%d", A + i); } #define MX (1 << 20) #define IS(A) ((cn[A >> 6] >> (A & 63)) & 1) #define ST(A) (cn[A >> 6] |= 1ULL << ((A & 63))) ll P[MX >> 1] = {2}, L(1), cn[1 + (MX >> 6)]; void gen() { ST(0), ST(1); int Q(1 + sqrt(MX)); for (ll i(4); i < MX; i += 2) ST(i); for (int k(3); k <= Q; k += 2) if (!IS(k)) for (ll h(k << 1), j(k * k); j < MX; j += h) ST(j); for (int i(3); i < MX; i += 2) if (!IS(i)) P[L++] = i; } int fc(int N, int *f, int *c) { int L(0); for (int i(0), h(0); N >= P[i] * P[i]; ++i, h = 0) { while (!(N % P[i])) ++h, N /= P[i]; if (h) f[L] = P[i], c[L++] = h; } if (N > 1) f[L] = N, c[L++] = 1; return L; } void rec(int *f, int *c, int p, int L, vi &o, int S) { if (p == L) o.PB(S); else F(c[p] + 1) rec(f, c, p + 1, L, o, S), S *= f[p]; } void dsr(int N, vi &o) { o.clear(); static int f[64], c[64]; int L(fc(N, f, c)); rec(f, c, 0, L, o, 1); sort(o.begin(), o.end(), greater<int>()); } int N, A[MX], K, T, V[MX]; bool ok(int M) { int I = 0, J = N - 1, q = 0; F(N) V[i] = A[i] % M; sort(V, V + N); while (I < J) { int m = min(V[I], M - V[J]); q += m, V[I] -= m, V[J] += m, V[J] %= M; if (q > K) return 0; I += !V[I]; J -= !V[J]; } return 1; } vi o; int main(void) { gen(), scanf("%d%d", &N, &K), ga(N, A), T = accumulate(A, A + N, 0); dsr(T, o); for (auto &h : o) if (ok(h)) return printf("%d\n", h), 0; assert(0); return 0; }
replace
87
88
87
88
2
p02955
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n; cin >> k; int a[n]; int asum; for (int i = 0; i < n; i++) { cin >> a[i]; asum += a[i]; } int divisor[asum]; int cursor = 0; for (int i = 1; i * i <= asum; i++) { if (asum % i == 0) { divisor[cursor] = i; if (i * i != asum) divisor[cursor + 1] = asum / i; cursor += 2; } } int divisorlen = cursor; sort(divisor, divisor + divisorlen, greater<int>()); int rem[n]; int r; int sum, nsum; for (int i = 0; i < divisorlen; i++) { int d = divisor[i]; sum = 0; nsum = 0; for (int i = 0; i < n; i++) { r = a[i] % d; sum += r; rem[i] = r; } sort(rem, rem + n, greater<int>()); for (int i = 0; i < n; i++) { if (sum == nsum) { if (sum <= k) { cout << d << "\n"; return 0; } else { continue; } } sum -= rem[i]; nsum += d - rem[i]; } } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n; cin >> k; int a[n]; int asum; for (int i = 0; i < n; i++) { cin >> a[i]; asum += a[i]; } int divisor[30000]; int cursor = 0; for (int i = 1; i * i <= asum; i++) { if (asum % i == 0) { divisor[cursor] = i; if (i * i != asum) divisor[cursor + 1] = asum / i; cursor += 2; } } int divisorlen = cursor; sort(divisor, divisor + divisorlen, greater<int>()); int rem[n]; int r; int sum, nsum; for (int i = 0; i < divisorlen; i++) { int d = divisor[i]; sum = 0; nsum = 0; for (int i = 0; i < n; i++) { r = a[i] % d; sum += r; rem[i] = r; } sort(rem, rem + n, greater<int>()); for (int i = 0; i < n; i++) { if (sum == nsum) { if (sum <= k) { cout << d << "\n"; return 0; } else { continue; } } sum -= rem[i]; nsum += d - rem[i]; } } return 0; }
replace
16
17
16
17
-11
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { freopen("in.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int A[n]; vector<int> factors; int sum = 0; for (int i = 0; i < n; ++i) { cin >> A[i]; sum += A[i]; } for (int i = 1; i * i <= sum; ++i) { if (sum % i == 0) { factors.push_back(i); factors.push_back(sum / i); } } multiset<int> s; int ans = 0; for (int j = 0; j < (int)factors.size(); ++j) { int d = factors[j]; // cout<<"d : " <<d<<endl; int totalCost = 0; s.clear(); for (int i = 0; i < n; ++i) { int mod = A[i] % d; s.insert(mod); totalCost += (d - mod); } int cnt = 0; for (auto e : s) { // cout<<e<<" "; cnt += e; totalCost -= d; if (totalCost == 0 && cnt <= k) { ans = max(ans, d); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { // freopen("in.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int A[n]; vector<int> factors; int sum = 0; for (int i = 0; i < n; ++i) { cin >> A[i]; sum += A[i]; } for (int i = 1; i * i <= sum; ++i) { if (sum % i == 0) { factors.push_back(i); factors.push_back(sum / i); } } multiset<int> s; int ans = 0; for (int j = 0; j < (int)factors.size(); ++j) { int d = factors[j]; // cout<<"d : " <<d<<endl; int totalCost = 0; s.clear(); for (int i = 0; i < n; ++i) { int mod = A[i] % d; s.insert(mod); totalCost += (d - mod); } int cnt = 0; for (auto e : s) { // cout<<e<<" "; cnt += e; totalCost -= d; if (totalCost == 0 && cnt <= k) { ans = max(ans, d); } } } cout << ans << endl; return 0; }
replace
6
7
6
7
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; int a[505]; int factor[100000]; int need[100000]; int sum = 0; bool good(int x) { int cnt = 0; for (int i = 0; i < n; i++) { int t = a[i] % x; if (t) need[++cnt] = t; } sort(need + 1, need + 1 + cnt); int have = k; int l = 1, r = cnt; while (l < r) { int t = min(need[l], x - need[r]); if (t > have) return false; have -= t; need[l] -= t; if (need[l] == 0) l++; need[r] += t; if (need[r] == x) r--; } return true; } int main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE #else freopen("in.in", "r", stdin); #endif cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (int i = 1; i * i < sum; i++) { if (sum % i == 0) { factor[++factor[0]] = i; factor[++factor[0]] = sum / i; } } sort(factor + 1, factor + 1 + factor[0]); int ans; for (int i = factor[0]; i >= 1; i--) { if (good(factor[i])) { ans = factor[i]; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[505]; int factor[100000]; int need[100000]; int sum = 0; bool good(int x) { int cnt = 0; for (int i = 0; i < n; i++) { int t = a[i] % x; if (t) need[++cnt] = t; } sort(need + 1, need + 1 + cnt); int have = k; int l = 1, r = cnt; while (l < r) { int t = min(need[l], x - need[r]); if (t > have) return false; have -= t; need[l] -= t; if (need[l] == 0) l++; need[r] += t; if (need[r] == x) r--; } return true; } int main() { ios::sync_with_stdio(false); // freopen("in.in","r",stdin); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (int i = 1; i * i < sum; i++) { if (sum % i == 0) { factor[++factor[0]] = i; factor[++factor[0]] = sum / i; } } sort(factor + 1, factor + 1 + factor[0]); int ans; for (int i = factor[0]; i >= 1; i--) { if (good(factor[i])) { ans = factor[i]; break; } } cout << ans << endl; return 0; }
replace
38
42
38
39
0
p02955
C++
Runtime Error
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define mod 998244353 #define int long long #define inf 2e15 const int minnodes = 1005; #define ll long long #define EPS 0.000000001 #define N 2000000 int32_t main() { IOS; #ifndef ONLINE_JUDGE freopen("int.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n, k; cin >> n >> k; vector<int> v(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } sort(v.begin(), v.end()); int fans = 1; for (int ans = 1; ans * ans <= sum; ans++) { if (sum % ans == 0) { int det = ans; int dec = 0; vector<int> r; for (int i = 0; i < n; i++) { if (v[i] % det != 0) { dec -= v[i] % det; r.push_back(det - v[i] % det); } } if (r.size() == 0) fans = max(fans, det); int req = 0; sort(r.begin(), r.end()); for (auto diff : r) { req += diff; if (req > k) break; dec += det - diff; if (req + dec >= 0) { fans = max(fans, det); break; } } det = sum / ans; dec = 0; r.clear(); for (int i = 0; i < n; i++) { if (v[i] % det != 0) { dec -= v[i] % det; r.push_back(det - v[i] % det); } } if (r.size() == 0) fans = max(fans, det); req = 0; sort(r.begin(), r.end()); for (auto diff : r) { req += diff; if (req > k) break; dec += det - diff; if (req + dec >= 0) { fans = max(fans, det); break; } } } } cout << fans; }
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define mod 998244353 #define int long long #define inf 2e15 const int minnodes = 1005; #define ll long long #define EPS 0.000000001 #define N 2000000 int32_t main() { IOS; int n, k; cin >> n >> k; vector<int> v(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } sort(v.begin(), v.end()); int fans = 1; for (int ans = 1; ans * ans <= sum; ans++) { if (sum % ans == 0) { int det = ans; int dec = 0; vector<int> r; for (int i = 0; i < n; i++) { if (v[i] % det != 0) { dec -= v[i] % det; r.push_back(det - v[i] % det); } } if (r.size() == 0) fans = max(fans, det); int req = 0; sort(r.begin(), r.end()); for (auto diff : r) { req += diff; if (req > k) break; dec += det - diff; if (req + dec >= 0) { fans = max(fans, det); break; } } det = sum / ans; dec = 0; r.clear(); for (int i = 0; i < n; i++) { if (v[i] % det != 0) { dec -= v[i] % det; r.push_back(det - v[i] % det); } } if (r.size() == 0) fans = max(fans, det); req = 0; sort(r.begin(), r.end()); for (auto diff : r) { req += diff; if (req > k) break; dec += det - diff; if (req + dec >= 0) { fans = max(fans, det); break; } } } } cout << fans; }
replace
21
25
21
22
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int #define fi first #define so second #define ps push_back #define ld long double #define mod 1000000007 int check(vector<int> v, int n, int k) { vector<int> p = v, s = v; int sum = 0, i; for (i = 1; i < v.size(); i++) { p[i] += p[i - 1]; } sum = 0; for (i = v.size() - 1; i >= 0; i--) { s[i] = sum + n - v[i]; sum += n - v[i]; } for (i = 0; i < v.size() - 1; i++) if (p[i] == s[i + 1] && p[i] <= k) return 1; return 0; } signed main() { int n, i, k; cin >> n >> k; int a[n], sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } vector<int> div; for (i = 1; i <= sqrt(sum); i++) { if (sum % i == 0) { div.ps(i); div.ps(sum / i); } } sort(div.begin(), div.end()); // cout<<endl; vector<int> v; for (i = div.size() - 1; i >= 0; i--) { for (int j = 0; j < n; j++) { if (a[j] % div[i] != 0) v.ps(a[j] % div[i]); } sort(v.begin(), v.end()); // cout<<"checking for "<<div[i]<<endl; if (check(v, div[i], k)) break; v.clear(); } cout << div[i]; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define fi first #define so second #define ps push_back #define ld long double #define mod 1000000007 int check(vector<int> v, int n, int k) { vector<int> p = v, s = v; int sum = 0, i; for (i = 1; i < v.size(); i++) { p[i] += p[i - 1]; } sum = 0; for (i = v.size() - 1; i >= 0; i--) { s[i] = sum + n - v[i]; sum += n - v[i]; } for (i = 0; i < v.size() - 1; i++) if (p[i] == s[i + 1] && p[i] <= k) return 1; return 0; } signed main() { int n, i, k; cin >> n >> k; int a[n], sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } vector<int> div; for (i = 1; i <= sqrt(sum); i++) { if (sum % i == 0) { div.ps(i); div.ps(sum / i); } } sort(div.begin(), div.end()); // cout<<endl; vector<int> v; for (i = div.size() - 1; i >= 0; i--) { for (int j = 0; j < n; j++) { if (a[j] % div[i] != 0) v.ps(a[j] % div[i]); } if (v.size() == 0) break; sort(v.begin(), v.end()); // cout<<"checking for "<<div[i]<<endl; if (check(v, div[i], k)) break; v.clear(); } cout << div[i]; }
insert
50
50
50
52
0
p02955
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define pii pair<int, int> #define all(x) (x).begin(), (x).end() const int MOD = 1e18; int mpow(int a, int b, int p = MOD) { a = a % p; int res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b = b >> 1; } return res % p; } const int N = 1e5 + 3; int a[555]; int n, k; bool chk(int mid) { int cnt = 0; int an = 0; for (int i = 0; i < n; i++) { int o = a[i] / mid; cnt += -(a[i] - o * mid); } if (abs(cnt) % mid == 0) { int ff = abs(cnt) / mid; vector<int> ooo; for (int i = 0; i < n; i++) { ooo.pb(((a[i] / mid + 1) * mid - a[i])); } sort(all(ooo)); for (int i = 0; i < n && ff; i++) { an += ooo[i]; ff--; } if (an <= k) { return true; } else return false; } else { return false; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; int s = 0; for (int i = 0; i < n; i++) cin >> a[i], s += a[i]; int lo = 1, high = 1e18; int ans = -1; for (int i = 1; i <= s; i++) { if (s % i) continue; if (chk(i)) ans = max(ans, i); if (chk(s / i)) ans = max(ans, s / i); } cout << ans; } // I never lose. I either win or I learn
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define pii pair<int, int> #define all(x) (x).begin(), (x).end() const int MOD = 1e18; int mpow(int a, int b, int p = MOD) { a = a % p; int res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b = b >> 1; } return res % p; } const int N = 1e5 + 3; int a[555]; int n, k; bool chk(int mid) { int cnt = 0; int an = 0; for (int i = 0; i < n; i++) { int o = a[i] / mid; cnt += -(a[i] - o * mid); } if (abs(cnt) % mid == 0) { int ff = abs(cnt) / mid; vector<int> ooo; for (int i = 0; i < n; i++) { ooo.pb(((a[i] / mid + 1) * mid - a[i])); } sort(all(ooo)); for (int i = 0; i < n && ff; i++) { an += ooo[i]; ff--; } if (an <= k) { return true; } else return false; } else { return false; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; int s = 0; for (int i = 0; i < n; i++) cin >> a[i], s += a[i]; int lo = 1, high = 1e18; int ans = -1; for (int i = 1; i * i <= s; i++) { if (s % i) continue; if (chk(i)) ans = max(ans, i); if (chk(s / i)) ans = max(ans, s / i); } cout << ans; } // I never lose. I either win or I learn
replace
60
61
60
61
TLE
p02955
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; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; const long long INF = 1LL << 60; const int MOD = 1000000000 + 7; #define rev(s) (string((s).rbegin(), (s).rend())) template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // cout << fixed << setprecision(10) << ans << endl; // *min_element(c + l, c + r) *max_element(c + l, c + r) // int dx[8]={1,1,0,-1,-1,-1,0,1}; // int dy[8]={0,1,1,1,0,-1,-1,-1}; // int dx[4]={1,0,-1,0}; // int dy[4]={0,1,0,-1}; // struct Edge { // int to, id; // Edge(int to, int id): to(to), id(id) {} // }; vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); reverse(res.begin(), res.end()); return res; } ll a[550]; int main() { ll n, k; cin >> n >> k; rep(i, n) cin >> a[i]; ll sum = 0; rep(i, n) sum += a[i]; vector<ll> vec = enum_divisors(sum); P b[55]; rep(i, vec.size()) { rep(j, n) b[j] = P(a[j] % vec[i], vec[i] - (a[j] % vec[i])); ll minus = 0; sort(b, b + n); int id = 0; while (1) { if (minus + b[id].first <= k) { minus += b[id].first; id++; } else { minus = 0; break; } } bool ok = true; for (int id2 = id; id2 < n; id2++) { minus += b[id2].second; if (minus > k) { ok = false; break; } } if (ok) { cout << vec[i] << endl; return 0; } else { continue; } } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; const long long INF = 1LL << 60; const int MOD = 1000000000 + 7; #define rev(s) (string((s).rbegin(), (s).rend())) template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // cout << fixed << setprecision(10) << ans << endl; // *min_element(c + l, c + r) *max_element(c + l, c + r) // int dx[8]={1,1,0,-1,-1,-1,0,1}; // int dy[8]={0,1,1,1,0,-1,-1,-1}; // int dx[4]={1,0,-1,0}; // int dy[4]={0,1,0,-1}; // struct Edge { // int to, id; // Edge(int to, int id): to(to), id(id) {} // }; vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); reverse(res.begin(), res.end()); return res; } ll a[550]; int main() { ll n, k; cin >> n >> k; rep(i, n) cin >> a[i]; ll sum = 0; rep(i, n) sum += a[i]; vector<ll> vec = enum_divisors(sum); P b[550]; rep(i, vec.size()) { rep(j, n) b[j] = P(a[j] % vec[i], vec[i] - (a[j] % vec[i])); ll minus = 0; sort(b, b + n); int id = 0; while (1) { if (minus + b[id].first <= k) { minus += b[id].first; id++; } else { minus = 0; break; } } bool ok = true; for (int id2 = id; id2 < n; id2++) { minus += b[id2].second; if (minus > k) { ok = false; break; } } if (ok) { cout << vec[i] << endl; return 0; } else { continue; } } }
replace
48
49
48
49
0
p02955
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll sum = 0LL; ll N, K; cin >> N >> K; vector<ll> A(N); for (ll i = 0LL; i < N; i++) { cin >> A[i]; sum += A[i]; } set<ll> s; for (ll i = 1LL; i * i <= sum; i++) { if (sum % i == 0LL) { s.insert(i); s.insert(sum % i); } } ll ans = 1LL; for (auto ne : s) { vector<ll> rem(N); for (ll i = 0LL; i < N; i++) { rem[i] = A[i] % ne; } sort(rem.begin(), rem.end()); ll lsum = 0LL; ll rsum = 0LL; for (ll i = 0; i < N; i++) { rsum += ne - rem[i]; } ll cnt = 1LL << 60; for (ll i = 0LL; i < N; i++) { lsum += rem[i]; rsum -= ne - rem[i]; if (lsum != rsum) { continue; } cnt = min(cnt, lsum); } if (cnt <= K) { ans = max(ans, ne); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll sum = 0LL; ll N, K; cin >> N >> K; vector<ll> A(N); for (ll i = 0LL; i < N; i++) { cin >> A[i]; sum += A[i]; } set<ll> s; for (ll i = 1LL; i * i <= sum; i++) { if (sum % i == 0LL) { s.insert(i); s.insert(sum / i); } } ll ans = 1LL; for (auto ne : s) { vector<ll> rem(N); for (ll i = 0LL; i < N; i++) { rem[i] = A[i] % ne; } sort(rem.begin(), rem.end()); ll lsum = 0LL; ll rsum = 0LL; for (ll i = 0; i < N; i++) { rsum += ne - rem[i]; } ll cnt = 1LL << 60; for (ll i = 0LL; i < N; i++) { lsum += rem[i]; rsum -= ne - rem[i]; if (lsum != rsum) { continue; } cnt = min(cnt, lsum); } if (cnt <= K) { ans = max(ans, ne); } } cout << ans << endl; return 0; }
replace
16
17
16
17
-8
p02955
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define itn int #define rep(i, x, y) for (int i = x; i < y; i++) #define range(a) a.begin(), a.end() #define print(A, n) \ rep(i, 0, n) { cout << (i ? " " : "") << A[i]; } \ cout << endl; #define pprint(A, m, n) \ rep(j, 0, m) { print(A[j], n); } const long mod = 1e9 + 7; const int size = 1e5; const int INF = 1e9; int main() { int N, K; cin >> N >> K; int A[N]; int sum = 0; rep(i, 0, N) { cin >> A[i]; sum += A[i]; } deque<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.push_back(i); d.push_back(sum / i); } } sort(d.begin(), d.end()); int check, k; int u; int B[N]; for (int i = d.size() - 1; i >= 0; i--) { u = d[i]; check = 0; rep(j, 0, N) { k = A[j] % u; B[j] = -k; check += k; } if (check % u == 0) { rep(k, 0, N) { sort(B, B + N); int temp = accumulate(B, B + (check / u), 0); if (check + temp <= K) { cout << u << endl; return 0; } } } } }
#include <bits/stdc++.h> using namespace std; #define itn int #define rep(i, x, y) for (int i = x; i < y; i++) #define range(a) a.begin(), a.end() #define print(A, n) \ rep(i, 0, n) { cout << (i ? " " : "") << A[i]; } \ cout << endl; #define pprint(A, m, n) \ rep(j, 0, m) { print(A[j], n); } const long mod = 1e9 + 7; const int size = 1e5; const int INF = 1e9; int main() { int N, K; cin >> N >> K; int A[N]; int sum = 0; rep(i, 0, N) { cin >> A[i]; sum += A[i]; } deque<int> d; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { d.push_back(i); d.push_back(sum / i); } } sort(d.begin(), d.end()); int check, k; int u; int B[N]; for (int i = d.size() - 1; i >= 0; i--) { u = d[i]; check = 0; rep(j, 0, N) { k = A[j] % u; B[j] = -k; check += k; } if (check % u == 0) { sort(B, B + N); int temp = accumulate(B, B + (check / u), 0); if (check + temp <= K) { cout << u << endl; return 0; } } } }
replace
42
49
42
47
TLE
p02955
Python
Time Limit Exceeded
N, K = map(int, input().split()) A = list(map(int, input().split())) divs = [] maxA = sum(A) for i in range(1, maxA + 1): if maxA % i == 0: divs.append(i) divs.append(maxA // i) divs.sort(reverse=True) for d in divs: rest = [a % d for a in A] rest.sort(reverse=True) restSum = sum(rest) // d cnt = 0 for i in range(restSum): cnt += d - rest[i] if cnt <= K: print(d) exit()
N, K = map(int, input().split()) A = list(map(int, input().split())) divs = [] maxA = sum(A) for i in range(1, int(maxA**0.5) + 1): if maxA % i == 0: divs.append(i) divs.append(maxA // i) divs.sort(reverse=True) for d in divs: rest = [a % d for a in A] rest.sort(reverse=True) restSum = sum(rest) // d cnt = 0 for i in range(restSum): cnt += d - rest[i] if cnt <= K: print(d) exit()
replace
5
6
5
6
TLE
p02955
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long k; cin >> k; vector<long long> a(n); long long sum_a = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum_a += a[i]; } for (int i = sum_a; i >= 0; i--) { if (sum_a % i != 0) continue; vector<long long> r(n); for (int j = 0; j < n; j++) { r[j] = a[j] % i; } sort(r.begin(), r.end()); long long total = accumulate(r.begin(), r.end(), 0LL); int l = n - total / i; long long count = accumulate(r.begin(), r.begin() + l, 0LL); if (count <= k) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long k; cin >> k; vector<long long> a(n); long long sum_a = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum_a += a[i]; } set<long long> factors; for (int i = 1; i * i <= sum_a; i++) { if (sum_a % i == 0) { factors.insert(i); factors.insert(sum_a / i); } } for (auto it = factors.rbegin(); it != factors.rend(); it++) { long long i = *it; if (sum_a % i != 0) continue; vector<long long> r(n); for (int j = 0; j < n; j++) { r[j] = a[j] % i; } sort(r.begin(), r.end()); long long total = accumulate(r.begin(), r.end(), 0LL); int l = n - total / i; long long count = accumulate(r.begin(), r.begin() + l, 0LL); if (count <= k) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
replace
14
15
14
23
TLE
p02956
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100, mod = 998244353; void plusle(int &a, int b) { a += b; if (a >= mod) a -= mod; return; } void minun(int &a, int b) { a -= b; if (a < 0) a += mod; return; } int add(int a, int b) { a += b; return a >= mod ? a - mod : a; } int sub(int a, int b) { a -= b; return a < 0 ? a + mod : a; } int mul(int a, int b) { return (int)((long long)a * b % mod); } struct BIT { int bit[maxn]; int n; BIT(int _n) { n = _n + 1; } void update(int idx, int val) { for (; idx < n; idx += (idx & (-idx))) bit[idx] += val; return; } int get(int idx) { int sum = 0; for (; idx > 0; idx -= (idx & (-idx))) sum += bit[idx]; return sum; } int get(int l, int r) { return get(r) - get(l - 1); } }; struct pt { int x, y; pt() : x(0), y(0) {} void read() { scanf("%d%d", &x, &y); } friend bool operator<(const pt &a, const pt &b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } } p[maxn]; vector<int> ss, sss; int ans, n; int p2[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { p[i].read(); ss.push_back(p[i].x); sss.push_back(p[i].y); } ss.push_back((int)(-1e9 - 7)); sss.push_back((int)(-1e9 - 7)); sort(ss.begin(), ss.end()); sort(sss.begin(), sss.end()); ss.erase(unique(ss.begin(), ss.end()), ss.end()); sss.erase(unique(sss.begin(), sss.end()), sss.end()); for (int i = 1; i <= n; i++) { p[i].x = (int)(lower_bound(ss.begin(), ss.end(), p[i].x) - ss.begin()); p[i].y = (int)(lower_bound(sss.begin(), sss.end(), p[i].y) - sss.begin()); } p2[0] = 1; for (int i = 1; i <= n; i++) { p2[i] = add(p2[i - 1], p2[i - 1]); } sort(p + 1, p + 1 + n); int cur = 0, u1, u2, d1, d2; BIT f1(n), f2(n); for (int i = 1; i <= n; i++) f1.update(p[i].y, 1); for (int i = 1; i <= n; i++) { int j = i, ct = 0; while (p[j].x == p[i].x && j <= n) { f1.update(p[j].y, -1); ct++; j++; } j--; for (int k = i; k <= j; k++) { u1 = f1.get(p[k].y + 1, n), u2 = f2.get(p[k].y + 1, n); d1 = f1.get(p[k].y - 1), d2 = f2.get(p[k].y - 1); plusle(ans, p2[n] - 1); /// completely above cur = u1 + u2 + (j - k); minun(ans, p2[cur] - 1); /// completely below cur = d1 + d2 + (k - i); minun(ans, p2[cur] - 1); /// completely left minun(ans, p2[i - 1] - 1); /// completely right minun(ans, p2[n - j] - 1); /// shitty four corners /// left-up plusle(ans, p2[u2] - 1); /// left down plusle(ans, p2[d2] - 1); /// right up plusle(ans, p2[u1] - 1); /// right down plusle(ans, p2[d1] - 1); } for (int k = i; k <= j; k++) { f2.update(p[k].y, 1); } i = j; } printf("%d\n", ans); } /* Good Luck -Lucina */
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100, mod = 998244353; void plusle(int &a, int b) { a += b; if (a >= mod) a -= mod; return; } void minun(int &a, int b) { a -= b; if (a < 0) a += mod; return; } int add(int a, int b) { a += b; return a >= mod ? a - mod : a; } int sub(int a, int b) { a -= b; return a < 0 ? a + mod : a; } int mul(int a, int b) { return (int)((long long)a * b % mod); } struct BIT { int bit[maxn]; int n; BIT(int _n) { n = _n + 1; for (int i = 0; i <= n; i++) bit[i] = 0; } void update(int idx, int val) { for (; idx < n; idx += (idx & (-idx))) bit[idx] += val; return; } int get(int idx) { int sum = 0; for (; idx > 0; idx -= (idx & (-idx))) sum += bit[idx]; return sum; } int get(int l, int r) { return get(r) - get(l - 1); } }; struct pt { int x, y; pt() : x(0), y(0) {} void read() { scanf("%d%d", &x, &y); } friend bool operator<(const pt &a, const pt &b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } } p[maxn]; vector<int> ss, sss; int ans, n; int p2[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { p[i].read(); ss.push_back(p[i].x); sss.push_back(p[i].y); } ss.push_back((int)(-1e9 - 7)); sss.push_back((int)(-1e9 - 7)); sort(ss.begin(), ss.end()); sort(sss.begin(), sss.end()); ss.erase(unique(ss.begin(), ss.end()), ss.end()); sss.erase(unique(sss.begin(), sss.end()), sss.end()); for (int i = 1; i <= n; i++) { p[i].x = (int)(lower_bound(ss.begin(), ss.end(), p[i].x) - ss.begin()); p[i].y = (int)(lower_bound(sss.begin(), sss.end(), p[i].y) - sss.begin()); } p2[0] = 1; for (int i = 1; i <= n; i++) { p2[i] = add(p2[i - 1], p2[i - 1]); } sort(p + 1, p + 1 + n); int cur = 0, u1, u2, d1, d2; BIT f1(n), f2(n); for (int i = 1; i <= n; i++) f1.update(p[i].y, 1); for (int i = 1; i <= n; i++) { int j = i, ct = 0; while (p[j].x == p[i].x && j <= n) { f1.update(p[j].y, -1); ct++; j++; } j--; for (int k = i; k <= j; k++) { u1 = f1.get(p[k].y + 1, n), u2 = f2.get(p[k].y + 1, n); d1 = f1.get(p[k].y - 1), d2 = f2.get(p[k].y - 1); plusle(ans, p2[n] - 1); /// completely above cur = u1 + u2 + (j - k); minun(ans, p2[cur] - 1); /// completely below cur = d1 + d2 + (k - i); minun(ans, p2[cur] - 1); /// completely left minun(ans, p2[i - 1] - 1); /// completely right minun(ans, p2[n - j] - 1); /// shitty four corners /// left-up plusle(ans, p2[u2] - 1); /// left down plusle(ans, p2[d2] - 1); /// right up plusle(ans, p2[u1] - 1); /// right down plusle(ans, p2[d1] - 1); } for (int k = i; k <= j; k++) { f2.update(p[k].y, 1); } i = j; } printf("%d\n", ans); } /* Good Luck -Lucina */
replace
27
28
27
32
0
p02956
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int N = 1e5 + 7; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return (a - b + MOD) % MOD; } int mul(int a, int b) { return (a * b) % MOD; } int pw[N]; void init() { pw[0] = 1; for (int i = 1; i < N; i++) { pw[i] = mul(pw[i - 1], 2); } } int cnt_bad(vector<int> p) { int ans = 0; for (auto t : p) { ans = add(ans, pw[t] - 1); } for (int i = 0; i < 4; i++) { int c = pw[p[i] + p[(i + 1) % 4]]; c = sub(c, pw[p[i]]); c = sub(c, pw[p[(i + 1) % 4]]); c = add(c, 1); ans = add(ans, c); } return ans; } struct Fenw { int n; vector<int> f; void add(int x, int c) { for (int i = x; i < n; i = i | (i + 1)) { f[i] += c; } } int sum(int x) { int ans = 0; for (int i = x; i >= 0; i = (i & (i + 1)) - 1) { ans += f[i]; } return ans; } Fenw(int n_) { n = n_; f.resize(n); } }; void zip(vector<int> &a) { vector<int> sn = a; sort(sn.begin(), sn.end()); sn.resize(unique(sn.begin(), sn.end()) - sn.begin()); for (auto &t : a) { t = lower_bound(sn.begin(), sn.end(), t) - sn.begin(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); init(); int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } zip(x); zip(y); vector<int> ind(n); iota(ind.begin(), ind.end(), 0); sort(ind.begin(), ind.end(), [&](int i, int j) { return x[i] < x[j]; }); Fenw lp(n); Fenw rp(n); for (auto t : ind) { rp.add(y[t], 1); } int ans = 0; for (int i = 0; i < n; i++) { if (i > 0) lp.add(y[ind[i - 1]], 1); rp.add(y[ind[i]], -1); vector<int> p(4); p[1] = lp.sum(y[ind[i]]); p[0] = i - p[1]; p[2] = rp.sum(y[ind[i]]); p[3] = (n - i - 1) - p[2]; { int all = sub(pw[n], 1); int none = cnt_bad(p); all = sub(all, none); ans = add(ans, all); } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int N = 2e5 + 7; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return (a - b + MOD) % MOD; } int mul(int a, int b) { return (a * b) % MOD; } int pw[N]; void init() { pw[0] = 1; for (int i = 1; i < N; i++) { pw[i] = mul(pw[i - 1], 2); } } int cnt_bad(vector<int> p) { int ans = 0; for (auto t : p) { ans = add(ans, pw[t] - 1); } for (int i = 0; i < 4; i++) { int c = pw[p[i] + p[(i + 1) % 4]]; c = sub(c, pw[p[i]]); c = sub(c, pw[p[(i + 1) % 4]]); c = add(c, 1); ans = add(ans, c); } return ans; } struct Fenw { int n; vector<int> f; void add(int x, int c) { for (int i = x; i < n; i = i | (i + 1)) { f[i] += c; } } int sum(int x) { int ans = 0; for (int i = x; i >= 0; i = (i & (i + 1)) - 1) { ans += f[i]; } return ans; } Fenw(int n_) { n = n_; f.resize(n); } }; void zip(vector<int> &a) { vector<int> sn = a; sort(sn.begin(), sn.end()); sn.resize(unique(sn.begin(), sn.end()) - sn.begin()); for (auto &t : a) { t = lower_bound(sn.begin(), sn.end(), t) - sn.begin(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); init(); int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } zip(x); zip(y); vector<int> ind(n); iota(ind.begin(), ind.end(), 0); sort(ind.begin(), ind.end(), [&](int i, int j) { return x[i] < x[j]; }); Fenw lp(n); Fenw rp(n); for (auto t : ind) { rp.add(y[t], 1); } int ans = 0; for (int i = 0; i < n; i++) { if (i > 0) lp.add(y[ind[i - 1]], 1); rp.add(y[ind[i]], -1); vector<int> p(4); p[1] = lp.sum(y[ind[i]]); p[0] = i - p[1]; p[2] = rp.sum(y[ind[i]]); p[3] = (n - i - 1) - p[2]; { int all = sub(pw[n], 1); int none = cnt_bad(p); all = sub(all, none); ans = add(ans, all); } } cout << ans << endl; }
replace
24
25
24
25
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> #define MOD 998244353 using namespace std; typedef long long ll; typedef pair<int, int> ii; ll fpow(ll x, ll p) { if (p == 0) return 1; return ((p & 1) ? x : 1) * fpow(x * x % MOD, p >> 1) % MOD; } ll subs(ll x, ll d) { return ((x - d) % MOD + MOD) % MOD; } ll comb(ll n) { if (n & 1) return (n - 1) / 2 * n % MOD; return n / 2 * (n - 1) % MOD; } class Fnwick { int *ar; int size; public: Fnwick(int n) { size = n + 1; ar = new int[size]; memset(ar, 0, sizeof(int) * size); } ~Fnwick() { delete ar; } int add(int x, int v) { for (int ctr1 = x + 1; ctr1 <= size; ctr1 += (ctr1 & -ctr1)) ar[ctr1] += v; } int get(int x) { int rez = 0; for (int ctr1 = x + 1; ctr1 > 0; ctr1 -= (ctr1 & -ctr1)) rez += ar[ctr1]; return rez; } }; ll count(vector<ii> &p, unordered_map<int, int> &rc, int n) { ll rez = 0; Fnwick bit(n); for (int ctr1 = 0; ctr1 < n; ++ctr1) { rez = subs(rez, fpow(2, ctr1)); rez = subs(rez, fpow(2, n - 1 - ctr1)); int y = rc.find(p[ctr1].second)->second; int lower = bit.get(y); int higher = ctr1 - lower; rez = (rez + fpow(2, lower)) % MOD; rez = (rez + fpow(2, higher)) % MOD; bit.add(y, 1); } return rez; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; int x, y; vector<ii> points; vector<int> compressed; unordered_map<int, int> rev; for (int ctr1 = 0; ctr1 < n; ++ctr1) cin >> x >> y, points.push_back(make_pair(x, y)), compressed.push_back(y); sort(points.begin(), points.end()); sort(compressed.begin(), compressed.end()); for (int ctr1 = 0; ctr1 < n; ++ctr1) rev.emplace(compressed[ctr1], ctr1); ll rez = subs(fpow(2, n), 1) * n % MOD; rez = (rez + count(points, rev, n)) % MOD; reverse(points.begin(), points.end()); rez = (rez + count(points, rev, n)) % MOD; cout << rez << "\n"; return 0; }
#include <bits/stdc++.h> #define MOD 998244353 using namespace std; typedef long long ll; typedef pair<int, int> ii; ll fpow(ll x, ll p) { if (p == 0) return 1; return ((p & 1) ? x : 1) * fpow(x * x % MOD, p >> 1) % MOD; } ll subs(ll x, ll d) { return ((x - d) % MOD + MOD) % MOD; } ll comb(ll n) { if (n & 1) return (n - 1) / 2 * n % MOD; return n / 2 * (n - 1) % MOD; } class Fnwick { int *ar; int size; public: Fnwick(int n) { size = n + 1; ar = new int[size]; memset(ar, 0, sizeof(int) * size); } ~Fnwick() { delete ar; } int add(int x, int v) { for (int ctr1 = x + 1; ctr1 <= size; ctr1 += (ctr1 & -ctr1)) ar[ctr1] += v; } int get(int x) { int rez = 0; for (int ctr1 = x + 1; ctr1 > 0; ctr1 -= (ctr1 & -ctr1)) rez += ar[ctr1]; return rez; } }; ll count(vector<ii> &p, unordered_map<int, int> &rc, int n) { ll rez = 0; Fnwick bit(2 * n); for (int ctr1 = 0; ctr1 < n; ++ctr1) { rez = subs(rez, fpow(2, ctr1)); rez = subs(rez, fpow(2, n - 1 - ctr1)); int y = rc.find(p[ctr1].second)->second; int lower = bit.get(y); int higher = ctr1 - lower; rez = (rez + fpow(2, lower)) % MOD; rez = (rez + fpow(2, higher)) % MOD; bit.add(y, 1); } return rez; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; int x, y; vector<ii> points; vector<int> compressed; unordered_map<int, int> rev; for (int ctr1 = 0; ctr1 < n; ++ctr1) cin >> x >> y, points.push_back(make_pair(x, y)), compressed.push_back(y); sort(points.begin(), points.end()); sort(compressed.begin(), compressed.end()); for (int ctr1 = 0; ctr1 < n; ++ctr1) rev.emplace(compressed[ctr1], ctr1); ll rez = subs(fpow(2, n), 1) * n % MOD; rez = (rez + count(points, rev, n)) % MOD; reverse(points.begin(), points.end()); rez = (rez + count(points, rev, n)) % MOD; cout << rez << "\n"; return 0; }
replace
47
48
47
48
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> #define FI first #define SE second #define EPS 1e-9 #define ALL(a) a.begin(), a.end() #define SZ(a) int((a).size()) #define MS(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORE(i, a, b) for (int i = (a); i >= (b); i--) #define FORALL(it, a) \ for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define WHATIS(x) cout << #x << " is " << x << endl; #define ERROR(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } //__builtin_ffs(x) return 1 + index of least significant 1-bit of x //__builtin_clz(x) return number of leading zeros of x //__builtin_ctz(x) return number of trailing zeros of x using namespace std; using ll = long long; using ld = double; typedef pair<int, int> II; typedef pair<II, int> III; typedef complex<ld> cd; typedef vector<cd> vcd; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const ll MODBASE = 998244353LL; const int MAXN = 100010; const int MAXM = 200010; const int MAXK = 110; const int MAXQ = 200010; int n; II a[MAXN]; set<int> s; vector<int> b; int t[MAXN * 4]; ll mu[MAXN], res[MAXN]; int bs(int u) { int dau = 0, cuoi = SZ(b) - 1; while (dau <= cuoi) { int mid = (dau + cuoi) >> 1; if (b[mid] > u) cuoi = mid - 1; else dau = mid + 1; } return cuoi; } void update(int k, int l, int r, int u) { if (l > r || r < u || u < l) return; if (l == r) { t[k] = 1; return; } int m = (l + r) >> 1; if (u <= m) update(k * 2, l, m, u); else update(k * 2 + 1, m + 1, r, u); t[k] = t[k * 2] + t[k * 2 + 1]; } int get(int k, int l, int r, int u, int v) { if (r < u || v < l || l > r) return 0; if (u <= l && r <= v) return t[k]; int m = (l + r) >> 1; return get(k * 2, l, m, u, v) + get(k * 2 + 1, m + 1, r, u, v); } int main() { ios::sync_with_stdio(0); cin.tie(nullptr); cin >> n; FOR(i, 1, n) cin >> a[i].FI >> a[i].SE; sort(a + 1, a + n + 1); // FOR(i,1,n) cout << a[i].FI << ' ' << a[i].SE << endl; FOR(i, 1, n) b.emplace_back(a[i].SE); sort(ALL(b)); FOR(i, 1, n) a[i].SE = bs(a[i].SE); // FOR(i,1,n) cout << a[i].FI << ' ' << a[i].SE << endl; MS(t, 0); mu[0] = 1; FOR(i, 1, n) mu[i] = mu[i - 1] * 2 % MODBASE; FOR(i, 1, n) res[i] = (mu[n] - 1 + MODBASE) % MODBASE; FOR(i, 1, n) { int lef = i - 1; int upperLeft = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lowerLeft = lef - upperLeft; // cout << i << ' ' << upperLeft << ' ' << lowerLeft << endl; res[i] = (res[i] + mu[upperLeft] + mu[lowerLeft]) % MODBASE; update(1, 0, n - 1, a[i].SE); } MS(t, 0); FORE(i, n, 1) { int rig = n - i; int upperRight = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lowerRight = rig - upperRight; // cout << i << ' ' << upperRight << ' ' << lowerRight << endl; res[i] = (res[i] + mu[upperRight] + mu[lowerRight]) % MODBASE; update(1, 0, n - 1, a[i].SE); } FOR(i, 1, n) { int upper = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lower = n - upper - 1; int rig = n - i; int lef = i - 1; // cout << upper << ' ' << lower << ' ' << lef << ' ' << rig << endl; ll p = (mu[upper] + mu[lower] + mu[rig] + mu[lef]) % MODBASE; res[i] = (res[i] - p + MODBASE) % MODBASE; } ll kq = 0; // FOR(i,1,n) cout << res[i] << ' '; // cout << endl; FOR(i, 1, n) kq = (kq + res[i]) % MODBASE; cout << kq; return 0; }
#include <bits/stdc++.h> #define FI first #define SE second #define EPS 1e-9 #define ALL(a) a.begin(), a.end() #define SZ(a) int((a).size()) #define MS(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORE(i, a, b) for (int i = (a); i >= (b); i--) #define FORALL(it, a) \ for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define WHATIS(x) cout << #x << " is " << x << endl; #define ERROR(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } //__builtin_ffs(x) return 1 + index of least significant 1-bit of x //__builtin_clz(x) return number of leading zeros of x //__builtin_ctz(x) return number of trailing zeros of x using namespace std; using ll = long long; using ld = double; typedef pair<int, int> II; typedef pair<II, int> III; typedef complex<ld> cd; typedef vector<cd> vcd; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const ll MODBASE = 998244353LL; const int MAXN = 200010; const int MAXM = 200010; const int MAXK = 110; const int MAXQ = 200010; int n; II a[MAXN]; set<int> s; vector<int> b; int t[MAXN * 4]; ll mu[MAXN], res[MAXN]; int bs(int u) { int dau = 0, cuoi = SZ(b) - 1; while (dau <= cuoi) { int mid = (dau + cuoi) >> 1; if (b[mid] > u) cuoi = mid - 1; else dau = mid + 1; } return cuoi; } void update(int k, int l, int r, int u) { if (l > r || r < u || u < l) return; if (l == r) { t[k] = 1; return; } int m = (l + r) >> 1; if (u <= m) update(k * 2, l, m, u); else update(k * 2 + 1, m + 1, r, u); t[k] = t[k * 2] + t[k * 2 + 1]; } int get(int k, int l, int r, int u, int v) { if (r < u || v < l || l > r) return 0; if (u <= l && r <= v) return t[k]; int m = (l + r) >> 1; return get(k * 2, l, m, u, v) + get(k * 2 + 1, m + 1, r, u, v); } int main() { ios::sync_with_stdio(0); cin.tie(nullptr); cin >> n; FOR(i, 1, n) cin >> a[i].FI >> a[i].SE; sort(a + 1, a + n + 1); // FOR(i,1,n) cout << a[i].FI << ' ' << a[i].SE << endl; FOR(i, 1, n) b.emplace_back(a[i].SE); sort(ALL(b)); FOR(i, 1, n) a[i].SE = bs(a[i].SE); // FOR(i,1,n) cout << a[i].FI << ' ' << a[i].SE << endl; MS(t, 0); mu[0] = 1; FOR(i, 1, n) mu[i] = mu[i - 1] * 2 % MODBASE; FOR(i, 1, n) res[i] = (mu[n] - 1 + MODBASE) % MODBASE; FOR(i, 1, n) { int lef = i - 1; int upperLeft = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lowerLeft = lef - upperLeft; // cout << i << ' ' << upperLeft << ' ' << lowerLeft << endl; res[i] = (res[i] + mu[upperLeft] + mu[lowerLeft]) % MODBASE; update(1, 0, n - 1, a[i].SE); } MS(t, 0); FORE(i, n, 1) { int rig = n - i; int upperRight = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lowerRight = rig - upperRight; // cout << i << ' ' << upperRight << ' ' << lowerRight << endl; res[i] = (res[i] + mu[upperRight] + mu[lowerRight]) % MODBASE; update(1, 0, n - 1, a[i].SE); } FOR(i, 1, n) { int upper = get(1, 0, n - 1, a[i].SE + 1, n - 1); int lower = n - upper - 1; int rig = n - i; int lef = i - 1; // cout << upper << ' ' << lower << ' ' << lef << ' ' << rig << endl; ll p = (mu[upper] + mu[lower] + mu[rig] + mu[lef]) % MODBASE; res[i] = (res[i] - p + MODBASE) % MODBASE; } ll kq = 0; // FOR(i,1,n) cout << res[i] << ' '; // cout << endl; FOR(i, 1, n) kq = (kq + res[i]) % MODBASE; cout << kq; return 0; }
replace
40
41
40
41
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> #define f first #define s second #define MOD 1000000007 #define PMOD 998244353 #define pb(x) push_back(x) using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> plii; typedef pair<int, pii> piii; const int INF = 1e9 + 10; const ll LINF = 1LL * INF * INF; const int MAXN = 4e5 + 10; const int MAXM = 5e3 + 10; priority_queue<int> pq; vector<vector<int>> graph; queue<int> que; pii A[MAXN]; ll bi[MAXN]; char S[MAXN]; int tree[MAXN][3]; int B[MAXN]; int C[MAXN]; vector<int> xpos; vector<int> ypos; void update(int tmp, int j) { tree[tmp][j]++; tmp >>= 1; while (tmp) { tree[tmp][j] = tree[tmp * 2][j] + tree[tmp * 2 + 1][j]; tmp >>= 1; } return; } int getans(int L, int R, int j) { ll res = 0; while (L <= R) { if (L & 1) { res += tree[L][j]; L++; } if (!(R & 1)) { res += tree[R][j]; R--; } L >>= 1; R >>= 1; } return res; } int main() { int n, m, k, x, y; int cnt = 0; int mx = 0; int mn = INF; int idx = -1, idy = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i].f >> A[i].s; xpos.push_back(A[i].f); ypos.push_back(A[i].s); } sort(xpos.begin(), xpos.end()); sort(ypos.begin(), ypos.end()); sort(A, A + n); bi[0] = 1; for (int i = 1; i <= n; i++) { bi[i] = bi[i - 1] * 2; bi[i] %= PMOD; } int base = 1; for (base; base < n; base *= 2) ; for (int i = 0; i < n; i++) { idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); C[i] = getans(base, base + idy, 0); update(base + idy, 0); } for (int i = n - 1; i >= 0; i--) { idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); B[i] = getans(base + idy, base * 2 - 1, 1); update(base + idy, 1); } ll res = 0; ll a, b, c, d; ll cur = 0; for (int i = 0; i < n; i++) { idx = lower_bound(xpos.begin(), xpos.end(), A[i].f) - xpos.begin(); idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); a = idx - C[i]; b = B[i]; c = C[i]; d = (n - 1 - idx) - B[i]; // cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; cur = bi[a + b] + bi[a + c] + bi[b + d] + bi[c + d]; cur %= PMOD; cur -= (bi[a] + bi[b] + bi[c] + bi[d]) % PMOD; cur = (bi[n] - 1) - cur; // cout<<cur<<"\n"; res = (res + cur + PMOD) % PMOD; } cout << res << "\n"; return 0; }
#include <bits/stdc++.h> #define f first #define s second #define MOD 1000000007 #define PMOD 998244353 #define pb(x) push_back(x) using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> plii; typedef pair<int, pii> piii; const int INF = 1e9 + 10; const ll LINF = 1LL * INF * INF; const int MAXN = 8e5 + 10; const int MAXM = 5e3 + 10; priority_queue<int> pq; vector<vector<int>> graph; queue<int> que; pii A[MAXN]; ll bi[MAXN]; char S[MAXN]; int tree[MAXN][3]; int B[MAXN]; int C[MAXN]; vector<int> xpos; vector<int> ypos; void update(int tmp, int j) { tree[tmp][j]++; tmp >>= 1; while (tmp) { tree[tmp][j] = tree[tmp * 2][j] + tree[tmp * 2 + 1][j]; tmp >>= 1; } return; } int getans(int L, int R, int j) { ll res = 0; while (L <= R) { if (L & 1) { res += tree[L][j]; L++; } if (!(R & 1)) { res += tree[R][j]; R--; } L >>= 1; R >>= 1; } return res; } int main() { int n, m, k, x, y; int cnt = 0; int mx = 0; int mn = INF; int idx = -1, idy = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i].f >> A[i].s; xpos.push_back(A[i].f); ypos.push_back(A[i].s); } sort(xpos.begin(), xpos.end()); sort(ypos.begin(), ypos.end()); sort(A, A + n); bi[0] = 1; for (int i = 1; i <= n; i++) { bi[i] = bi[i - 1] * 2; bi[i] %= PMOD; } int base = 1; for (base; base < n; base *= 2) ; for (int i = 0; i < n; i++) { idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); C[i] = getans(base, base + idy, 0); update(base + idy, 0); } for (int i = n - 1; i >= 0; i--) { idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); B[i] = getans(base + idy, base * 2 - 1, 1); update(base + idy, 1); } ll res = 0; ll a, b, c, d; ll cur = 0; for (int i = 0; i < n; i++) { idx = lower_bound(xpos.begin(), xpos.end(), A[i].f) - xpos.begin(); idy = lower_bound(ypos.begin(), ypos.end(), A[i].s) - ypos.begin(); a = idx - C[i]; b = B[i]; c = C[i]; d = (n - 1 - idx) - B[i]; // cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; cur = bi[a + b] + bi[a + c] + bi[b + d] + bi[c + d]; cur %= PMOD; cur -= (bi[a] + bi[b] + bi[c] + bi[d]) % PMOD; cur = (bi[n] - 1) - cur; // cout<<cur<<"\n"; res = (res + cur + PMOD) % PMOD; } cout << res << "\n"; return 0; }
replace
14
15
14
15
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, x, n) for (int i = x; i <= n; i++) #define rep3(i, x, n) for (int i = x; i >= n; i--) #define elif else if typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll INF = 1e18; ll f(ll a, ll b) { return a + b; } int other = 0; struct segment_tree { ll n; ll seg[444444]; // 要素数Nのセグメントツリーを構築 segment_tree(int N) { n = 1; while (n < N) n *= 2; fill_n(seg, 2 * n - 1, other); } // i番目の要素をxに変更(0番目から数える) void update(int i, ll x) { i += n - 1; seg[i] = x; while (i > 0) { i = (i - 1) / 2; seg[i] = f(seg[2 * i + 1], seg[2 * i + 2]); } } // 要素数N以上の最小の2べきnを取得 ll size() { return n; } // query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得 ll query(int a, int b, int i, int l, int r) { if (a >= r || b <= l) return other; elif (a <= l && r <= b) return seg[i]; else { int vl = query(a, b, 2 * i + 1, l, (l + r) / 2); int vr = query(a, b, 2 * i + 2, (l + r) / 2, r); return f(vl, vr); } } }; int main() { int N; cin >> N; ll e[N]; e[0] = 1; rep2(i, 1, N - 1) e[i] = (2 * e[i - 1]) % MOD2; int x[N], y[N]; vector<P> vecx, vecy, vec; rep(i, N) { cin >> x[i] >> y[i]; vecx.push_back(P(x[i], i)); vecy.push_back(P(y[i], i)); } sort(vecx.begin(), vecx.end()); sort(vecy.begin(), vecy.end()); rep(i, N) { int px = vecx[i].second, py = vecy[i].second; x[px] = i, y[py] = i; } rep(i, N) vec.push_back(P(x[i], y[i])); sort(vec.begin(), vec.end()); int X[N], Y[N]; rep(i, N) X[i] = vec[i].first, Y[i] = vec[i].second; segment_tree segl(N), segr(N); ll n = segl.size(); ll ul[N], ur[N], dl[N], dr[N]; rep(i, N) { dl[i] = segl.query(0, Y[i], 0, 0, n); ul[i] = i - dl[i]; segl.update(Y[i], 1); } rep3(i, N - 1, 0) { dr[i] = segr.query(0, Y[i], 0, 0, n); ur[i] = N - 1 - i - dr[i]; segr.update(Y[i], 1); } ll ans = (N * e[N - 1]) % MOD2; rep(i, N) { ll a = (e[ul[i]] - 1) * (e[dr[i]] - 1) % MOD2; ll b = (e[ur[i]] - 1) * (e[dl[i]] - 1) % MOD2; ans += a * e[ur[i] + dl[i]]; ans %= MOD2; ans += b * e[ul[i] + dr[i]]; ans %= MOD2; ans += MOD2 * MOD2 - a * b; ans %= MOD2; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, x, n) for (int i = x; i <= n; i++) #define rep3(i, x, n) for (int i = x; i >= n; i--) #define elif else if typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll INF = 1e18; ll f(ll a, ll b) { return a + b; } int other = 0; struct segment_tree { ll n; ll seg[1000000]; // 要素数Nのセグメントツリーを構築 segment_tree(int N) { n = 1; while (n < N) n *= 2; fill_n(seg, 2 * n - 1, other); } // i番目の要素をxに変更(0番目から数える) void update(int i, ll x) { i += n - 1; seg[i] = x; while (i > 0) { i = (i - 1) / 2; seg[i] = f(seg[2 * i + 1], seg[2 * i + 2]); } } // 要素数N以上の最小の2べきnを取得 ll size() { return n; } // query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得 ll query(int a, int b, int i, int l, int r) { if (a >= r || b <= l) return other; elif (a <= l && r <= b) return seg[i]; else { int vl = query(a, b, 2 * i + 1, l, (l + r) / 2); int vr = query(a, b, 2 * i + 2, (l + r) / 2, r); return f(vl, vr); } } }; int main() { int N; cin >> N; ll e[N]; e[0] = 1; rep2(i, 1, N - 1) e[i] = (2 * e[i - 1]) % MOD2; int x[N], y[N]; vector<P> vecx, vecy, vec; rep(i, N) { cin >> x[i] >> y[i]; vecx.push_back(P(x[i], i)); vecy.push_back(P(y[i], i)); } sort(vecx.begin(), vecx.end()); sort(vecy.begin(), vecy.end()); rep(i, N) { int px = vecx[i].second, py = vecy[i].second; x[px] = i, y[py] = i; } rep(i, N) vec.push_back(P(x[i], y[i])); sort(vec.begin(), vec.end()); int X[N], Y[N]; rep(i, N) X[i] = vec[i].first, Y[i] = vec[i].second; segment_tree segl(N), segr(N); ll n = segl.size(); ll ul[N], ur[N], dl[N], dr[N]; rep(i, N) { dl[i] = segl.query(0, Y[i], 0, 0, n); ul[i] = i - dl[i]; segl.update(Y[i], 1); } rep3(i, N - 1, 0) { dr[i] = segr.query(0, Y[i], 0, 0, n); ur[i] = N - 1 - i - dr[i]; segr.update(Y[i], 1); } ll ans = (N * e[N - 1]) % MOD2; rep(i, N) { ll a = (e[ul[i]] - 1) * (e[dr[i]] - 1) % MOD2; ll b = (e[ur[i]] - 1) * (e[dl[i]] - 1) % MOD2; ans += a * e[ur[i] + dl[i]]; ans %= MOD2; ans += b * e[ul[i] + dr[i]]; ans %= MOD2; ans += MOD2 * MOD2 - a * b; ans %= MOD2; } cout << ans << endl; }
replace
17
18
17
18
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> #define MOD 998244353LL using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<P, int> PP; class segtree { public: static const int N = 1 << 18; int dp[1 << 19]; segtree() { memset(dp, 0, sizeof(dp)); } void update(int k, int v) { k += N - 1; dp[k] += v; while (k > 0) { k = (k - 1) / 2; dp[k] = dp[k * 2 + 1] + dp[k * 2 + 2]; } } int query(int a, int b, int k = 0, int l = 0, int r = N) { if (b <= l || r <= a) return 0; if (a <= l && r <= b) return dp[k]; int mid = (l + r) / 2; int vl = query(a, b, k * 2 + 1, l, mid); int vr = query(a, b, k * 2 + 2, mid, r); return vl + vr; } }; int n; int x[200005], y[200005]; vector<int> xi; vector<int> yi; int cnt[2][100005][2]; segtree seg; PP p[200005]; ll mod_pow(ll x, ll n) { ll ans = 1; while (n > 0) { if (n & 1) { ans = ans * x % MOD; } x = x * x % MOD; n >>= 1; } return ans; } int main(void) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld%lld", &x[i], &y[i]); xi.push_back(x[i]); yi.push_back(y[i]); } sort(xi.begin(), xi.end()); sort(yi.begin(), yi.end()); for (int i = 0; i < n; i++) { x[i] = lower_bound(xi.begin(), xi.end(), x[i]) - xi.begin(); y[i] = lower_bound(yi.begin(), yi.end(), y[i]) - yi.begin(); p[i].first = P(x[i], y[i]); p[i].second = i; } sort(p, p + n); for (int i = 0; i < n; i++) { int v = p[i].second; cnt[0][v][0] = seg.query(0, p[i].first.second); cnt[0][v][1] = seg.query(p[i].first.second, n); seg.update(p[i].first.second, 1); } memset(seg.dp, 0, sizeof(seg.dp)); for (int i = n - 1; i >= 0; i--) { int v = p[i].second; cnt[1][v][0] = seg.query(0, p[i].first.second); cnt[1][v][1] = seg.query(p[i].first.second, n); seg.update(p[i].first.second, 1); } ll ans = (ll)n * mod_pow(2, n - 1) % MOD; for (int i = 0; i < n; i++) { // printf("%lld %d %d %d // %d\n",ans,cnt[0][i][0],cnt[0][i][1],cnt[1][i][0],cnt[1][i][1]); ll val = (mod_pow(2, cnt[0][i][0]) - 1LL) * (mod_pow(2, cnt[1][i][1]) - 1LL) % MOD; ll val2 = (mod_pow(2, cnt[0][i][1]) - 1LL) * (mod_pow(2, cnt[1][i][0]) - 1LL) % MOD; ans += MOD - (val * val2) % MOD; ans %= MOD; ans += val * mod_pow(2, cnt[0][i][1] + cnt[1][i][0]) % MOD; ans %= MOD; ans += val2 * mod_pow(2, cnt[0][i][0] + cnt[1][i][1]) % MOD; ans %= MOD; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define MOD 998244353LL using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<P, int> PP; class segtree { public: static const int N = 1 << 18; int dp[1 << 19]; segtree() { memset(dp, 0, sizeof(dp)); } void update(int k, int v) { k += N - 1; dp[k] += v; while (k > 0) { k = (k - 1) / 2; dp[k] = dp[k * 2 + 1] + dp[k * 2 + 2]; } } int query(int a, int b, int k = 0, int l = 0, int r = N) { if (b <= l || r <= a) return 0; if (a <= l && r <= b) return dp[k]; int mid = (l + r) / 2; int vl = query(a, b, k * 2 + 1, l, mid); int vr = query(a, b, k * 2 + 2, mid, r); return vl + vr; } }; int n; int x[200005], y[200005]; vector<int> xi; vector<int> yi; int cnt[2][200005][2]; segtree seg; PP p[200005]; ll mod_pow(ll x, ll n) { ll ans = 1; while (n > 0) { if (n & 1) { ans = ans * x % MOD; } x = x * x % MOD; n >>= 1; } return ans; } int main(void) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld%lld", &x[i], &y[i]); xi.push_back(x[i]); yi.push_back(y[i]); } sort(xi.begin(), xi.end()); sort(yi.begin(), yi.end()); for (int i = 0; i < n; i++) { x[i] = lower_bound(xi.begin(), xi.end(), x[i]) - xi.begin(); y[i] = lower_bound(yi.begin(), yi.end(), y[i]) - yi.begin(); p[i].first = P(x[i], y[i]); p[i].second = i; } sort(p, p + n); for (int i = 0; i < n; i++) { int v = p[i].second; cnt[0][v][0] = seg.query(0, p[i].first.second); cnt[0][v][1] = seg.query(p[i].first.second, n); seg.update(p[i].first.second, 1); } memset(seg.dp, 0, sizeof(seg.dp)); for (int i = n - 1; i >= 0; i--) { int v = p[i].second; cnt[1][v][0] = seg.query(0, p[i].first.second); cnt[1][v][1] = seg.query(p[i].first.second, n); seg.update(p[i].first.second, 1); } ll ans = (ll)n * mod_pow(2, n - 1) % MOD; for (int i = 0; i < n; i++) { // printf("%lld %d %d %d // %d\n",ans,cnt[0][i][0],cnt[0][i][1],cnt[1][i][0],cnt[1][i][1]); ll val = (mod_pow(2, cnt[0][i][0]) - 1LL) * (mod_pow(2, cnt[1][i][1]) - 1LL) % MOD; ll val2 = (mod_pow(2, cnt[0][i][1]) - 1LL) * (mod_pow(2, cnt[1][i][0]) - 1LL) % MOD; ans += MOD - (val * val2) % MOD; ans %= MOD; ans += val * mod_pow(2, cnt[0][i][1] + cnt[1][i][0]) % MOD; ans %= MOD; ans += val2 * mod_pow(2, cnt[0][i][0] + cnt[1][i][1]) % MOD; ans %= MOD; } printf("%lld\n", ans); return 0; }
replace
37
38
37
38
0
p02956
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; 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; } using ll = long long; using P = pair<ll, ll>; using graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1 << 30; const ll mod = 998244353LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct BIT { ll bit[1000010]; void add(ll a, ll w) { for (ll x = a; x < 1000010; x += (x & -x)) bit[x] += w; } ll sum(ll a) { ll ret = 0; for (ll x = a; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } }; ll pow(ll a, ll n, ll m) { ll ret = 1LL; for (; n > 0LL; n >>= 1LL, a = a * a % m) { if (n % 2LL == 1LL) { ret = ret * a % m; } } return ret; } int main() { ll N; cin >> N; vector<P> v(N); rep(i, N) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end()); vector<ll> y(N), Y(N); rep(i, N) y[i] = Y[i] = v[i].second; sort(y.begin(), y.end()); rep(i, N) { ll s = find(y.begin(), y.end(), Y[i]) - y.begin() + 1; Y[i] = s; } BIT B; vector<vector<ll>> cnt(N, vector<ll>(4)); rep(i, N) { cnt[i][1] = B.sum(Y[i]); B.add(Y[i], 1); } BIT C; rep(i, N) { cnt[N - i - 1][2] = C.sum(Y[N - i - 1]); C.add(Y[N - i - 1], 1); } rep(i, N) { cnt[i][0] = i - cnt[i][1]; cnt[i][3] = N - i - 1 - cnt[i][2]; } ll al = pow(2LL, N, mod) - 1; ll ans = 0; rep(i, N) { ll t = 0; rep(j, 4) { t += (pow(2LL, cnt[i][j] + cnt[i][(j + 1) % 4], mod) - pow(2LL, cnt[i][j], mod)) % mod; } ans = (ans + (al - t)) % mod; } if (ans < 0) ans += mod; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; 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; } using ll = long long; using P = pair<ll, ll>; using graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1 << 30; const ll mod = 998244353LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct BIT { ll bit[1000010]; void add(ll a, ll w) { for (ll x = a; x < 1000010; x += (x & -x)) bit[x] += w; } ll sum(ll a) { ll ret = 0; for (ll x = a; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } }; ll pow(ll a, ll n, ll m) { ll ret = 1LL; for (; n > 0LL; n >>= 1LL, a = a * a % m) { if (n % 2LL == 1LL) { ret = ret * a % m; } } return ret; } int main() { ll N; cin >> N; vector<P> v(N); rep(i, N) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end()); vector<ll> y(N), Y(N); rep(i, N) y[i] = Y[i] = v[i].second; sort(y.begin(), y.end()); rep(i, N) { ll s = lower_bound(y.begin(), y.end(), Y[i]) - y.begin() + 1; Y[i] = s; } BIT B; vector<vector<ll>> cnt(N, vector<ll>(4)); rep(i, N) { cnt[i][1] = B.sum(Y[i]); B.add(Y[i], 1); } BIT C; rep(i, N) { cnt[N - i - 1][2] = C.sum(Y[N - i - 1]); C.add(Y[N - i - 1], 1); } rep(i, N) { cnt[i][0] = i - cnt[i][1]; cnt[i][3] = N - i - 1 - cnt[i][2]; } ll al = pow(2LL, N, mod) - 1; ll ans = 0; rep(i, N) { ll t = 0; rep(j, 4) { t += (pow(2LL, cnt[i][j] + cnt[i][(j + 1) % 4], mod) - pow(2LL, cnt[i][j], mod)) % mod; } ans = (ans + (al - t)) % mod; } if (ans < 0) ans += mod; cout << ans << endl; }
replace
63
64
63
64
TLE
p02956
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define form2(i, a, b) for (int i = (a); i < (b); ++i) #define ford2(i, a, b) for (int i = (a - 1); i >= (b); --i) #define form(i, n) form2(i, 0, n) #define ford(i, n) ford2(i, n, 0) #define chmax(x, v) x = max(x, (v)) #define chmin(x, v) x = min(x, (v)) #define fi first #define se second const long long BIG = 1000000000000000000LL; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } const int MOD = 998244353; const int borne = 2 * (int)(1e5) + 5; int fen[borne]; int getSom(int idx) { int res = 0; while (idx > 0) { res += fen[idx]; idx -= idx & (-idx); } return res; } int getSom(int l, int r) { if (l > r) return 0; else return getSom(r) - getSom(l - 1); } void inc(int idx) { while (idx < borne) { fen[idx]++; idx += idx & (-idx); } } map<int, int> compX, compY; pii pts[borne]; int quad[borne][4]; int nbPoints; void docmp(vector<int> vec, map<int, int> &cmap) { sort(vec.begin(), vec.end()); int sz = vec.size(); form(i, sz) { cmap[vec[i]] = i + 1; } } int pm[borne]; int cmm(int x) { x %= MOD; x += MOD; x %= MOD; return x; } void solve() { cin >> nbPoints; vector<int> lx, ly; form(i, nbPoints) { int x, y; cin >> x >> y; lx.push_back(x); ly.push_back(y); pts[i] = {x, y}; } docmp(lx, compX); docmp(ly, compY); form(i, nbPoints) { pts[i].fi += 30; pts[i].se += 30; // pts[i].fi = compX[pts[i].fi]; // pts[i].se = compY[pts[i].se]; } sort(pts, pts + nbPoints); form(i, nbPoints) { quad[i][0] = getSom(1, pts[i].se); quad[i][1] = getSom(pts[i].se, borne - 1); inc(pts[i].se); } form(i, borne) fen[i] = 0; ford(i, nbPoints) { quad[i][3] = getSom(1, pts[i].se); quad[i][2] = getSom(pts[i].se, borne - 1); inc(pts[i].se); } pm[0] = 1; form2(i, 1, borne) { pm[i] = cmm(2 * pm[i - 1]); } int res = 0; vector<int> v{0, 1, 2, 3}; set<vector<int>> sp; do { form(c, 4) { vector<int> yw; form(i, c + 1) yw.push_back(v[i]); bool ok = false; for (int a : yw) for (int b : yw) if (a % 2 == b % 2 && a != b) ok = true; if (!ok) continue; sort(yw.begin(), yw.end()); sp.insert(yw); } } while (next_permutation(v.begin(), v.end())); form(i, nbPoints) { for (auto yw : sp) { int subCnt = 1; for (int x : yw) { subCnt = cmm(subCnt * cmm(pm[quad[i][x]] - 1)); } res = cmm(res + subCnt); } res = cmm(res + pm[nbPoints - 1]); } cout << res << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long #define form2(i, a, b) for (int i = (a); i < (b); ++i) #define ford2(i, a, b) for (int i = (a - 1); i >= (b); --i) #define form(i, n) form2(i, 0, n) #define ford(i, n) ford2(i, n, 0) #define chmax(x, v) x = max(x, (v)) #define chmin(x, v) x = min(x, (v)) #define fi first #define se second const long long BIG = 1000000000000000000LL; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } const int MOD = 998244353; const int borne = 2 * (int)(1e5) + 5; int fen[borne]; int getSom(int idx) { int res = 0; while (idx > 0) { res += fen[idx]; idx -= idx & (-idx); } return res; } int getSom(int l, int r) { if (l > r) return 0; else return getSom(r) - getSom(l - 1); } void inc(int idx) { while (idx < borne) { fen[idx]++; idx += idx & (-idx); } } map<int, int> compX, compY; pii pts[borne]; int quad[borne][4]; int nbPoints; void docmp(vector<int> vec, map<int, int> &cmap) { sort(vec.begin(), vec.end()); int sz = vec.size(); form(i, sz) { cmap[vec[i]] = i + 1; } } int pm[borne]; int cmm(int x) { x %= MOD; x += MOD; x %= MOD; return x; } void solve() { cin >> nbPoints; vector<int> lx, ly; form(i, nbPoints) { int x, y; cin >> x >> y; lx.push_back(x); ly.push_back(y); pts[i] = {x, y}; } docmp(lx, compX); docmp(ly, compY); form(i, nbPoints) { pts[i].fi = compX[pts[i].fi]; pts[i].se = compY[pts[i].se]; } sort(pts, pts + nbPoints); form(i, nbPoints) { quad[i][0] = getSom(1, pts[i].se); quad[i][1] = getSom(pts[i].se, borne - 1); inc(pts[i].se); } form(i, borne) fen[i] = 0; ford(i, nbPoints) { quad[i][3] = getSom(1, pts[i].se); quad[i][2] = getSom(pts[i].se, borne - 1); inc(pts[i].se); } pm[0] = 1; form2(i, 1, borne) { pm[i] = cmm(2 * pm[i - 1]); } int res = 0; vector<int> v{0, 1, 2, 3}; set<vector<int>> sp; do { form(c, 4) { vector<int> yw; form(i, c + 1) yw.push_back(v[i]); bool ok = false; for (int a : yw) for (int b : yw) if (a % 2 == b % 2 && a != b) ok = true; if (!ok) continue; sort(yw.begin(), yw.end()); sp.insert(yw); } } while (next_permutation(v.begin(), v.end())); form(i, nbPoints) { for (auto yw : sp) { int subCnt = 1; for (int x : yw) { subCnt = cmm(subCnt * cmm(pm[quad[i][x]] - 1)); } res = cmm(res + subCnt); } res = cmm(res + pm[nbPoints - 1]); } cout << res << "\n"; }
replace
87
91
87
89
0
p02956
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; const i64 MOD = (i64)1e9 + 7; const i64 INF = (i64)1e18 + 7; template <typename T = i64> struct Range { struct iterator { T value; const T step, last; const T &operator*() { return value; } iterator(T value, T step, T last) : value(step < static_cast<T>(0) ? max(last, value) : min(last, value)), step(step), last(last) {} iterator operator++() { value = step < static_cast<T>(0) ? max(value + step, last) : min(value + step, last); return *this; } bool operator!=(const iterator &x) { return value != x.value; } }; const T start, last, step; Range(const T start, const T last, const T step = static_cast<T>(1)) : start(start), last(last), step(step) {} Range(const T last) : start(0), last(last), step(1) {} iterator begin() { return iterator(start, step, last); } iterator end() { return iterator(last, step, last); } }; template <typename F> struct FixPoint { const F _f; FixPoint(F &&f) : _f(forward<F>(f)) {} template <typename... Types> decltype(auto) operator()(Types &&...args) const { return _f(*this, forward<Types>(args)...); } }; template <typename F> static decltype(auto) makeRec(F &&f) { return FixPoint<F>(forward<F>(f)); } template <typename T, T Value = T()> vector<T> makeVector(size_t x) { return vector<T>(x, T(Value)); } template <typename T, T Value = T(), typename... Types> auto makeVector(size_t x, Types... args) { return vector<decltype(makeVector<T, Value>(args...))>( x, makeVector<T, Value>(args...)); } template <typename T = i64> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T = i64> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #ifdef TEST #define dump(x) \ fprintf(stderr, "line =%4d, name =%7s , ", __LINE__, #x); \ cout << "value = " << x << endl; #define vecdump(x) \ fprintf(stderr, "line =%4d, name =%7s\n", __LINE__, #x); \ _dump_macro(x); #else #define vecdump(x) #define dump(x) #endif void _dump(int, string &x) { #ifdef TEST cout << x << endl; #endif } template <typename T> void _dump(bool, T &x) { #ifdef TEST cout << x << " "; #endif } template <typename T, typename U = typename T::iterator> void _dump(int, T &x) { #ifdef TEST for (auto &elm : x) _dump(0, elm); cout << endl; #endif } template <typename T> void _dump_macro(T &x) { _dump(0, x); } void _input(int, string &x) { cin >> x; } template <typename T> void _input(bool, T &x) { cin >> x; } template <typename T, typename U = typename T::iterator> void _input(int, T &x) { for (auto &elm : x) _input(0, elm); } template <typename T> void input_single(T &x) { _input(0, x); } auto input() {} template <typename T, typename... Types> void input(T &value, Types &&...args) { input_single(value); input(forward<Types>(args)...); }; void _pararell_input(size_t) {} template <typename T, typename... Types> void _pararell_input(size_t index, T &value, Types &&...args) { input(value[index]); _pararell_input(index, forward<Types>(args)...); } template <typename... Types> void pararell_input(size_t count, Types &&...args) { for (const auto &i : Range<>(count)) _pararell_input(i, forward<Types>(args)...); } template <typename T> struct Segtree { int n; T op; vector<T> elm; function<T(T, T)> f; Segtree(int n, T init, function<T(T, T)> f, T op = T()) : n(n), op(op), elm(2 * n, init), f(f) { for (int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) : n(n), op(op), elm(2 * n), f(f) { for (int i = 0; i < n; ++i) elm[i + n] = init[i]; for (int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } void set(int x, T val) { x += n; elm[x] = val; while (x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } void update(int x, T val) { x += n; elm[x] = f(val, elm[x]); while (x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } T get(int x, int y) const { T l = op, r = op; for (x += n, y += n - 1; x <= y; x >>= 1, y >>= 1) { if (x & 1) l = f(l, elm[x++]); if (!(y & 1)) r = f(elm[y--], r); } return f(l, r); } }; template <typename T> struct Compression { vector<T> compvec; Compression(vector<T> &inp) { // 圧縮する compvec = inp; sort(compvec.begin(), compvec.end()); compvec.erase(unique(compvec.begin(), compvec.end()), compvec.end()); } int Index(T val) { // 圧縮を元に対応するインデックスを返す auto it = lower_bound(compvec.begin(), compvec.end(), val); return distance(compvec.begin(), it); } vector<T> &operator*() { return compvec; } }; template <i64 mod = MOD> struct ModInt { i64 p; ModInt() : p(0) {} ModInt(i64 x) { p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod; } ModInt &operator+=(const ModInt &y) { p = p + *y - ((p + *y) >= mod ? mod : 0); return *this; } ModInt &operator-=(const ModInt &y) { p = p - *y + (p - *y < 0 ? mod : 0); return *this; } ModInt &operator*=(const ModInt &y) { p = (p * *y) % mod; return *this; } ModInt &operator%=(const ModInt &y) { if (y) p %= *y; return *this; } ModInt operator+(const ModInt &y) const { ModInt x = *this; return x += y; } ModInt operator-(const ModInt &y) const { ModInt x = *this; return x -= y; } ModInt operator*(const ModInt &y) const { ModInt x = *this; return x *= y; } ModInt operator%(const ModInt &y) const { ModInt x = *this; return x %= y; } friend ostream &operator<<(ostream &stream, const ModInt<mod> &x) { stream << *x; return stream; } friend ostream &operator>>(ostream &stream, const ModInt<mod> &x) { stream >> *x; return stream; } ModInt &operator++() { p = (p + 1) % mod; return *this; } ModInt &operator--() { p = (p - 1 + mod) % mod; return *this; } bool operator==(const ModInt &y) const { return p == *y; } bool operator!=(const ModInt &y) const { return p != *y; } const i64 &operator*() const { return p; } i64 &operator*() { return p; } }; using mint = ModInt<998244353>; i64 solve(i64 _count) { int n; input(n); if (!static_cast<bool>(cin)) return MOD; #ifdef TEST cout << "Case: " << _count << endl; #endif vector<i64> x(n), y(n); pararell_input(n, x, y); vector<pair<i64, i64>> v; for (int i = 0; i < n; ++i) v.emplace_back(x[i], y[i]); sort(v.begin(), v.end()); vector<mint> tp(n + 3, 1); for (int i = 0; i < n + 3; ++i) tp[i + 1] = tp[i] * 2; Compression<i64> comp(y); Segtree<int> seg_up( n, 1, [](auto x, auto y) { return x + y; }, 0); Segtree<int> seg_down( n, 0, [](auto x, auto y) { return x + y; }, 0); mint ans(0); for (auto &p : v) { int idx = comp.Index(p.second); seg_up.set(idx, 0); i64 p1 = seg_up.get(0, idx); i64 p2 = seg_up.get(idx, n); i64 p3 = seg_down.get(0, idx); i64 p4 = seg_down.get(idx, n); mint val = 1; val *= tp[p1] - 1; val *= tp[p4] - 1; ans += val * tp[n - p1 - p4 - 1]; val = 1; val *= tp[p2] - 1; val *= tp[p3] - 1; ans += val * tp[n - p2 - p3 - 1]; val = 1; val *= tp[p1] - 1; val *= tp[p2] - 1; val *= tp[p3] - 1; val *= tp[p4] - 1; ans -= val; ans += tp[n - 1]; seg_down.set(idx, 1); } cout << ans << endl; return 0; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 0; while (solve(++t) != MOD) ; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; const i64 MOD = (i64)1e9 + 7; const i64 INF = (i64)1e18 + 7; template <typename T = i64> struct Range { struct iterator { T value; const T step, last; const T &operator*() { return value; } iterator(T value, T step, T last) : value(step < static_cast<T>(0) ? max(last, value) : min(last, value)), step(step), last(last) {} iterator operator++() { value = step < static_cast<T>(0) ? max(value + step, last) : min(value + step, last); return *this; } bool operator!=(const iterator &x) { return value != x.value; } }; const T start, last, step; Range(const T start, const T last, const T step = static_cast<T>(1)) : start(start), last(last), step(step) {} Range(const T last) : start(0), last(last), step(1) {} iterator begin() { return iterator(start, step, last); } iterator end() { return iterator(last, step, last); } }; template <typename F> struct FixPoint { const F _f; FixPoint(F &&f) : _f(forward<F>(f)) {} template <typename... Types> decltype(auto) operator()(Types &&...args) const { return _f(*this, forward<Types>(args)...); } }; template <typename F> static decltype(auto) makeRec(F &&f) { return FixPoint<F>(forward<F>(f)); } template <typename T, T Value = T()> vector<T> makeVector(size_t x) { return vector<T>(x, T(Value)); } template <typename T, T Value = T(), typename... Types> auto makeVector(size_t x, Types... args) { return vector<decltype(makeVector<T, Value>(args...))>( x, makeVector<T, Value>(args...)); } template <typename T = i64> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T = i64> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #ifdef TEST #define dump(x) \ fprintf(stderr, "line =%4d, name =%7s , ", __LINE__, #x); \ cout << "value = " << x << endl; #define vecdump(x) \ fprintf(stderr, "line =%4d, name =%7s\n", __LINE__, #x); \ _dump_macro(x); #else #define vecdump(x) #define dump(x) #endif void _dump(int, string &x) { #ifdef TEST cout << x << endl; #endif } template <typename T> void _dump(bool, T &x) { #ifdef TEST cout << x << " "; #endif } template <typename T, typename U = typename T::iterator> void _dump(int, T &x) { #ifdef TEST for (auto &elm : x) _dump(0, elm); cout << endl; #endif } template <typename T> void _dump_macro(T &x) { _dump(0, x); } void _input(int, string &x) { cin >> x; } template <typename T> void _input(bool, T &x) { cin >> x; } template <typename T, typename U = typename T::iterator> void _input(int, T &x) { for (auto &elm : x) _input(0, elm); } template <typename T> void input_single(T &x) { _input(0, x); } auto input() {} template <typename T, typename... Types> void input(T &value, Types &&...args) { input_single(value); input(forward<Types>(args)...); }; void _pararell_input(size_t) {} template <typename T, typename... Types> void _pararell_input(size_t index, T &value, Types &&...args) { input(value[index]); _pararell_input(index, forward<Types>(args)...); } template <typename... Types> void pararell_input(size_t count, Types &&...args) { for (const auto &i : Range<>(count)) _pararell_input(i, forward<Types>(args)...); } template <typename T> struct Segtree { int n; T op; vector<T> elm; function<T(T, T)> f; Segtree(int n, T init, function<T(T, T)> f, T op = T()) : n(n), op(op), elm(2 * n, init), f(f) { for (int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) : n(n), op(op), elm(2 * n), f(f) { for (int i = 0; i < n; ++i) elm[i + n] = init[i]; for (int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } void set(int x, T val) { x += n; elm[x] = val; while (x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } void update(int x, T val) { x += n; elm[x] = f(val, elm[x]); while (x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } T get(int x, int y) const { T l = op, r = op; for (x += n, y += n - 1; x <= y; x >>= 1, y >>= 1) { if (x & 1) l = f(l, elm[x++]); if (!(y & 1)) r = f(elm[y--], r); } return f(l, r); } }; template <typename T> struct Compression { vector<T> compvec; Compression(vector<T> &inp) { // 圧縮する compvec = inp; sort(compvec.begin(), compvec.end()); compvec.erase(unique(compvec.begin(), compvec.end()), compvec.end()); } int Index(T val) { // 圧縮を元に対応するインデックスを返す auto it = lower_bound(compvec.begin(), compvec.end(), val); return distance(compvec.begin(), it); } vector<T> &operator*() { return compvec; } }; template <i64 mod = MOD> struct ModInt { i64 p; ModInt() : p(0) {} ModInt(i64 x) { p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod; } ModInt &operator+=(const ModInt &y) { p = p + *y - ((p + *y) >= mod ? mod : 0); return *this; } ModInt &operator-=(const ModInt &y) { p = p - *y + (p - *y < 0 ? mod : 0); return *this; } ModInt &operator*=(const ModInt &y) { p = (p * *y) % mod; return *this; } ModInt &operator%=(const ModInt &y) { if (y) p %= *y; return *this; } ModInt operator+(const ModInt &y) const { ModInt x = *this; return x += y; } ModInt operator-(const ModInt &y) const { ModInt x = *this; return x -= y; } ModInt operator*(const ModInt &y) const { ModInt x = *this; return x *= y; } ModInt operator%(const ModInt &y) const { ModInt x = *this; return x %= y; } friend ostream &operator<<(ostream &stream, const ModInt<mod> &x) { stream << *x; return stream; } friend ostream &operator>>(ostream &stream, const ModInt<mod> &x) { stream >> *x; return stream; } ModInt &operator++() { p = (p + 1) % mod; return *this; } ModInt &operator--() { p = (p - 1 + mod) % mod; return *this; } bool operator==(const ModInt &y) const { return p == *y; } bool operator!=(const ModInt &y) const { return p != *y; } const i64 &operator*() const { return p; } i64 &operator*() { return p; } }; using mint = ModInt<998244353>; i64 solve(i64 _count) { int n; input(n); if (!static_cast<bool>(cin)) return MOD; #ifdef TEST cout << "Case: " << _count << endl; #endif vector<i64> x(n), y(n); pararell_input(n, x, y); vector<pair<i64, i64>> v; for (int i = 0; i < n; ++i) v.emplace_back(x[i], y[i]); sort(v.begin(), v.end()); vector<mint> tp(n + 3, 1); for (int i = 0; i < n + 2; ++i) tp[i + 1] = tp[i] * 2; Compression<i64> comp(y); Segtree<int> seg_up( n, 1, [](auto x, auto y) { return x + y; }, 0); Segtree<int> seg_down( n, 0, [](auto x, auto y) { return x + y; }, 0); mint ans(0); for (auto &p : v) { int idx = comp.Index(p.second); seg_up.set(idx, 0); i64 p1 = seg_up.get(0, idx); i64 p2 = seg_up.get(idx, n); i64 p3 = seg_down.get(0, idx); i64 p4 = seg_down.get(idx, n); mint val = 1; val *= tp[p1] - 1; val *= tp[p4] - 1; ans += val * tp[n - p1 - p4 - 1]; val = 1; val *= tp[p2] - 1; val *= tp[p3] - 1; ans += val * tp[n - p2 - p3 - 1]; val = 1; val *= tp[p1] - 1; val *= tp[p2] - 1; val *= tp[p3] - 1; val *= tp[p4] - 1; ans -= val; ans += tp[n - 1]; seg_down.set(idx, 1); } cout << ans << endl; return 0; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 0; while (solve(++t) != MOD) ; }
replace
294
295
294
295
0