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
p02818
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; while (k > 0) { if (a > 0) { a -= 1; k -= 1; } else if (b > 0) { b -= 1; k -= 1; } else { k -= 1; break; } } cout << a << " " << b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; if (k > a) { k -= a; a = 0; } else { a -= k; k = 0; } if (k > b) { k -= b; b = 0; } else { b -= k; k = 0; } cout << a << " " << b; return 0; }
replace
5
16
5
18
TLE
p02818
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++) int main() { ll a, b, k; cin >> a >> b >> k; rep(i, k) { if (a >= 1) a--; else if (b >= 1) b--; else break; } cout << a << ' ' << b << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++) int main() { ll a, b, k; cin >> a >> b >> k; if (k <= a) { cout << a - k << ' ' << b << endl; } else if (k <= a + b) { cout << 0 << ' ' << b - (k - a) << endl; } else cout << 0 << ' ' << 0 << endl; }
replace
12
21
12
18
TLE
p02818
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #define endl "\n" #define all(v) v.begin(), v.end() #define allr(s) s.rbegin(), s.rend() #define RT(s) return cout << s, 0 #define watch(x) cout << (#x) << " = " << x << endl #define sz(s) (int)(s.size()) #define PI acos(-1) #define EPS 1e-8 using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else // freopen("street.in", "r", stdin); // freopen("out.txt", "w", stdout); #endif } void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); ll a, b, k; cin >> a >> b >> k; ll mn = min(a, k); a -= mn, k -= mn; b -= k; b = max(b, 0LL); cout << a << ' ' << b << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #define endl "\n" #define all(v) v.begin(), v.end() #define allr(s) s.rbegin(), s.rend() #define RT(s) return cout << s, 0 #define watch(x) cout << (#x) << " = " << x << endl #define sz(s) (int)(s.size()) #define PI acos(-1) #define EPS 1e-8 using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else // freopen("street.in", "r", stdin); // freopen("out.txt", "w", stdout); #endif } void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { // file(); fast(); ll a, b, k; cin >> a >> b >> k; ll mn = min(a, k); a -= mn, k -= mn; b -= k; b = max(b, 0LL); cout << a << ' ' << b << endl; return 0; }
replace
35
36
35
36
0
p02818
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; while (a > 0) { a--; k--; if (k == 0) break; } while (b > 0) { b--; k--; if (k == 0) break; } cout << a << " " << b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; if (a >= k) cout << a - k << " " << b; else if (a < k && a + b >= k) cout << 0 << " " << b - k + a; else if (a < k && b < k) cout << 0 << " " << 0; return 0; }
replace
6
19
6
12
TLE
p02818
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; if (a + b <= k) { cout << "0 0" << endl; } else { for (long i = 0; i < k; i++) { if (a > 0) --a; else if (b > 0) --b; } cout << a << " " << b << endl; } return 0; }
#include <iostream> using namespace std; int main() { long long a, b, k; cin >> a >> b >> k; if (a + b <= k) { cout << "0 0" << endl; } else { if (k <= a) cout << a - k << " " << b << endl; else cout << "0 " << b + a - k; } return 0; }
replace
9
16
9
13
TLE
p02818
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long A, B, K; cin >> A >> B >> K; if (A > K) { A -= K; } else { B -= K - A; A = 0; } printf("%llf %llf\n", A, max(0LL, B)); }
#include <bits/stdc++.h> using namespace std; int main() { long long A, B, K; cin >> A >> B >> K; if (A > K) { A -= K; } else { B -= K - A; A = 0; } printf("%lld %lld\n", A, max(0LL, B)); }
replace
11
12
11
12
0
p02818
C++
Time Limit Exceeded
#include <iostream> using namespace std; long A, B, K; int main() { cin >> A >> B >> K; for (long i = 0; i < K; i++) { if (A >= 1) { A--; } else if (B >= 1) { B--; } else { break; } } cout << A << ' ' << B; }
#include <iostream> using namespace std; long A, B, K; int main() { cin >> A >> B >> K; if (K < A) { A = A - K; } else { B = B - (K - A); A = 0; } if (B < 0) { B = 0; } cout << A << ' ' << B; }
replace
8
16
8
17
TLE
p02818
Python
Time Limit Exceeded
A, B, K = map(int, input().split()) for _ in range(K): if A > 0: A -= 1 elif B > 0: B -= 1 else: continue print(A, B)
A, B, K = map(int, input().split()) C = max(0, A - K) K -= A - C print(C, max(0, B - K))
replace
2
10
2
5
TLE
p02818
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define co(a) cout << a << endl #define sz size() #define bgn begin() #define en end() #define pb(a) push_back(a) #define pp() pop_back() #define V vector #define P pair #define V2(a, b, c) V<V<int>> a(b, V<int>(c)) #define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d)) #define incin(a) \ int a; \ cin >> a #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define pri priority_queue #define syo <int,V<int> #define ff fi.fi #define fs fi.se #define sf se.fi #define ss se.se #define all(a) (a).begin(), (a).end() #define Pi P<int, int> #define elif else if // #define min min<int> // #define max max<int> int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } /*template<> void cou(vector<vector<char>> a){ int b=a.size(); int c=a[0].size(); fo(i,b){ fo(j,c){ cout<<a[i][j]; if(j==c-1) cout<<endl; else cout<<' '; } } }*/ int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } /*int lcm(int a,int b){ int d=a,e=b,f; if(a<b) swap(a,b); int c,m=1; while(m){ c=a%b; if(c==0){ f=b; m--; } else{ a=b; b=c; } } return d*e/f; } */ int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } /*int gcm(int a,int b){ if(b==0) return a; return gcm(b,a%b); }*/ int lcm(int a, int b) { return a / gcm(a, b) * b; } /*struct aa{ vector<int> gt; aa(int n){ gt= vector<int>(n, 1); } void c(V<int> d,int b){ if(d[b]==0){ gt[d[b]-1]++; gt[gt.sz-1]++; } else{ gt[d[b]-1]++; c(d,d[d[b]]-1); } } void cok(int a){ cout<<gt[a-1]<<endl; fo(i,a-1) cout<<gt[i]<<endl; } }; */ /*struct dfs(){ }*/ bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ signed main() { int A, B, K; cin >> A >> B >> K; fo(i, K) { if (A != 0) A--; else if (B != 0) B--; } cout << A << " " << B; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define co(a) cout << a << endl #define sz size() #define bgn begin() #define en end() #define pb(a) push_back(a) #define pp() pop_back() #define V vector #define P pair #define V2(a, b, c) V<V<int>> a(b, V<int>(c)) #define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d)) #define incin(a) \ int a; \ cin >> a #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define pri priority_queue #define syo <int,V<int> #define ff fi.fi #define fs fi.se #define sf se.fi #define ss se.se #define all(a) (a).begin(), (a).end() #define Pi P<int, int> #define elif else if // #define min min<int> // #define max max<int> int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } /*template<> void cou(vector<vector<char>> a){ int b=a.size(); int c=a[0].size(); fo(i,b){ fo(j,c){ cout<<a[i][j]; if(j==c-1) cout<<endl; else cout<<' '; } } }*/ int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } /*int lcm(int a,int b){ int d=a,e=b,f; if(a<b) swap(a,b); int c,m=1; while(m){ c=a%b; if(c==0){ f=b; m--; } else{ a=b; b=c; } } return d*e/f; } */ int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } /*int gcm(int a,int b){ if(b==0) return a; return gcm(b,a%b); }*/ int lcm(int a, int b) { return a / gcm(a, b) * b; } /*struct aa{ vector<int> gt; aa(int n){ gt= vector<int>(n, 1); } void c(V<int> d,int b){ if(d[b]==0){ gt[d[b]-1]++; gt[gt.sz-1]++; } else{ gt[d[b]-1]++; c(d,d[d[b]]-1); } } void cok(int a){ cout<<gt[a-1]<<endl; fo(i,a-1) cout<<gt[i]<<endl; } }; */ /*struct dfs(){ }*/ bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ signed main() { int A, B, K; cin >> A >> B >> K; if (A >= K) cout << A - K << " " << B; else if (A + B >= K) cout << 0 << " " << A + B - K; else cout << 0 << " " << 0; }
replace
246
254
246
253
TLE
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <vector> using namespace std; const int N = pow(10, 9); vector<bool> isp(N + 1, true); void sieve() { isp[0] = false; isp[1] = false; for (int i = 2; pow(i, 2) <= N; i++) { if (isp[i]) for (int j = 2; i * j <= N; j++) isp[i * j] = false; } } int main() { long long N, a, b = 0; long long counter = 0; cin >> N; long long counter1 = 0; vector<long long> vec(100005); vector<long long> ves(100005); // N以下の整数に対して素数判定をしてくれます。 // nが素数ならば isp(n)=true、そうでなければ isp(n)=false sieve(); // ex. 51から80までの素数を出力 for (long long i = N; i > 0; i++) { if (isp[i]) { counter1 = i; break; } } cout << counter1 << endl; }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <vector> using namespace std; const int N = pow(10, 6); vector<bool> isp(N + 1, true); void sieve() { isp[0] = false; isp[1] = false; for (int i = 2; pow(i, 2) <= N; i++) { if (isp[i]) for (int j = 2; i * j <= N; j++) isp[i * j] = false; } } int main() { long long N, a, b = 0; long long counter = 0; cin >> N; long long counter1 = 0; vector<long long> vec(100005); vector<long long> ves(100005); // N以下の整数に対して素数判定をしてくれます。 // nが素数ならば isp(n)=true、そうでなければ isp(n)=false sieve(); // ex. 51から80までの素数を出力 for (long long i = N; i > 0; i++) { if (isp[i]) { counter1 = i; break; } } cout << counter1 << endl; }
replace
6
7
6
7
TLE
p02819
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = 1; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(a) (a).begin(), (a).end() typedef pair<int, int> P; typedef long long ll; bool is_prime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; for (ll i = 3; i <= (ll)sqrt(num); i += 2) { if (num % i == 0) return false; } return true; } int main() { int x; cin >> x; for (int i = x;; i++) { if (is_prime(i)) { dunk(i); } } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = 1; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(a) (a).begin(), (a).end() typedef pair<int, int> P; typedef long long ll; bool is_prime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; for (ll i = 3; i <= (ll)sqrt(num); i += 2) { if (num % i == 0) return false; } return true; } int main() { int x; cin >> x; for (int i = x;; i++) { if (is_prime(i)) { dunk(i); return 0; } } return 0; }
insert
32
32
32
33
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int x, s; int a[100009][2]; for (int i = 2; i < 100009; i++) { a[i][0] = i; a[i][1] = 0; } for (int i = 2; i < 400; i++) { if (a[i][1] == 0) { a[i][1] = 2; s = 2; while (i * s < 100009) { a[i * s][1] = 1; s++; } } } s = 0; cin >> x; while (s == 0) { if (a[x][1] == 2) { cout << x << endl; s++; } else x++; } }
#include <bits/stdc++.h> using namespace std; int main() { int x, s; int a[100009][2]; for (int i = 2; i < 100009; i++) { a[i][0] = i; a[i][1] = 0; } for (int i = 2; i < 100009; i++) { if (a[i][1] == 0) { a[i][1] = 2; s = 2; while (i * s < 100009) { a[i * s][1] = 1; s++; } } } s = 0; cin >> x; while (s == 0) { if (a[x][1] == 2) { cout << x << endl; s++; } else x++; } }
replace
10
11
10
11
0
p02819
C++
Runtime Error
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <bits/stdc++.h> using namespace std; using ll = int64_t; using Pair = pair<int32_t, int32_t>; // std::cout << std::setprecision(20) << 1.1 << endl; int32_t f(const int32_t n) { return (n % 2 == 0) ? n / 2 : 3 * n + 1; } int main() { cin.tie(0); ios::sync_with_stdio(false); int32_t X; cin >> X; const int32_t max_search = max(100, 2 * X); vector<bool> is_prime(max_search, true); int32_t result = -1; for (int32_t i = 2; i <= max_search; ++i) { if (is_prime[i]) { if (i >= X) { result = i; break; } int32_t j = 2 * i; while (j <= max_search) { is_prime[j] = false; j += i; } } } cout << result << endl; return 0; }
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <bits/stdc++.h> using namespace std; using ll = int64_t; using Pair = pair<int32_t, int32_t>; // std::cout << std::setprecision(20) << 1.1 << endl; int32_t f(const int32_t n) { return (n % 2 == 0) ? n / 2 : 3 * n + 1; } int main() { cin.tie(0); ios::sync_with_stdio(false); int32_t X; cin >> X; const int32_t max_search = max(100, 2 * X); vector<bool> is_prime(max_search + 1, true); int32_t result = -1; for (int32_t i = 2; i <= max_search; ++i) { if (is_prime[i]) { if (i >= X) { result = i; break; } int32_t j = 2 * i; while (j <= max_search) { is_prime[j] = false; j += i; } } } cout << result << endl; return 0; }
replace
20
21
20
21
0
p02819
C++
Time Limit Exceeded
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int x; int ans; cin >> x; ans = 0; int x2; x2 = x; while (ans == 0) { rep(i, x2 - 2) { if (x % (i + 2) == 0) { break; } if (i == x2 - 3) { ans = x; } } ++x; } cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int x; int ans; cin >> x; ans = 0; int x2; x2 = x; while (ans == 0) { if (x == 2) { ans = 2; break; } rep(i, x2 - 2) { if (x % (i + 2) == 0) { break; } if (i == x2 - 3) { ans = x; } } ++x; } cout << ans << endl; return 0; }
insert
14
14
14
18
TLE
p02819
Python
Time Limit Exceeded
# ABC149C - Next Prime def is_prime(n: int) -> bool: """ Evaluate whether a number is prime or not. Args: n: a number to evaluate Returns: whether n is prime or not """ if n == 2: return True if n == 1 or n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def main(): N = int(input()) while not is_prime(N): N += 2 print(N) if __name__ == "__main__": main()
# ABC149C - Next Prime def is_prime(n: int) -> bool: """ Evaluate whether a number is prime or not. Args: n: a number to evaluate Returns: whether n is prime or not """ if n == 2: return True if n == 1 or n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def main(): N = int(input()) if N != 2 and N % 2 == 0: N += 1 while not is_prime(N): N += 2 print(N) if __name__ == "__main__": main()
insert
22
22
22
24
TLE
p02819
Python
Time Limit Exceeded
import math x = int(input()) primes = [] for n in range(2, 10000000000, 2): f = True mp = math.ceil(math.sqrt(n)) for p in primes: if p > mp: break if n % p == 0: f = False break if f: primes.append(n) if n >= x: print(n) exit(0)
import math x = int(input()) primes = [] if x == 2: print(2) exit(0) for n in range(3, 10000000000, 2): f = True mp = math.ceil(math.sqrt(n)) for p in primes: if p > mp: break if n % p == 0: f = False break if f: primes.append(n) if n >= x: print(n) exit(0)
replace
6
7
6
11
TLE
p02819
C++
Runtime Error
#include <cmath> #include <cstdlib> #include <iostream> #include <vector> using namespace std; using lli = long long int; int main() { int x; cin >> x; int m = min(x * x, 100010); vector<bool> p(m, true); p[0] = p[1] = false; for (int i = 2; i < (int)sqrt(m); i++) { if (p[i] == false) { continue; } for (int j = i * 2; j < m; j += i) { p[j] = false; } } for (int i = x; i < m; i++) { if (p[i]) { cout << i << endl; break; } } return 0; }
#include <cmath> #include <cstdlib> #include <iostream> #include <vector> using namespace std; using lli = long long int; int main() { int x; cin >> x; int m = 100010; vector<bool> p(m, true); p[0] = p[1] = false; for (int i = 2; i < (int)sqrt(m); i++) { if (p[i] == false) { continue; } for (int j = i * 2; j < m; j += i) { p[j] = false; } } for (int i = x; i < m; i++) { if (p[i]) { cout << i << endl; break; } } return 0; }
replace
10
11
10
11
0
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool is_prime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return false; } int main() { int n; cin >> n; while (!is_prime(n)) n++; cout << n; }
#include <bits/stdc++.h> using namespace std; bool is_prime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int main() { int n; cin >> n; while (!is_prime(n)) n++; cout << n; }
replace
9
10
9
10
TLE
p02819
C++
Runtime Error
// libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> // namespace using namespace std; using namespace __gnu_pbds; // typedef typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, greater<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long, long> pll; // define #define inp(X) cin >> X; #define inp_long(X) \ long long X; \ cin >> X; #define inp_arr(A, N) \ long long A[N]; \ for (long long int i = 0; i < N; i++) { \ cin >> A[i]; \ } #define sz(A) A.size() #define pb push_back #define pf push_front #define fi first #define se second // #define endl '\n' #define vect(A) vector<long long> A; #define inp_vect(A, N) \ ; \ vect(A); \ for (long long i = 0; i < N; i++) { \ long long q; \ cin >> q; \ A.push_back(q); \ } #define forin(i, a, b) for (long long i = a; i <= b; i++) #define forde(i, a, b) for (long long i = a; i >= b; i--) #define fio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const long long inf = (long long)1e18; const long long MOD = (long long)(1e9 + 7); ll z[100004] = {0}; ll power(ll x, ll y) { if (y == 0) return 1; ll p = power(x, y / 2) % MOD; p = (p * p) % MOD; return (y % 2 == 0) ? p : (x * p) % MOD; } ll modInverse(ll a) { return power(a, MOD - 2); } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen ("OUTPUT.txt" , "w" , stdout); #endif fio; forin(i, 2, 1e5) { ll d = 0; forin(j, 2, sqrt(i)) { if (i % j == 0) { d++; break; } } if (d) { z[i] = 0; } else { z[i] = 1; } } z[100003] = 1; ll n; cin >> n; forin(i, n, 100003) { if (z[i]) { cout << i << endl; break; } } }
// libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> // namespace using namespace std; using namespace __gnu_pbds; // typedef typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, greater<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long, long> pll; // define #define inp(X) cin >> X; #define inp_long(X) \ long long X; \ cin >> X; #define inp_arr(A, N) \ long long A[N]; \ for (long long int i = 0; i < N; i++) { \ cin >> A[i]; \ } #define sz(A) A.size() #define pb push_back #define pf push_front #define fi first #define se second // #define endl '\n' #define vect(A) vector<long long> A; #define inp_vect(A, N) \ ; \ vect(A); \ for (long long i = 0; i < N; i++) { \ long long q; \ cin >> q; \ A.push_back(q); \ } #define forin(i, a, b) for (long long i = a; i <= b; i++) #define forde(i, a, b) for (long long i = a; i >= b; i--) #define fio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const long long inf = (long long)1e18; const long long MOD = (long long)(1e9 + 7); ll z[100004] = {0}; ll power(ll x, ll y) { if (y == 0) return 1; ll p = power(x, y / 2) % MOD; p = (p * p) % MOD; return (y % 2 == 0) ? p : (x * p) % MOD; } ll modInverse(ll a) { return power(a, MOD - 2); } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } int main() { /* #ifndef ONLINE_JUDGE freopen ("input.txt" , "r" , stdin); // freopen ("OUTPUT.txt" , "w" , stdout); #endif */ fio; forin(i, 2, 1e5) { ll d = 0; forin(j, 2, sqrt(i)) { if (i % j == 0) { d++; break; } } if (d) { z[i] = 0; } else { z[i] = 1; } } z[100003] = 1; ll n; cin >> n; forin(i, n, 100003) { if (z[i]) { cout << i << endl; break; } } }
replace
75
79
75
80
0
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool isPrime(int x) { bool res = true; for (int i = 1; i * i <= x; i++) { if (x % i == 0) { res = false; break; } } return res; } int main() { int X; cin >> X; while (true) { if (isPrime(X)) { cout << X << endl; return 0; } X++; } }
#include <bits/stdc++.h> using namespace std; bool isPrime(int x) { bool res = true; for (int i = 2; i * i <= x; i++) { if (x % i == 0) { res = false; break; } } return res; } int main() { int X; cin >> X; while (true) { if (isPrime(X)) { cout << X << endl; return 0; } X++; } }
replace
5
6
5
6
TLE
p02819
C++
Runtime Error
#include <iostream> using namespace std; int const NMAX = 1e6; bool ciur[1 + NMAX]; int computeCiur() { for (long long i = 2; i * i <= NMAX; i++) { if (ciur[i] == 0) { for (long long j = i * i; j <= NMAX; j += i) { ciur[j] = 1; } } } } int main() { int n; cin >> n; computeCiur(); while (ciur[n] == 1) { n++; } cout << n; return 0; }
#include <iostream> using namespace std; int const NMAX = 1e6; bool ciur[1 + NMAX]; void computeCiur() { for (long long i = 2; i * i <= NMAX; i++) { if (ciur[i] == 0) { for (long long j = i * i; j <= NMAX; j += i) { ciur[j] = 1; } } } } int main() { int n; cin >> n; computeCiur(); while (ciur[n] == 1) { n++; } cout << n; return 0; }
replace
8
9
8
9
0
p02819
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define REP(i, n) \ for (long long(i) = 0, i_bound = (long long)(n); (i) < i_bound; ++i) #define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } const long long MOD = static_cast<long long>(1e9) + 7LL; const long long INF = 1234567891234567890LL; int main() { cin.tie(0); cout.sync_with_stdio(false); ll X; cin >> X; ll Y = X + 3000; vector<int> furui(Y, 1); for (int i = 2; i * i <= Y; i++) { if (!furui[i]) continue; for (int j = 2; i * j <= Y; j++) { furui[i * j] = 0; } } ll res = -1; for (int i = X; i <= Y; i++) { if (furui[i]) { res = i; break; } } cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define REP(i, n) \ for (long long(i) = 0, i_bound = (long long)(n); (i) < i_bound; ++i) #define FOR(i, a, b) for (long long(i) = (a); (i) < (b); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } const long long MOD = static_cast<long long>(1e9) + 7LL; const long long INF = 1234567891234567890LL; int main() { cin.tie(0); cout.sync_with_stdio(false); ll X; cin >> X; ll Y = X + 3000; vector<int> furui(Y + 10, 1); for (int i = 2; i * i <= Y; i++) { if (!furui[i]) continue; for (int j = 2; i * j <= Y; j++) { furui[i * j] = 0; } } ll res = -1; for (int i = X; i <= Y; i++) { if (furui[i]) { res = i; break; } } cout << res << endl; return 0; }
replace
51
52
51
52
0
p02819
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stdio.h> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int x; cin >> x; while (true) { bool fig = true; for (int i = 1; i <= sqrt(x); i++) { if (x % i == 0) fig = false; } if (fig) { cout << x << endl; return 0; } x++; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stdio.h> #include <string> #include <time.h> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int x; cin >> x; while (true) { bool fig = true; for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) fig = false; } if (fig) { cout << x << endl; return 0; } x++; } return 0; }
replace
19
20
19
20
TLE
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (i % 2 == 0) return false; } return true; } int32_t main() { int n; cin >> n; int p = n; while (!isPrime(p)) { p++; } cout << p << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int32_t main() { int n; cin >> n; int p = n; while (!isPrime(p)) { p++; } cout << p << endl; return 0; }
replace
8
9
8
9
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define SORTR(v) sort((v).rbegin(), (v).rend()) #define all(v) (v).begin(), (v).end() #define vmax 10000 constexpr ll inf = 100000000000000; /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ // 最大公約数 ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // 最小公倍数 ll lcm(ll a, ll b) { return a * b / gcd(a, b); } // 素因数分解 map<int, int> prime_factor(int n, map<int, int> &res) { for (int i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) { if (res[n] == 0) { res[n] = 1; } else { res[n]++; } } return res; } // 約数列挙 vector<ll> divisor(ll n) { vector<ll> a; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { a.push_back(i); if (i * i != n) { a.push_back(n / i); } } } SORT(a); return a; } // 拡張ユークリッドの互除法 int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } else { int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } } // 素数判定 void sieve(int n, vector<bool> &is_prime) { is_prime[0] = false; is_prime[1] = false; for (int i = 2; i * i <= n; i++) { if (is_prime[i]) { for (int j = i * i; j <= n; j += i) is_prime[j] = false; } } return; } // 繰り返し2乗法 ll mod_pow(ll x, ll n, ll mod) { x %= mod; ll res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } // mod m での a の逆元 int mod_inverse(int a, int m) { int x, y; extgcd(a, m, x, y); return (m + x % m) % m; } // nCkの前計算 void init(ll n, ll m, vector<ll> &factrial, vector<ll> &inverse) { factrial.resize(n + 1); inverse.resize(n + 1); factrial[0] = 1; inverse[0] = 1; for (ll i = 1; i <= n; i++) { factrial[i] = factrial[i - 1] * i % m; inverse[i] = mod_inverse(factrial[i], m); } } // nCk ll nCk(ll n, ll k, ll m, vector<ll> &factrial, vector<ll> &inverse) { if (n < 0 || k < 0 || n < k) { return 0; } return factrial[n] * inverse[k] % m * inverse[n - k] % m; } int main() { int n; cin >> n; vector<bool> a(1e6, true); sieve(1e6 + 3, a); for (int i = n; i < 1e6 + 3; i++) { if (a[i]) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define SORTR(v) sort((v).rbegin(), (v).rend()) #define all(v) (v).begin(), (v).end() #define vmax 10000 constexpr ll inf = 100000000000000; /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ // 最大公約数 ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // 最小公倍数 ll lcm(ll a, ll b) { return a * b / gcd(a, b); } // 素因数分解 map<int, int> prime_factor(int n, map<int, int> &res) { for (int i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) { if (res[n] == 0) { res[n] = 1; } else { res[n]++; } } return res; } // 約数列挙 vector<ll> divisor(ll n) { vector<ll> a; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { a.push_back(i); if (i * i != n) { a.push_back(n / i); } } } SORT(a); return a; } // 拡張ユークリッドの互除法 int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } else { int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } } // 素数判定 void sieve(int n, vector<bool> &is_prime) { is_prime[0] = false; is_prime[1] = false; for (int i = 2; i * i <= n; i++) { if (is_prime[i]) { for (int j = i * i; j <= n; j += i) is_prime[j] = false; } } return; } // 繰り返し2乗法 ll mod_pow(ll x, ll n, ll mod) { x %= mod; ll res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } // mod m での a の逆元 int mod_inverse(int a, int m) { int x, y; extgcd(a, m, x, y); return (m + x % m) % m; } // nCkの前計算 void init(ll n, ll m, vector<ll> &factrial, vector<ll> &inverse) { factrial.resize(n + 1); inverse.resize(n + 1); factrial[0] = 1; inverse[0] = 1; for (ll i = 1; i <= n; i++) { factrial[i] = factrial[i - 1] * i % m; inverse[i] = mod_inverse(factrial[i], m); } } // nCk ll nCk(ll n, ll k, ll m, vector<ll> &factrial, vector<ll> &inverse) { if (n < 0 || k < 0 || n < k) { return 0; } return factrial[n] * inverse[k] % m * inverse[n - k] % m; } int main() { int n; cin >> n; vector<bool> a(1e6 + 10, true); sieve(1e6 + 3, a); for (int i = n; i < 1e6 + 3; i++) { if (a[i]) { cout << i << endl; return 0; } } }
replace
129
130
129
130
0
p02819
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x; cin >> x; while (1) { bool ok = true; for (int i = 2; i < x; ++i) { if (x % 1 == 0) { ok = false; break; } } if (ok) break; ++x; } cout << x << endl; return 0; }
#include <iostream> using namespace std; int main() { int x; cin >> x; while (1) { bool ok = true; for (int i = 2; i < x; ++i) { if (x % i == 0) { ok = false; break; } } if (ok) break; ++x; } cout << x << endl; return 0; }
replace
10
11
10
11
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define countof(array) (sizeof(array) / sizeof(array[0])) #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rep2(i, n) for (int i = 1; i <= (n); ++i) #define rrep2(i, n) for (int i = (n); i > 0; --i) #define srep(i, s, n) for (int i = s; i < (n); ++i) #define rsrep(i, s, n) for (int i = (n)-1; i >= s; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define aall(a) (a), (a) + countof(a) // for array sorting #define raall(a) (a), (a) + countof(a), greater<>() #define show(x) cout << #x << " = " << (x) << endl; #define vfind(v, a) find(all(v), a) != v.end() #define yn(f) \ { \ if (f) \ puts("YES"); \ else \ puts("NO"); \ } #define yns(f) \ { \ if (f) \ puts("Yes"); \ else \ puts("No"); \ } #define show_ary(...) \ { \ cout << #__VA_ARGS__ << " = "; \ for (const auto &x : (__VA_ARGS__)) { \ cout << x << " "; \ } \ cout << endl; \ } #define show_pair(...) \ cout << #__VA_ARGS__ << " = " << endl; \ for (const auto &x : (__VA_ARGS__)) { \ cout << " " << x.fi << " : " << x.se << endl; \ } #define out_ary(...) \ { \ int n = (__VA_ARGS__).size(); \ rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n - 1 ? " " : "\n"); \ } #define argmax(v) distance((v).begin(), max_element(all(v))) #define argmin(v) distance((v).begin(), min_element(all(v))) #define vmax(v) *max_element(all(v)) #define vmin(v) *min_element(all(v)) typedef long long int ll; typedef pair<int, int> P; typedef vector<P> vpair; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<string> vstr; typedef vector<bool> vbool; typedef vector<vint> vvint; typedef vector<vll> vvll; typedef vector<vstr> vvstr; typedef vector<vbool> vvbool; const ll LINF = 2000000000000000000ll; const int INF = 1000000100; const ll MOD = 1e9 + 7; const int MAX = 200000; vll prime(ll n) { vll ans; vbool ls(n, true); ls[0] = false; ls[1] = false; srep(i, 2, n + 1) { if (ls[i]) { ans.push_back(i); ll j = i * 2; while (j <= n) { ls[j] = false; j += i; } } } return ans; } int main() { int x; cin >> x; vll ls = prime(MAX); for (auto p : ls) { if (p >= x) { cout << p << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define countof(array) (sizeof(array) / sizeof(array[0])) #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rep2(i, n) for (int i = 1; i <= (n); ++i) #define rrep2(i, n) for (int i = (n); i > 0; --i) #define srep(i, s, n) for (int i = s; i < (n); ++i) #define rsrep(i, s, n) for (int i = (n)-1; i >= s; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define aall(a) (a), (a) + countof(a) // for array sorting #define raall(a) (a), (a) + countof(a), greater<>() #define show(x) cout << #x << " = " << (x) << endl; #define vfind(v, a) find(all(v), a) != v.end() #define yn(f) \ { \ if (f) \ puts("YES"); \ else \ puts("NO"); \ } #define yns(f) \ { \ if (f) \ puts("Yes"); \ else \ puts("No"); \ } #define show_ary(...) \ { \ cout << #__VA_ARGS__ << " = "; \ for (const auto &x : (__VA_ARGS__)) { \ cout << x << " "; \ } \ cout << endl; \ } #define show_pair(...) \ cout << #__VA_ARGS__ << " = " << endl; \ for (const auto &x : (__VA_ARGS__)) { \ cout << " " << x.fi << " : " << x.se << endl; \ } #define out_ary(...) \ { \ int n = (__VA_ARGS__).size(); \ rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n - 1 ? " " : "\n"); \ } #define argmax(v) distance((v).begin(), max_element(all(v))) #define argmin(v) distance((v).begin(), min_element(all(v))) #define vmax(v) *max_element(all(v)) #define vmin(v) *min_element(all(v)) typedef long long int ll; typedef pair<int, int> P; typedef vector<P> vpair; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<string> vstr; typedef vector<bool> vbool; typedef vector<vint> vvint; typedef vector<vll> vvll; typedef vector<vstr> vvstr; typedef vector<vbool> vvbool; const ll LINF = 2000000000000000000ll; const int INF = 1000000100; const ll MOD = 1e9 + 7; const int MAX = 200000; vll prime(ll n) { vll ans; vbool ls(n + 1, true); ls[0] = false; ls[1] = false; srep(i, 2, n + 1) { if (ls[i]) { ans.push_back(i); ll j = i * 2; while (j <= n) { ls[j] = false; j += i; } } } return ans; } int main() { int x; cin >> x; vll ls = prime(MAX); for (auto p : ls) { if (p >= x) { cout << p << endl; return 0; } } return 0; }
replace
73
74
73
74
-6
double free or corruption (!prev)
p02819
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define rep(i, n) for (long long i = 0; (i) < (n); (i)++) using namespace std; using ll = long long; const ll mod = 1000000007; int main() { ll N; cin >> N; if (N == 2) { cout << 2 << endl; return 0; } vector<ll> prime; prime.push_back(2); for (int i = 3; i <= 100003; i++) { bool flag = true; for (auto k : prime) { if (i % k == 0) flag = false; } if (flag) { if (i >= N) { cout << i << endl; return 0; } prime.push_back(i); } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define rep(i, n) for (long long i = 0; (i) < (n); (i)++) using namespace std; using ll = long long; const ll mod = 1000000007; int main() { ll N; cin >> N; if (N == 2) { cout << 2 << endl; return 0; } vector<ll> prime; prime.push_back(2); for (int i = 3; i <= 100003; i++) { bool flag = true; for (auto k : prime) { if (k * k > i) break; if (i % k == 0) flag = false; } if (flag) { if (i >= N) { cout << i << endl; return 0; } prime.push_back(i); } } return 0; }
insert
26
26
26
28
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define sz(x) (int)(x).size() typedef vector<int> vi; // #define ll long long #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 = 1e9 + 7; 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 = 2 * 1e5 + 2; bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("out10.txt","w",stdout); #endif int x; cin >> x; for (int i = x;; i++) { if (prime(i)) { cout << i; return 0; } } } // I never lose. I either win or I learn
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define sz(x) (int)(x).size() typedef vector<int> vi; // #define ll long long #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 = 1e9 + 7; 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 = 2 * 1e5 + 2; bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int x; cin >> x; for (int i = x;; i++) { if (prime(i)) { cout << i; return 0; } } } // I never lose. I either win or I learn
replace
37
41
37
38
0
p02819
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; 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; } const int inf = 1001001001; 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; } } s(100000); int main() { int x; cin >> x; while (true) { if (s.isPrime(x)) { cout << x << endl; return 0; } x++; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; 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; } const int inf = 1001001001; 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; } } s(200000); int main() { int x; cin >> x; while (true) { if (s.isPrime(x)) { cout << x << endl; return 0; } x++; } }
replace
65
66
65
66
0
p02819
C++
Runtime Error
#include <bits/stdc++.h> #define PI 3.1415926535897932 #define MOD 1000000007 #define INF 1e9 #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; void solve() { ll X; cin >> X; ll MAX = 1000000; vb isPrime(MAX); fill(ALL(isPrime), true); isPrime[0] = isPrime[1] = false; for (ll i = 2; i * i <= MAX; i++) { if (isPrime[i]) { for (ll j = i * 2; j <= MAX; j += i) { isPrime[j] = false; } } } for (ll i = X; i <= MAX; i++) { if (isPrime[i]) { cout << i << endl; return; } } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); solve(); return 0; }
#include <bits/stdc++.h> #define PI 3.1415926535897932 #define MOD 1000000007 #define INF 1e9 #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; void solve() { ll X; cin >> X; ll MAX = 1000000; vb isPrime(MAX + 1); fill(ALL(isPrime), true); isPrime[0] = isPrime[1] = false; for (ll i = 2; i * i <= MAX; i++) { if (isPrime[i]) { for (ll j = i * 2; j <= MAX; j += i) { isPrime[j] = false; } } } for (ll i = X; i <= MAX; i++) { if (isPrime[i]) { cout << i << endl; return; } } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); solve(); return 0; }
replace
25
26
25
26
-6
double free or corruption (!prev)
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAX_N = 120000; vector<bool> IsPrime(MAX_N, true); void sieve() { IsPrime[0] = false; IsPrime[1] = false; for (int i = 2; i * i <= MAX_N; i++) { if (IsPrime[i]) { for (int j = 2; i * j <= MAX_N; j++) { IsPrime[i * j] = false; } } } } int main() { int x; cin >> x; int ans = 0; sieve(); for (int i = 2; i <= MAX_N; i++) { if (IsPrime[i] && i >= x) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 101010; vector<bool> IsPrime(MAX_N, true); void sieve() { IsPrime[0] = false; IsPrime[1] = false; for (int i = 2; i * i <= MAX_N; i++) { if (IsPrime[i]) { for (int j = 2; i * j <= MAX_N; j++) { IsPrime[i * j] = false; } } } } int main() { int x; cin >> x; int ans = 0; sieve(); for (int i = 2; i <= MAX_N; i++) { if (IsPrime[i] && i >= x) { ans = i; break; } } cout << ans << endl; }
replace
3
4
3
4
-6
double free or corruption (!prev)
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> #include <string> #define UB upper_bound #define LB lower_bound #define BS binary_search #define IN insert #define PB push_back #define EB emplace_back #define MP make_pair #define NL cout << endl #define ll long long int #define ld long double #define vl vector<ll> #define sl set<ll> #define ml map<ll, ll> #define sc set<char> #define li list<ll> #define vp vector<pair<ll, ll>> #define vs vector<string> #define ss set<string> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPI(i, a, b) for (ll i = b - 1; i >= a; i--) #define REPIT(it, a) for (auto it = a.begin(); it != a.end(); it++) #define N (ll) pow(2, 32) - 1 #define mod (ll)1000000007 using namespace std; vl p; vl sieve(ll m) { vl f; REP(i, 1, sqrt(m) + 1) { if (m % i == 0) { f.PB(i); if (m / i != i) f.PB(m / i); } } return f; } void fill(ll n) { p.PB(2); p.PB(3); p.PB(5); p.PB(7); REP(i, 11, n) { vl v = sieve(i); if (v.size() == 2) p.PB(i); } } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t = 1; // cin>>t; while (t--) { p.clear(); fill(1000000ll); ll n; cin >> n; auto it = LB(p.begin(), p.end(), n); cout << *it << endl; } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> #define UB upper_bound #define LB lower_bound #define BS binary_search #define IN insert #define PB push_back #define EB emplace_back #define MP make_pair #define NL cout << endl #define ll long long int #define ld long double #define vl vector<ll> #define sl set<ll> #define ml map<ll, ll> #define sc set<char> #define li list<ll> #define vp vector<pair<ll, ll>> #define vs vector<string> #define ss set<string> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPI(i, a, b) for (ll i = b - 1; i >= a; i--) #define REPIT(it, a) for (auto it = a.begin(); it != a.end(); it++) #define N (ll) pow(2, 32) - 1 #define mod (ll)1000000007 using namespace std; vl p; vl sieve(ll m) { vl f; REP(i, 1, sqrt(m) + 1) { if (m % i == 0) { f.PB(i); if (m / i != i) f.PB(m / i); } } return f; } void fill(ll n) { p.PB(2); p.PB(3); p.PB(5); p.PB(7); REP(i, 11, n) { vl v = sieve(i); if (v.size() == 2) p.PB(i); } } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t = 1; // cin>>t; while (t--) { p.clear(); fill(150000ll); ll n; cin >> n; auto it = LB(p.begin(), p.end(), n); cout << *it << endl; } return 0; }
replace
58
59
58
59
TLE
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n; cin >> n; vector<ll> so; for (ll i = 2;; i++) { bool ch = true; for (auto itr = so.begin(); itr != so.end(); itr++) { if (i % *itr == 0) { ch = false; } } if (ch) { if (i >= n) { cout << i << endl; return 0; } so.push_back(i); } } // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n; cin >> n; vector<ll> so; for (ll i = 2;; i++) { bool ch = true; for (auto itr = so.begin(); itr != so.end(); itr++) { if (i % *itr == 0) { ch = false; } if (*itr > sqrt(i)) { break; } } if (ch) { if (i >= n) { cout << i << endl; return 0; } so.push_back(i); } } // your code goes here return 0; }
insert
16
16
16
19
TLE
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int X; cin >> X; bool prime = true; int count = 0; // 約数の数 if (X == 2) { cout << 2 << endl; } else { while (prime) { for (int j = 2; j * j <= X; j++) { if (X % j == 0) { count++; break; } } // j if (count == 0) { prime = false; } X += 1; } // while cout << X - 1 << endl; } // else }
#include <bits/stdc++.h> using namespace std; int main() { int X; cin >> X; bool prime = true; int count = 0; // 約数の数 if (X == 2) { cout << 2 << endl; } else { while (prime) { count = 0; for (int j = 2; j * j <= X; j++) { if (X % j == 0) { count++; break; } } // j if (count == 0) { prime = false; } X += 1; } // while cout << X - 1 << endl; } // else }
insert
11
11
11
12
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) using ll = long long; using namespace std; ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } vector<bool> isprime(2 * 1e5, true); int main() { ll x; cin >> x; isprime[0] = false; isprime[1] = false; for (ll i = 2; pow(i, 2) <= 2 * x; i++) { if (isprime[i]) { for (ll j = 2; i * j <= 2 * x; j++) isprime[i * j] = false; } } rep(i, x + x) { if (isprime[i] && i >= x) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) using ll = long long; using namespace std; ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } vector<bool> isprime(1e6, true); int main() { ll x; cin >> x; isprime[0] = false; isprime[1] = false; for (ll i = 2; pow(i, 2) <= 2 * x; i++) { if (isprime[i]) { for (ll j = 2; i * j <= 2 * x; j++) isprime[i * j] = false; } } rep(i, x + x) { if (isprime[i] && i >= x) { cout << i << endl; return 0; } } }
replace
5
6
5
6
0
p02819
C++
Runtime Error
// define DEBUG for debug #define DEBUG #include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define MAX 100000 + 100 #define MOD 1000000007 typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int asallar[100000], asalsay = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef DEBUG freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); #endif ll x; cin >> x; for (ll i = 2; i < 100004; i++) { bool asal = true; for (ll a = 0; a < asalsay; a++) { if (i % asallar[a] == 0) { asal = false; break; } } if (asal) { if (i >= x) { cout << i; return 0; } asallar[asalsay] = i; asalsay++; } } return 0; }
// define DEBUG for debug // #define DEBUG #include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define MAX 100000 + 100 #define MOD 1000000007 typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int asallar[100000], asalsay = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef DEBUG freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); #endif ll x; cin >> x; for (ll i = 2; i < 100004; i++) { bool asal = true; for (ll a = 0; a < asalsay; a++) { if (i % asallar[a] == 0) { asal = false; break; } } if (asal) { if (i >= x) { cout << i; return 0; } asallar[asalsay] = i; asalsay++; } } return 0; }
replace
1
2
1
2
0
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a == 0) { cout << 1; } else if (a == 1) { cout << 2; } else { for (long long i = 2; i <= a * a; i++) { long long flag = 1; for (long long j = 2; j <= i / 2; ++j) { if (i % j == 0) { flag = 0; break; } } if (flag && i >= a) { cout << i; break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a == 0) { cout << 1; } else if (a == 1) { cout << 2; } else { for (long long i = a; i <= a * a; i++) { long long flag = 1; for (long long j = 2; j <= i / 2; ++j) { if (i % j == 0) { flag = 0; break; } } if (flag && i >= a) { cout << i; break; } } } return 0; }
replace
12
13
12
13
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<bool> isp; int N; void sieve() { isp[0] = false; isp[1] = false; for (int i = 2; pow(i, 2) <= N; i++) { if (isp[i]) for (int j = 2; i * j <= N; j++) isp[i * j] = false; } } void solve(long long X) { N = X; isp = vector<bool>(N + 1, true); for (int i = 0; i < 100; i++) { sieve(); if (isp[N]) { cout << N << endl; break; } N++; } } // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { long long X; scanf("%lld", &X); solve(X); return 0; }
#include <bits/stdc++.h> using namespace std; vector<bool> isp; int N; void sieve() { isp[0] = false; isp[1] = false; for (int i = 2; pow(i, 2) <= N; i++) { if (isp[i]) for (int j = 2; i * j <= N; j++) isp[i * j] = false; } } void solve(long long X) { N = X; isp = vector<bool>(N + 100, true); for (int i = 0; i < 100; i++) { sieve(); if (isp[N]) { cout << N << endl; break; } N++; } } // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { long long X; scanf("%lld", &X); solve(X); return 0; }
replace
18
19
18
19
0
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int X; cin >> X; for (;;) { for (int i = X - 1; 1 <= i; i--) { if (X % i == 0) { continue; ; } if (i == 1) { cout << X << endl; return 0; ; } } X++; } }
#include <bits/stdc++.h> using namespace std; int main() { int X; cin >> X; for (;;) { for (int i = X - 1; 1 <= i; i--) { if (X % i == 0 && (!(i == 1))) { break; ; } if (i == 1) { cout << X << endl; return 0; ; } } X++; } }
replace
8
10
8
10
TLE
p02819
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using vpii = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvs = vector<vector<string>>; using pii = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rreps(i, n) for (int i = (int)(n); i > 0; i--) #define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define RFOR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) #define all(x) (x).begin(), (x).end() #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) 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 INF = INT_MAX; const int MOD = 1000000007; bool is_prime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } int main() { int n; cin >> n; int i = n; while (true) { if (is_prime(n)) break; else i++; } cout << i << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using vpii = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvs = vector<vector<string>>; using pii = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rreps(i, n) for (int i = (int)(n); i > 0; i--) #define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define RFOR(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) #define all(x) (x).begin(), (x).end() #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) 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 INF = INT_MAX; const int MOD = 1000000007; bool is_prime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } int main() { int n; cin >> n; int i = n; while (!is_prime(i)) i++; cout << i << endl; }
replace
57
63
57
59
TLE
p02819
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> vector<T> read(vector<T> &v, int n) { v.resize(n); for (auto &x : v) cin >> x; } template <typename T> void trav(vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { cout << v[i]; if (i != (int)v.size() - 1) cout << ' '; } } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int lg2(int x) { return 32 - __builtin_clzll(x) - 1; } struct pair_hash { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto h1 = hash<T1>{}(p.first); auto h2 = hash<T2>{}(p.second); return h1 ^ h2; } }; int x; bool prime[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); set<int> pr; memset(prime, true, sizeof prime); prime[2] = true; for (int i = 2; i <= MAXN; ++i) { if (prime[i]) { pr.insert(i); for (int j = 2 * i; j <= MAXN; j += i) { prime[j] = false; } } } int x; cin >> x; cout << *pr.lower_bound(x) << endl; return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> vector<T> read(vector<T> &v, int n) { v.resize(n); for (auto &x : v) cin >> x; } template <typename T> void trav(vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { cout << v[i]; if (i != (int)v.size() - 1) cout << ' '; } } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int lg2(int x) { return 32 - __builtin_clzll(x) - 1; } struct pair_hash { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto h1 = hash<T1>{}(p.first); auto h2 = hash<T2>{}(p.second); return h1 ^ h2; } }; int x; bool prime[MAXN + 1]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); set<int> pr; memset(prime, true, sizeof prime); prime[2] = true; for (int i = 2; i <= MAXN; ++i) { if (prime[i]) { pr.insert(i); for (int j = 2 * i; j <= MAXN; j += i) { prime[j] = false; } } } int x; cin >> x; cout << *pr.lower_bound(x) << endl; return 0; }
replace
65
66
65
66
0
p02819
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stdlib.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; const int N = 1000000; vector<bool> isp(N, true); void sieve() { isp[0] = false; isp[1] = false; for (auto i = 0; i <= N; i++) { if (isp[i]) { for (auto j = 2; i * j <= N; j++) isp[i * j] = false; } } } int main() { sieve(); ll k; cin >> k; for (auto i = k; i <= N; i++) { if (isp[i]) { cout << i << endl; return 0; } } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stdlib.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; const int N = 100003 + 1; vector<bool> isp(N, true); void sieve() { isp[0] = false; isp[1] = false; for (auto i = 0; i <= N; i++) { if (isp[i]) { for (auto j = 2; i * j <= N; j++) isp[i * j] = false; } } } int main() { sieve(); ll k; cin >> k; for (auto i = k; i <= N; i++) { if (isp[i]) { cout << i << endl; return 0; } } return 0; }
replace
13
14
13
14
0
p02819
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define pb push_back #define f first #define s second #define MOD 1000000007 using namespace std; bool prime[200001]; void solve() { ll x; cin >> x; for (int i = 2; i < 200001; i++) { if (!prime[i]) { for (int j = i; i * j <= 200000; j++) { prime[j * i] = 1; } } } for (int i = 2; i <= 200000; i++) { if (prime[i] == 0 && i >= x) { cout << i; break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // cout<<fixed<<setprecision(12); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define pb push_back #define f first #define s second #define MOD 1000000007 using namespace std; bool prime[200001]; void solve() { ll x; cin >> x; for (int i = 2; i < 200001; i++) { if (!prime[i] && (ll)i * i <= 200001) { for (int j = i; i * j <= 200000; j++) { prime[j * i] = 1; } } } for (int i = 2; i <= 200000; i++) { if (prime[i] == 0 && i >= x) { cout << i; break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // cout<<fixed<<setprecision(12); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); cout << "\n"; } return 0; }
replace
17
18
17
18
-11
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX typedef long long ll; using namespace std; ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(a, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } int r, p, s; int point(char c) { int add = 0; if (c == 'r') add = p; if (c == 'p') add = s; if (c == 's') add = r; if (c == 'n') add = 0; return add; } int main() { int n, k; cin >> n >> k >> r >> s >> p; string t; cin >> t; ll ans = 0; for (int i = 0; i < n - k; i++) { for (int j = 1; k * j + i < n; j++) { if (t.at(i + k * (j - 1)) == t.at(i + k * j)) t.at(i + j * k) = 'n'; } } rep(i, n) { ans += point(t.at(i)); } cout << ans << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX typedef long long ll; using namespace std; ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(a, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } int r, p, s; int point(char c) { int add = 0; if (c == 'r') add = p; if (c == 'p') add = s; if (c == 's') add = r; if (c == 'n') add = 0; return add; } int main() { int n, k; cin >> n >> k >> r >> s >> p; string t; cin >> t; ll ans = 0; for (int i = k; i < n; i++) { if (t.at(i - k) == t.at(i)) t.at(i) = 'n'; } rep(i, n) { ans += point(t.at(i)); } cout << ans << endl; }
replace
43
48
43
46
TLE
p02820
C++
Runtime Error
#include <bitset> #include <iostream> #define REP(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; string T; cin >> T; bitset<11000> win; REP(i, N) if (i < K || T[i - K] != T[i] || !win[i - K]) win[i] = true; ll ans = 0; REP(i, N) if (win[i]) { if (T[i] == 's') ans += R; if (T[i] == 'p') ans += S; if (T[i] == 'r') ans += P; } cout << ans << endl; return 0; }
#include <bitset> #include <iostream> #define REP(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; string T; cin >> T; bitset<110000> win; REP(i, N) if (i < K || T[i - K] != T[i] || !win[i - K]) win[i] = true; ll ans = 0; REP(i, N) if (win[i]) { if (T[i] == 's') ans += R; if (T[i] == 'p') ans += S; if (T[i] == 'r') ans += P; } cout << ans << endl; return 0; }
replace
11
12
11
12
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; vector<char> tt(n); rep(i, n) { if (t[i] == 'r') tt[i] = 'p'; if (t[i] == 's') tt[i] = 'r'; if (t[i] == 'p') tt[i] = 's'; } ll sum = 0; rep(i, n) { if (tt[i - k] == tt[i] && i - k >= 0) { tt[i] = -1; continue; } if (tt[i] == 'r') sum += r; if (tt[i] == 's') sum += s; if (tt[i] == 'p') sum += p; } cout << sum << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; vector<char> tt(n); rep(i, n) { if (t[i] == 'r') tt[i] = 'p'; if (t[i] == 's') tt[i] = 'r'; if (t[i] == 'p') tt[i] = 's'; } ll sum = 0; rep(i, n) { if (i - k >= 0) { if (tt[i - k] == tt[i]) { tt[i] = -1; continue; } } if (tt[i] == 'r') sum += r; if (tt[i] == 's') sum += s; if (tt[i] == 'p') sum += p; } cout << sum << endl; }
replace
38
41
38
43
0
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T &value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T &value, const Ts &...args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; ll n, k; string hand = "rsp"; map<char, ll> score; ll dp[100001][3]; ll Score(char t, char m) { if (t == m) { return 0; } if (t == 'r' && m == 's' || t == 's' && m == 'p' || t == 'p' && m == 'r') { return score[t]; } return 0; } ll solve(const string &t) { dbg(t); rep(i, 100001) rep(j, 3) dp[i][j] = 0; rep(i, t.size()) { rep(j, 3) { ll d = 0; rep(k, 3) { if (k != j) { d = max(d, dp[i][k]); } } dp[i + 1][j] = d + Score(hand[j], t[i]); dbg(i, j, hand[j], t[i], dp[i + 1][j]); } } ll ret = 0; rep(i, 3) ret = max(ret, dp[t.size()][i]); dbg(ret); return ret; } int main() { cin >> n >> k; rep(i, 3) cin >> score[hand[i]]; in(string, t); vector<string> ts(k); rep(i, t.size()) { ts[i % k] += t[i]; } ll ans = 0; rep(i, k) { ans += solve(ts[i]); } out(ans); }
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T &value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T &value, const Ts &...args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; ll n, k; string hand = "rsp"; map<char, ll> score; ll dp[100001][3]; ll Score(char t, char m) { if (t == m) { return 0; } if (t == 'r' && m == 's' || t == 's' && m == 'p' || t == 'p' && m == 'r') { return score[t]; } return 0; } ll solve(const string &t) { dbg(t); rep(i, 3) dp[0][i] = 0; rep(i, t.size()) { rep(j, 3) { ll d = 0; rep(k, 3) { if (k != j) { d = max(d, dp[i][k]); } } dp[i + 1][j] = d + Score(hand[j], t[i]); dbg(i, j, hand[j], t[i], dp[i + 1][j]); } } ll ret = 0; rep(i, 3) ret = max(ret, dp[t.size()][i]); dbg(ret); return ret; } int main() { cin >> n >> k; rep(i, 3) cin >> score[hand[i]]; in(string, t); vector<string> ts(k); rep(i, t.size()) { ts[i % k] += t[i]; } ll ans = 0; rep(i, k) { ans += solve(ts[i]); } out(ans); }
replace
63
64
63
64
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define itn int #define rep(i, n) for (int i = 0; i < n; i++) #define P pair<int, int> long long dp[100000][4]; int main(void) { string t; int n, k, r, s, p; cin >> n >> k >> r >> s >> p >> t; // r = 0,s = 1,p = 2 for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { if (j != 0) dp[i + k][j] = max(dp[i + k][j], dp[i][0]); if (j != 1) dp[i + k][j] = max(dp[i + k][j], dp[i][1]); if (j != 2) dp[i + k][j] = max(dp[i + k][j], dp[i][2]); } if (t[i] == 'r') dp[i + k][2] += p; if (t[i] == 's') dp[i + k][0] += r; if (t[i] == 'p') dp[i + k][1] += s; } long long ans = 0; for (int i = n; i < n + k; i++) { ans += max(dp[i][0], max(dp[i][1], dp[i][2])); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define itn int #define rep(i, n) for (int i = 0; i < n; i++) #define P pair<int, int> long long dp[200000][4]; int main(void) { string t; int n, k, r, s, p; cin >> n >> k >> r >> s >> p >> t; // r = 0,s = 1,p = 2 for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { if (j != 0) dp[i + k][j] = max(dp[i + k][j], dp[i][0]); if (j != 1) dp[i + k][j] = max(dp[i + k][j], dp[i][1]); if (j != 2) dp[i + k][j] = max(dp[i + k][j], dp[i][2]); } if (t[i] == 'r') dp[i + k][2] += p; if (t[i] == 's') dp[i + k][0] += r; if (t[i] == 'p') dp[i + k][1] += s; } long long ans = 0; for (int i = n; i < n + k; i++) { ans += max(dp[i][0], max(dp[i][1], dp[i][2])); } cout << ans << endl; }
replace
7
8
7
8
0
p02820
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; char win(char s) { switch (s) { case 'r': return 'p'; case 's': return 'r'; case 'p': return 's'; default: return 'q'; } } int main(void) { int n, k, r, s, p; char t[10000]; cin >> n >> k >> r >> s >> p; for (int i = 0; i < n; ++i) { cin >> t[i]; } ll score = 0; for (int i = 0; i < n; ++i) { switch (win(t[i])) { case 'r': if (i < k || t[i] != t[i - k]) { score += r; } else { t[i] = 'q'; } break; case 's': if (i < k || t[i] != t[i - k]) { score += s; } else { t[i] = 'q'; } break; case 'p': if (i < k || t[i] != t[i - k]) { score += p; } else { t[i] = 'q'; } break; } } cout << score; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; char win(char s) { switch (s) { case 'r': return 'p'; case 's': return 'r'; case 'p': return 's'; default: return 'q'; } } int main(void) { int n, k, r, s, p; char t[100000]; cin >> n >> k >> r >> s >> p; for (int i = 0; i < n; ++i) { cin >> t[i]; } ll score = 0; for (int i = 0; i < n; ++i) { switch (win(t[i])) { case 'r': if (i < k || t[i] != t[i - k]) { score += r; } else { t[i] = 'q'; } break; case 's': if (i < k || t[i] != t[i - k]) { score += s; } else { t[i] = 'q'; } break; case 'p': if (i < k || t[i] != t[i - k]) { score += p; } else { t[i] = 'q'; } break; } } cout << score; }
replace
19
20
19
20
0
p02820
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, k; int r, s, p; cin >> n >> k; cin >> r >> s >> p; char T[n + 1]; cin >> T; int i, ans; ans = 0; for (i = 0; i <= n; i++) { if (i - k + 1 > 0 and T[i] == T[i - k]) { if (T[i] == T[i + k] and T[i + k] == 'r') T[i] = 's'; else if (T[i] == T[i + k] and T[i + k] == 's') T[i] = 'p'; else if (T[i] == T[i + k] and T[i + k] == 'p') T[i] = 'r'; } else { if (T[i] == 'r') ans = ans + p; else if (T[i] == 's') ans = ans + r; else if (T[i] == 'p') ans = ans + s; } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int n, k; int r, s, p; cin >> n >> k; cin >> r >> s >> p; char T[n + 1 + k]; cin >> T; int i, ans; ans = 0; for (i = 0; i <= n; i++) { if (i - k + 1 > 0 and T[i] == T[i - k]) { if (T[i] == T[i + k] and T[i + k] == 'r') T[i] = 's'; else if (T[i] == T[i + k] and T[i + k] == 's') T[i] = 'p'; else if (T[i] == T[i + k] and T[i + k] == 'p') T[i] = 'r'; } else { if (T[i] == 'r') ans = ans + p; else if (T[i] == 's') ans = ans + r; else if (T[i] == 'p') ans = ans + s; } } cout << ans << endl; }
replace
9
10
9
10
0
p02820
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; #define mp make_pair #define f first #define s second #define pb push_back const int N = 1e5 + 5; const int M = 1e6 + 5; const int Q = 2e5 + 5; const int OO = 1e9; const int mod = 1e9 + 7; int n, k, cur[4], r[N], s[N], p[N], ans, dp[N][4]; string t; int solve(int idx, int col) { if (idx >= n) return 0; int &ret = dp[idx][col]; ret = 0; for (int i = 1; i <= 3; ++i) { bool ok = 0; if (i == 1 && t[idx] == 's') ok = 1; if (i == 2 && t[idx] == 'p') ok = 1; if (i == 3 && t[idx] == 'r') ok = 1; if (i == 0) ok = 1; if (col != i) ret = max(ret, (ok ? cur[i] : 0) + solve(idx + k, i)); } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> cur[1] >> cur[2] >> cur[3] >> t; memset(dp, -1, sizeof(dp)); for (int i = 0; i < k; ++i) ans += solve(i, 0); cout << ans << '\n'; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; #define mp make_pair #define f first #define s second #define pb push_back const int N = 1e5 + 5; const int M = 1e6 + 5; const int Q = 2e5 + 5; const int OO = 1e9; const int mod = 1e9 + 7; int n, k, cur[4], r[N], s[N], p[N], ans, dp[N][4]; string t; int solve(int idx, int col) { if (idx >= n) return 0; int &ret = dp[idx][col]; if (~ret) return ret; ret = 0; for (int i = 1; i <= 3; ++i) { bool ok = 0; if (i == 1 && t[idx] == 's') ok = 1; if (i == 2 && t[idx] == 'p') ok = 1; if (i == 3 && t[idx] == 'r') ok = 1; if (i == 0) ok = 1; if (col != i) ret = max(ret, (ok ? cur[i] : 0) + solve(idx + k, i)); } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> cur[1] >> cur[2] >> cur[3] >> t; memset(dp, -1, sizeof(dp)); for (int i = 0; i < k; ++i) ans += solve(i, 0); cout << ans << '\n'; return 0; }
insert
27
27
27
30
TLE
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define REP(i, b, e) for (int i = (b); i < (e); ++i) #define RREP(i, b, e) for (int i = (b)-1; i >= e; --i) #define rep(i, e) for (int i = 0; i < (e); ++i) constexpr int MOD = 1000000007; constexpr int INF = 1LL << 30; constexpr long long LLINF = 1LL << 62; constexpr double EPS = 1e-9; struct Initializer { Initializer() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15) << boolalpha; } } initializer; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto it = vec.begin(); it != vec.end(); ++it) { if (it != vec.begin()) os << ", "; os << *it; } return os << "]"; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &pa) { return os << "(" << pa.first << ", " << pa.second << ")"; } template <typename Tuple, size_t N> struct TuplePrinter { static void print(const Tuple &t) { TuplePrinter<Tuple, N - 1>::print(t); cout << ", " << get<N - 1>(t); } }; template <typename Tuple> struct TuplePrinter<Tuple, 1> { static void print(const Tuple &t) { cout << get<0>(t); } }; template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tup) { os << "("; TuplePrinter<decltype(tup), sizeof...(T)>::print(tup); return os << ")"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &se) { os << "{"; for (auto it = se.begin(); it != se.end(); ++it) { if (it != se.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &ma) { os << "{"; for (auto it = ma.begin(); it != ma.end(); ++it) { if (it != ma.begin()) os << ", "; os << it->first << ": " << it->second; } return os << "}"; } inline void print(void) { cout << '\n'; } template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T, class... U> inline void print(const T &x, const U &...y) { cout << x << " "; print(y...); } #define dump(...) \ cout << #__VA_ARGS__ << ": [L_" << __LINE__ << "]" << '\n'; \ print(__VA_ARGS__); \ cout << '\n'; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; int ans = 0; rep(i, k) { int cur = i; int j = 0; vector<vector<int>> dp(n, vector<int>(4, 0)); if (t[cur] == 'r') dp[j][3] = p; if (t[cur] == 's') dp[j][1] = r; if (t[cur] == 'p') dp[j][2] = s; cur += k; ++j; while (cur < n) { if (t[cur] == 'r') { dp[j][1] = max(dp[j - 1][2], dp[j - 1][3]); dp[j][2] = max(dp[j - 1][1], dp[j - 1][3]); dp[j][3] = max(dp[j - 1][1] + p, dp[j - 1][2] + p); } if (t[cur] == 's') { dp[j][1] = max(dp[j - 1][2] + r, dp[j - 1][3] + r); dp[j][2] = max(dp[j - 1][1], dp[j - 1][3]); dp[j][3] = max(dp[j - 1][1], dp[j - 1][2]); } if (t[cur] == 'p') { dp[j][1] = max(dp[j - 1][2], dp[j - 1][3]); dp[j][2] = max(dp[j - 1][1] + s, dp[j - 1][3] + s); dp[j][3] = max(dp[j - 1][1], dp[j - 1][2]); } cur += k; ++j; } int res = 0; rep(l, 4) res = max(res, dp[j - 1][l]); ans += res; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, b, e) for (int i = (b); i < (e); ++i) #define RREP(i, b, e) for (int i = (b)-1; i >= e; --i) #define rep(i, e) for (int i = 0; i < (e); ++i) constexpr int MOD = 1000000007; constexpr int INF = 1LL << 30; constexpr long long LLINF = 1LL << 62; constexpr double EPS = 1e-9; struct Initializer { Initializer() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15) << boolalpha; } } initializer; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto it = vec.begin(); it != vec.end(); ++it) { if (it != vec.begin()) os << ", "; os << *it; } return os << "]"; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &pa) { return os << "(" << pa.first << ", " << pa.second << ")"; } template <typename Tuple, size_t N> struct TuplePrinter { static void print(const Tuple &t) { TuplePrinter<Tuple, N - 1>::print(t); cout << ", " << get<N - 1>(t); } }; template <typename Tuple> struct TuplePrinter<Tuple, 1> { static void print(const Tuple &t) { cout << get<0>(t); } }; template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tup) { os << "("; TuplePrinter<decltype(tup), sizeof...(T)>::print(tup); return os << ")"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &se) { os << "{"; for (auto it = se.begin(); it != se.end(); ++it) { if (it != se.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &ma) { os << "{"; for (auto it = ma.begin(); it != ma.end(); ++it) { if (it != ma.begin()) os << ", "; os << it->first << ": " << it->second; } return os << "}"; } inline void print(void) { cout << '\n'; } template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T, class... U> inline void print(const T &x, const U &...y) { cout << x << " "; print(y...); } #define dump(...) \ cout << #__VA_ARGS__ << ": [L_" << __LINE__ << "]" << '\n'; \ print(__VA_ARGS__); \ cout << '\n'; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; int ans = 0; rep(i, k) { int cur = i; int j = 0; vector<vector<int>> dp(n / k + 10, vector<int>(4, 0)); if (t[cur] == 'r') dp[j][3] = p; if (t[cur] == 's') dp[j][1] = r; if (t[cur] == 'p') dp[j][2] = s; cur += k; ++j; while (cur < n) { if (t[cur] == 'r') { dp[j][1] = max(dp[j - 1][2], dp[j - 1][3]); dp[j][2] = max(dp[j - 1][1], dp[j - 1][3]); dp[j][3] = max(dp[j - 1][1] + p, dp[j - 1][2] + p); } if (t[cur] == 's') { dp[j][1] = max(dp[j - 1][2] + r, dp[j - 1][3] + r); dp[j][2] = max(dp[j - 1][1], dp[j - 1][3]); dp[j][3] = max(dp[j - 1][1], dp[j - 1][2]); } if (t[cur] == 'p') { dp[j][1] = max(dp[j - 1][2], dp[j - 1][3]); dp[j][2] = max(dp[j - 1][1] + s, dp[j - 1][3] + s); dp[j][3] = max(dp[j - 1][1], dp[j - 1][2]); } cur += k; ++j; } int res = 0; rep(l, 4) res = max(res, dp[j - 1][l]); ans += res; } print(ans); return 0; }
replace
117
118
117
118
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define S second #define F first using namespace std; const int N = 3e3 + 15, M = 2e5 + 5; #define arr(t, n, s, e) t _##n[e - s + 1], *n = _##n + (-s); ll n, k, arr[3]; char str[N], alpha[] = "rspx", opp[] = "sprx"; ll dp[N][5]; ll solve(int ind, int prv) { if (ind >= n) return 0; ll &ret = dp[ind][prv]; if (~ret) return ret; ret = 0; for (int i = 0; i < 3; i++) { if (prv != i) ret = max(ret, solve(ind + k, i) + arr[i] * (str[ind] == opp[i])); } return ret; } int main() { memset(dp, -1, sizeof dp); scanf("%lld%lld%lld%lld%lld%s", &n, &k, arr, arr + 1, arr + 2, str); ll ans = 0; for (int i = 0; i < k; i++) ans += solve(i, 3); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define ll long long #define S second #define F first using namespace std; const int N = 2e5 + 15, M = 2e5 + 5; #define arr(t, n, s, e) t _##n[e - s + 1], *n = _##n + (-s); ll n, k, arr[3]; char str[N], alpha[] = "rspx", opp[] = "sprx"; ll dp[N][5]; ll solve(int ind, int prv) { if (ind >= n) return 0; ll &ret = dp[ind][prv]; if (~ret) return ret; ret = 0; for (int i = 0; i < 3; i++) { if (prv != i) ret = max(ret, solve(ind + k, i) + arr[i] * (str[ind] == opp[i])); } return ret; } int main() { memset(dp, -1, sizeof dp); scanf("%lld%lld%lld%lld%lld%s", &n, &k, arr, arr + 1, arr + 2, str); ll ans = 0; for (int i = 0; i < k; i++) ans += solve(i, 3); printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cerr; using std::cin; using std::cout; using std::endl; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int n, k; scanf("%d%d", &n, &k); int r, s, p; scanf("%d%d%d", &r, &s, &p); std::string t; cin >> t; // 0: r // 1: s // 2: p auto calc = [&](char c, int x) { if (c == 'r') return (x == 2 ? p : 0); if (c == 's') return (x == 0 ? r : 0); if (c == 'p') return (x == 1 ? s : 0); }; int ans = 0; for (int offset = 0; offset < k; offset++) { int add = 0; auto dp = make_v<int>(n + 1, 3); for (int i = 0; offset + i * k < n; i++) { int idx = offset + i * k; for (int j = 0; j < 3; j++) { int from = dp[i][j]; for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = std::max(dp[i + 1][k], from + calc(t[idx], k)); add = std::max(add, dp[i + 1][k]); } } } ans += add; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cerr; using std::cin; using std::cout; using std::endl; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int n, k; scanf("%d%d", &n, &k); int r, s, p; scanf("%d%d%d", &r, &s, &p); std::string t; cin >> t; // 0: r // 1: s // 2: p auto calc = [&](char c, int x) { if (c == 'r') return (x == 2 ? p : 0); if (c == 's') return (x == 0 ? r : 0); if (c == 'p') return (x == 1 ? s : 0); }; int ans = 0; for (int offset = 0; offset < k; offset++) { int add = 0, tmp = n / k + 5; auto dp = make_v<int>(tmp, 3); for (int i = 0; offset + i * k < n; i++) { int idx = offset + i * k; for (int j = 0; j < 3; j++) { int from = dp[i][j]; for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = std::max(dp[i + 1][k], from + calc(t[idx], k)); add = std::max(add, dp[i + 1][k]); } } } ans += add; } printf("%d\n", ans); return 0; }
replace
38
40
38
40
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { int n, k, r, s, p, i; string a; cin >> n >> k >> r >> s >> p; int dp[10000][3] = {0}; cin >> a; ll ans = 0; for (i = 0; i < k; i++) { if (a[i] == 'r') { ans += p; dp[i][2] = 1; } else if (a[i] == 's') { ans += r; dp[i][0] = 1; } else { ans += s; dp[i][1] = 1; } } for (i = k; i < a.size(); i++) { if (a[i] == 'r' && dp[i - k][2] == 0) { ans += p; dp[i][2] = 1; } else if (a[i] == 's' && dp[i - k][0] == 0) { ans += r; dp[i][0] = 1; } else if (a[i] == 'p' && dp[i - k][1] == 0) { ans += s; dp[i][1] = 1; } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { int n, k, r, s, p, i; string a; cin >> n >> k >> r >> s >> p; int dp[100005][3] = {0}; cin >> a; ll ans = 0; for (i = 0; i < k; i++) { if (a[i] == 'r') { ans += p; dp[i][2] = 1; } else if (a[i] == 's') { ans += r; dp[i][0] = 1; } else { ans += s; dp[i][1] = 1; } } for (i = k; i < a.size(); i++) { if (a[i] == 'r' && dp[i - k][2] == 0) { ans += p; dp[i][2] = 1; } else if (a[i] == 's' && dp[i - k][0] == 0) { ans += r; dp[i][0] = 1; } else if (a[i] == 'p' && dp[i - k][1] == 0) { ans += s; dp[i][1] = 1; } } cout << ans << endl; }
replace
7
8
7
8
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; const int INF = 1e9 + 1; int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; string T; cin >> T; vector<bool> flag(N); ll ans = 0; rep(i, T.size()) { if (T[i] != T[i - K]) { if (T[i] == 'r') ans += P; else if (T[i] == 's') ans += R; else ans += S; flag[i] = true; } else { if (!flag[i - K]) { if (T[i] == 'r') ans += P; else if (T[i] == 's') ans += R; else ans += S; flag[i] = true; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; const int INF = 1e9 + 1; int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; string T; cin >> T; vector<bool> flag(N); ll ans = 0; rep(i, T.size()) { if (i - K < 0 || T[i] != T[i - K]) { if (T[i] == 'r') ans += P; else if (T[i] == 's') ans += R; else ans += S; flag[i] = true; } else { if (!flag[i - K]) { if (T[i] == 'r') ans += P; else if (T[i] == 's') ans += R; else ans += S; flag[i] = true; } } } cout << ans << endl; return 0; }
replace
19
20
19
20
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long int ll; typedef pair<int, int> P; const int INF = 1e9 + 7; int main() { int N, K, R, S, P; string T; cin >> N >> K >> R >> S >> P >> T; vector<char> re; ll cnt = 0; rep(i, N) { char c; c = T.at(i); if (i < K) { if (c == 'r') { cnt += P; re.push_back('p'); } else if (c == 's') { cnt += R; re.push_back('r'); } else { cnt += S; re.push_back('s'); } } else if (i > N - K) { char k = re.at(i - K); if (c == 'r') { if (k != 'p') { cnt += P; } } else if (c == 's') { if (k != 'r') { cnt += R; } } else { if (k != 's') { cnt += S; } } } else { char k = re.at(i - K); if (c == 'r') { if (k != 'p') { cnt += P; re.push_back('p'); } else { if (T.at(i + K) == 'r' || T.at(i + K) == 's') { re.push_back('s'); } else { re.push_back('r'); } } } else if (c == 's') { if (k != 'r') { cnt += R; re.push_back('r'); } else { if (T.at(i + K) == 's' || T.at(i + K) == 'p') { re.push_back('p'); } else { re.push_back('s'); } } } else { if (k != 's') { cnt += S; re.push_back('s'); } else { if (T.at(i + K) == 'r' || T.at(i + K) == 'p') { re.push_back('r'); } else { re.push_back('p'); } } } } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long int ll; typedef pair<int, int> P; const int INF = 1e9 + 7; int main() { int N, K, R, S, P; string T; cin >> N >> K >> R >> S >> P >> T; vector<char> re; ll cnt = 0; rep(i, N) { char c; c = T.at(i); if (i < K) { if (c == 'r') { cnt += P; re.push_back('p'); } else if (c == 's') { cnt += R; re.push_back('r'); } else { cnt += S; re.push_back('s'); } } else if (i > N - K - 1) { char k = re.at(i - K); if (c == 'r') { if (k != 'p') { cnt += P; } } else if (c == 's') { if (k != 'r') { cnt += R; } } else { if (k != 's') { cnt += S; } } } else { char k = re.at(i - K); if (c == 'r') { if (k != 'p') { cnt += P; re.push_back('p'); } else { if (T.at(i + K) == 'r' || T.at(i + K) == 's') { re.push_back('s'); } else { re.push_back('r'); } } } else if (c == 's') { if (k != 'r') { cnt += R; re.push_back('r'); } else { if (T.at(i + K) == 's' || T.at(i + K) == 'p') { re.push_back('p'); } else { re.push_back('s'); } } } else { if (k != 's') { cnt += S; re.push_back('s'); } else { if (T.at(i + K) == 'r' || T.at(i + K) == 'p') { re.push_back('r'); } else { re.push_back('p'); } } } } } cout << cnt; }
replace
27
28
27
28
0
p02820
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define a first #define b second #define sz(x) (ll)((x).size()) #define pb push_back #define mp make_pair #define bg begin() #define ed end() #define all(x) (x).bg, (x).ed #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (ll i = (n); i >= 1; i--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) const ll MOD = 1000000007; const ll INF = 1000000000000000; 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; } ll maxx(ll x, ll y, ll z) { return max(max(x, y), z); } ll minn(ll x, ll y, ll z) { return min(min(x, y), z); } ll gcd(ll x, ll y) { if (x % y == 0) return y; else return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * (y / gcd(x, y)); } ll digsz(ll x) { if (x == 0) return 1; else { ll ans = 0; while (x) { x /= 10; ans++; } return ans; } } ll digsum(ll x) { ll sum = 0; while (x) { sum += x % 10; x /= 10; } return sum; } vector<ll> pw2(62, 1); vector<ll> pw10(19, 1); int main() { { rep1(i, 61) pw2[i] = 2 * pw2[i - 1]; } { rep1(i, 18) pw10[i] = 10 * pw10[i - 1]; } ll N, K, R, S, P; cin >> N >> K >> R >> S >> P; ll ans = 0; string s; cin >> s; vector<ll> hand(K, 0); ll now = 5; rep(i, sz(s)) { // ぐ if (s[i] == 'r') { // パー出す if (i < K || hand[i - K] != 2) { ans += P; hand[i] = 2; } else if (i + K < sz(s)) { if (s[i + K] == 'p') hand[i] = 0; else hand[i] = 1; } } // ち else if (s[i] == 's') { // ぐー出す if (i < K || hand[i - K] != 0) { ans += R; hand[i] = 0; } else if (i + K < sz(s)) { if (s[i + K] == 'r') hand[i] = 1; else hand[i] = 2; } } // ぱ else { // チョキ出す if (i < K || hand[i - K] != 1) { ans += S; hand[i] = 1; } else if (i + K < sz(s)) { if (s[i + K] == 'r') hand[i] = 0; else hand[i] = 2; } } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define a first #define b second #define sz(x) (ll)((x).size()) #define pb push_back #define mp make_pair #define bg begin() #define ed end() #define all(x) (x).bg, (x).ed #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (ll i = (n); i >= 1; i--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) const ll MOD = 1000000007; const ll INF = 1000000000000000; 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; } ll maxx(ll x, ll y, ll z) { return max(max(x, y), z); } ll minn(ll x, ll y, ll z) { return min(min(x, y), z); } ll gcd(ll x, ll y) { if (x % y == 0) return y; else return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * (y / gcd(x, y)); } ll digsz(ll x) { if (x == 0) return 1; else { ll ans = 0; while (x) { x /= 10; ans++; } return ans; } } ll digsum(ll x) { ll sum = 0; while (x) { sum += x % 10; x /= 10; } return sum; } vector<ll> pw2(62, 1); vector<ll> pw10(19, 1); int main() { { rep1(i, 61) pw2[i] = 2 * pw2[i - 1]; } { rep1(i, 18) pw10[i] = 10 * pw10[i - 1]; } ll N, K, R, S, P; cin >> N >> K >> R >> S >> P; ll ans = 0; string s; cin >> s; vector<ll> hand(sz(s), 0); rep(i, sz(s)) { // ぐ if (s[i] == 'r') { // パー出す if (i < K || hand[i - K] != 2) { ans += P; hand[i] = 2; } else if (i + K < sz(s)) { if (s[i + K] == 'p') hand[i] = 0; else hand[i] = 1; } } // ち else if (s[i] == 's') { // ぐー出す if (i < K || hand[i - K] != 0) { ans += R; hand[i] = 0; } else if (i + K < sz(s)) { if (s[i + K] == 'r') hand[i] = 1; else hand[i] = 2; } } // ぱ else { // チョキ出す if (i < K || hand[i - K] != 1) { ans += S; hand[i] = 1; } else if (i + K < sz(s)) { if (s[i + K] == 'r') hand[i] = 0; else hand[i] = 2; } } } cout << ans << endl; }
replace
86
88
86
87
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) #define vprint(x) \ for (auto a : (x)) \ cout << x << endl; using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; 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; } int main(void) { ll n, k, score[3]; string t; cin >> n >> k >> score[0] >> score[1] >> score[2] >> t; map<char, int> mp; mp['r'] = score[2]; mp['s'] = score[0]; mp['p'] = score[1]; vector<bool> chk(n, false); cin.tie(0); ios::sync_with_stdio(false); int res = 0; rep(i, n) { if (n <= k) { res += mp[t[i]]; chk[i] = true; } else { if (t[i] != t[i - k] || !chk[i - k]) { res += mp[t[i]]; chk[i] = true; } } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) #define vprint(x) \ for (auto a : (x)) \ cout << x << endl; using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; 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; } int main(void) { ll n, k, score[3]; string t; cin >> n >> k >> score[0] >> score[1] >> score[2] >> t; map<char, int> mp; mp['r'] = score[2]; mp['s'] = score[0]; mp['p'] = score[1]; vector<bool> chk(n, false); cin.tie(0); ios::sync_with_stdio(false); int res = 0; rep(i, n) { if (i < k) { res += mp[t[i]]; chk[i] = true; } else { if (t[i] != t[i - k] || !chk[i - k]) { res += mp[t[i]]; chk[i] = true; } } } cout << res << endl; return 0; }
replace
40
41
40
41
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 // 10^9+7 #define INF 1000000000000 // 10^12 #define P pair<int, int> int n, k; int r, s, p; string t; char c[20000]; int ans = 0; signed main() { cin >> n >> k; cin >> r >> s >> p; cin >> t; rep(i, n) { if (i < k) { if (t[i] == 'r') { c[i] = 'p'; ans += p; } else if (t[i] == 's') { c[i] = 'r'; ans += r; } else { c[i] = 's'; ans += s; } } else { if (t[i] == 'r') { if (c[i - k] != 'p') { c[i] = 'p'; ans += p; } else c[i] = '?'; } else if (t[i] == 's') { if (c[i - k] != 'r') { c[i] = 'r'; ans += r; } else c[i] = '?'; } else { if (c[i - k] != 's') { c[i] = 's'; ans += s; } else c[i] = '?'; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 // 10^9+7 #define INF 1000000000000 // 10^12 #define P pair<int, int> int n, k; int r, s, p; string t; char c[200000]; int ans = 0; signed main() { cin >> n >> k; cin >> r >> s >> p; cin >> t; rep(i, n) { if (i < k) { if (t[i] == 'r') { c[i] = 'p'; ans += p; } else if (t[i] == 's') { c[i] = 'r'; ans += r; } else { c[i] = 's'; ans += s; } } else { if (t[i] == 'r') { if (c[i - k] != 'p') { c[i] = 'p'; ans += p; } else c[i] = '?'; } else if (t[i] == 's') { if (c[i - k] != 'r') { c[i] = 'r'; ans += r; } else c[i] = '?'; } else { if (c[i - k] != 's') { c[i] = 's'; ans += s; } else c[i] = '?'; } } } cout << ans << endl; return 0; }
replace
11
12
11
12
0
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, k, r, s, p; string t; long long res = 0; long long dp[3][100001]; long long cal(string tmp) { memset(dp, 0, sizeof dp); for (int i = 1; i <= tmp.size(); i++) { // tmp[i-1] // 0,1,2-> R,S,P dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + (tmp[i - 1] == 's') * r; dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + (tmp[i - 1] == 'p') * s; dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + (tmp[i - 1] == 'r') * p; } return max(dp[0][tmp.size()], max(dp[1][tmp.size()], dp[2][tmp.size()])); } int main() { cin >> n >> k >> r >> s >> p; cin >> t; // cout<<t; string tmp; int j = 0; for (int i = 0; i < k; i++) { tmp = ""; j = 0; while (i + j * k < n) { tmp += t[i + j * k]; // cout<<i+j*k<<" "; j++; } res += cal(tmp); // cout<<tmp<<" "<<res<<" "<<cal(tmp)<<endl; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; int n, k, r, s, p; string t; long long res = 0; long long dp[3][100001]; long long cal(string tmp) { // memset(dp,0,sizeof dp); dp[0][0] = 0; dp[1][0] = 0; dp[2][0] = 0; for (int i = 1; i <= tmp.size(); i++) { // tmp[i-1] // 0,1,2-> R,S,P dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + (tmp[i - 1] == 's') * r; dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + (tmp[i - 1] == 'p') * s; dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + (tmp[i - 1] == 'r') * p; } return max(dp[0][tmp.size()], max(dp[1][tmp.size()], dp[2][tmp.size()])); } int main() { cin >> n >> k >> r >> s >> p; cin >> t; // cout<<t; string tmp; int j = 0; for (int i = 0; i < k; i++) { tmp = ""; j = 0; while (i + j * k < n) { tmp += t[i + j * k]; // cout<<i+j*k<<" "; j++; } res += cal(tmp); // cout<<tmp<<" "<<res<<" "<<cal(tmp)<<endl; } cout << res << endl; }
replace
7
8
7
11
TLE
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int dp[3][100010]; int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; int ans = 0; for (int i = 0; i < k; ++i) { memset(dp, 0, sizeof(dp)); int pos = 0; for (int j = 0; j * k + i < t.length(); ++j) { if (t[j * k + i] == 'r') { dp[0][j + 1] = max(dp[1][j], dp[2][j]); dp[1][j + 1] = max(dp[0][j] + p, dp[2][j] + p); dp[2][j + 1] = max(dp[1][j], dp[0][j]); } else if (t[j * k + i] == 'p') { dp[0][j + 1] = max(dp[1][j], dp[2][j]); dp[1][j + 1] = max(dp[0][j], dp[2][j]); dp[2][j + 1] = max(dp[1][j] + s, dp[0][j] + s); } else { dp[0][j + 1] = max(dp[1][j] + r, dp[2][j] + r); dp[1][j + 1] = max(dp[0][j], dp[2][j]); dp[2][j + 1] = max(dp[1][j], dp[0][j]); } pos = j + 1; } ans += max({dp[0][pos], dp[1][pos], dp[2][pos]}); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int dp[3][100010]; int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; int ans = 0; for (int i = 0; i < k; ++i) { int pos = 0; for (int j = 0; j * k + i < t.length(); ++j) { if (t[j * k + i] == 'r') { dp[0][j + 1] = max(dp[1][j], dp[2][j]); dp[1][j + 1] = max(dp[0][j] + p, dp[2][j] + p); dp[2][j + 1] = max(dp[1][j], dp[0][j]); } else if (t[j * k + i] == 'p') { dp[0][j + 1] = max(dp[1][j], dp[2][j]); dp[1][j + 1] = max(dp[0][j], dp[2][j]); dp[2][j + 1] = max(dp[1][j] + s, dp[0][j] + s); } else { dp[0][j + 1] = max(dp[1][j] + r, dp[2][j] + r); dp[1][j + 1] = max(dp[0][j], dp[2][j]); dp[2][j + 1] = max(dp[1][j], dp[0][j]); } pos = j + 1; } ans += max({dp[0][pos], dp[1][pos], dp[2][pos]}); } cout << ans << endl; }
delete
10
11
10
10
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; #define INF 1e9 int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; vector<string> a(k); rep(i, k) { for (int j = i; j < n; j += k) { if (t[j] == 'r') a[i] += 'p'; if (t[j] == 's') a[i] += 'r'; if (t[j] == 'p') a[i] += 's'; } } int ans = 0; rep(i, k) { for (int j = 1; j < n; j++) { if (a[i][j] == a[i][j - 1]) { a[i][j] = 'x'; continue; } if (a[i][j] == 'r') ans += r; if (a[i][j] == 's') ans += s; if (a[i][j] == 'p') ans += p; } if (a[i][0] == 'r') ans += r; if (a[i][0] == 's') ans += s; if (a[i][0] == 'p') ans += p; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; #define INF 1e9 int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; vector<string> a(k); rep(i, k) { for (int j = i; j < n; j += k) { if (t[j] == 'r') a[i] += 'p'; if (t[j] == 's') a[i] += 'r'; if (t[j] == 'p') a[i] += 's'; } } int ans = 0; rep(i, k) { for (int j = 1; j < a[i].size(); j++) { if (a[i][j] == a[i][j - 1]) { a[i][j] = 'x'; continue; } if (a[i][j] == 'r') ans += r; if (a[i][j] == 's') ans += s; if (a[i][j] == 'p') ans += p; } if (a[i][0] == 'r') ans += r; if (a[i][0] == 's') ans += s; if (a[i][0] == 'p') ans += p; } cout << ans << endl; }
replace
29
30
29
30
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); ++(i)) using namespace std; int main() { int n, k, r, s, p; string t; vector<string> g(2 * k); cin >> n >> k >> r >> s >> p >> t; rep(i, n) g[i % k] += t[i]; int ans = 0; rep(i, k) { int m = g[i].size(); vector<vector<int>> dp(m, vector<int>(3, 0)); if (g[i][0] == 'r') dp[0][2] = p; if (g[i][0] == 's') dp[0][0] = r; if (g[i][0] == 'p') dp[0][1] = s; for (int j = 1; j < m; ++j) { dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); if (g[i][j] == 'r') dp[j][2] += p; if (g[i][j] == 's') dp[j][0] += r; if (g[i][j] == 'p') dp[j][1] += s; } int h = max(dp[m - 1][0], dp[m - 1][1]); h = max(h, dp[m - 1][2]); ans += h; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); ++(i)) using namespace std; int main() { int n, k, r, s, p; string t; vector<string> g(100000); cin >> n >> k >> r >> s >> p >> t; rep(i, n) g[i % k] += t[i]; int ans = 0; rep(i, k) { int m = g[i].size(); vector<vector<int>> dp(m, vector<int>(3, 0)); if (g[i][0] == 'r') dp[0][2] = p; if (g[i][0] == 's') dp[0][0] = r; if (g[i][0] == 'p') dp[0][1] = s; for (int j = 1; j < m; ++j) { dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); if (g[i][j] == 'r') dp[j][2] += p; if (g[i][j] == 's') dp[j][0] += r; if (g[i][j] == 'p') dp[j][1] += s; } int h = max(dp[m - 1][0], dp[m - 1][1]); h = max(h, dp[m - 1][2]); ans += h; } cout << ans << endl; }
replace
7
8
7
8
-11
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(obj) obj.begin(), obj.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int iINF = 1e9; const long long llINF = 1e18; const int MOD = 1e9 + 7; using namespace std; long long dp[20010][3]; // r = 0, s = 1, p = 2 int main() { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; string T; cin >> T; REP(i, N) { REP(j, 3) { REP(k, 3) { if (j == k) continue; if (T[i] == 's' && k == 0) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + R); } if (T[i] == 'p' && k == 1) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + S); } if (T[i] == 'r' && k == 2) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + P); } dp[i + K][k] = max(dp[i + K][k], dp[i][j]); } } } long long ans = 0; for (int i = N; i < N + K; i++) { ans += max(max(dp[i][0], dp[i][1]), dp[i][2]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(obj) obj.begin(), obj.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int iINF = 1e9; const long long llINF = 1e18; const int MOD = 1e9 + 7; using namespace std; long long dp[200010][3]; // r = 0, s = 1, p = 2 int main() { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; string T; cin >> T; REP(i, N) { REP(j, 3) { REP(k, 3) { if (j == k) continue; if (T[i] == 's' && k == 0) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + R); } if (T[i] == 'p' && k == 1) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + S); } if (T[i] == 'r' && k == 2) { dp[i + K][k] = max(dp[i + K][k], dp[i][j] + P); } dp[i + K][k] = max(dp[i + K][k], dp[i][j]); } } } long long ans = 0; for (int i = N; i < N + K; i++) { ans += max(max(dp[i][0], dp[i][1]), dp[i][2]); } cout << ans << endl; return 0; }
replace
26
27
26
27
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { int n, k; map<char, int> mp; string t; cin >> n >> k >> mp['s'] >> mp['p'] >> mp['r'] >> t; vector<bool> win(n); int ans = 0; rep(i, n) { if (n >= k && t[i] == t[i - k] && win[i - k]) win[i] = false; else { win[i] = true; ans += mp[t[i]]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { int n, k; map<char, int> mp; string t; cin >> n >> k >> mp['s'] >> mp['p'] >> mp['r'] >> t; vector<bool> win(n); int ans = 0; rep(i, n) { if (i >= k && t[i] == t[i - k] && win[i - k]) win[i] = false; else { win[i] = true; ans += mp[t[i]]; } } cout << ans << endl; return 0; }
replace
13
14
13
14
0
p02820
C++
Runtime Error
// Hovalhagh // Ya Aziz & Hakim // AliReza Kaboli #include <bits/stdc++.h> using namespace std; int main() { int n, k, r, s, p, ans = 0; string t, sa; cin >> n >> k >> r >> s >> p >> t; for (int i = 0; i < n; ++i) { if (t[i] == 'r') { ans += p; sa += 'p'; } else if (t[i] == 's') { ans += r; sa += 'r'; } else { ans += s; sa += 's'; } } for (int i = 0; i < n; ++i) { if (i + k < n && sa[i] == sa[i + k]) { if (sa[i + k] == 'r') ans -= r; else if (sa[i + k] == 's') ans -= s; else ans -= p; if (sa[i] != 'r' && sa[i + 2 * k] != 'r') sa[i + k] = 'r'; if (sa[i] != 's' && sa[i + 2 * k] != 's') sa[i + k] = 's'; if (sa[i] != 'p' && sa[i + 2 * k] != 'p') sa[i + k] = 'p'; } } cout << ans << '\n'; }
// Hovalhagh // Ya Aziz & Hakim // AliReza Kaboli #include <bits/stdc++.h> using namespace std; int main() { int n, k, r, s, p, ans = 0; string t, sa; cin >> n >> k >> r >> s >> p >> t; for (int i = 0; i < n; ++i) { if (t[i] == 'r') { ans += p; sa += 'p'; } else if (t[i] == 's') { ans += r; sa += 'r'; } else { ans += s; sa += 's'; } } for (int i = 0; i < n; ++i) { if (i + k < n && sa[i] == sa[i + k]) { if (sa[i + k] == 'r') ans -= r; else if (sa[i + k] == 's') ans -= s; else ans -= p; if (i + 2 * k < n) { if (sa[i] != 'r' && sa[i + 2 * k] != 'r') sa[i + k] = 'r'; if (sa[i] != 's' && sa[i + 2 * k] != 's') sa[i + k] = 's'; if (sa[i] != 'p' && sa[i + 2 * k] != 'p') sa[i + k] = 'p'; } } } cout << ans << '\n'; }
replace
32
38
32
40
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 unsigned gcd(unsigned a, unsigned b) { if (a < b) return gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } int main() { // rsp int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; vector<char> te(n); ll ans = 0; REP(i, n) { te[i] = t[i]; if (i - k >= 0) { if (t[i] == te[i - k]) { if (t[i + k] == 'r') te[i] = 's'; else if (t[i + k] == 's') te[i] = 'r'; else if (t[i + k] == 'p') te[i] = 'r'; continue; } } if (t[i] == 'r') ans += p, te[i] = 'r'; else if (t[i] == 's') ans += r, te[i] = 's'; else if (t[i] == 'p') ans += s, te[i] = 'p'; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 unsigned gcd(unsigned a, unsigned b) { if (a < b) return gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } int main() { // rsp int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; vector<char> te(n); ll ans = 0; REP(i, n) { te[i] = t[i]; if (i - k >= 0) { if (t[i] == te[i - k]) { if (i + k < n) { if (t[i + k] == 'r') te[i] = 's'; else if (t[i + k] == 's') te[i] = 'r'; else if (t[i + k] == 'p') te[i] = 'r'; } continue; } } if (t[i] == 'r') ans += p, te[i] = 'r'; else if (t[i] == 's') ans += r, te[i] = 's'; else if (t[i] == 'p') ans += s, te[i] = 'p'; } print(ans); return 0; }
replace
265
271
265
273
0
p02820
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int N = 100010; bool st[N]; int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; char t[N]; cin >> t; int sum = 0; for (int i = 0; i < n; i++) { if (st[i] == false) { if (t[i] == t[i + k]) { st[i + k] = true; } if (t[i] == 'r') sum += p; else if (t[i] == 's') sum += r; else if (t[i] == 'p') sum += s; } } cout << sum << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int N = 100010; bool st[N]; int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; char t[N]; cin >> t; int sum = 0; for (int i = 0; i < n; i++) { if (st[i] == false) { if (i + k < n && t[i] == t[i + k]) { st[i + k] = true; } if (t[i] == 'r') sum += p; else if (t[i] == 's') sum += r; else if (t[i] == 'p') sum += s; } } cout << sum << endl; return 0; }
replace
14
15
14
15
0
p02820
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<pair<ll, ll>>> vvpll; #define rep(i, n) for (ll i = 0; i < n; i++) #define exrep(i, a, b) for (ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const ll MAX_N = 100010; int main() { ll n, K, R, S, P; string T; cin >> n >> K >> R >> S >> P >> T; ll ans = 0; rep(i, K) { for (ll j = i; j < n; j += K) { if (T[j] == 'r') { ans += P; } else if (T[j] == 's') { ans += R; } else if (T[j] == 'p') { ans += S; } if (T[j] == T[j + K]) { j += K; } } } out(ans); re0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<pair<ll, ll>>> vvpll; #define rep(i, n) for (ll i = 0; i < n; i++) #define exrep(i, a, b) for (ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const ll MAX_N = 100010; int main() { ll n, K, R, S, P; string T; cin >> n >> K >> R >> S >> P >> T; ll ans = 0; rep(i, K) { for (ll j = i; j < n; j += K) { if (T[j] == 'r') { ans += P; } else if (T[j] == 's') { ans += R; } else if (T[j] == 'p') { ans += S; } if (j + K <= n - 1 && T[j] == T[j + K]) { j += K; } } } out(ans); re0; }
replace
47
48
47
48
0
p02820
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; long long int gcd(long long int a, long long int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main() { long long int n, k, r, s, p, ans = 0; cin >> n >> k >> r >> s >> p; string q; cin >> q; for (long long int i = 0; i < n; i++) { if (q[i] == 'r') { ans += p; } else if (q[i] == 's') { ans += r; } else if (q[i] == 'p') { ans += s; } if (q[i] == q[i + k]) { q[i + k] = 'z'; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; long long int gcd(long long int a, long long int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main() { long long int n, k, r, s, p, ans = 0; cin >> n >> k >> r >> s >> p; string q; cin >> q; for (long long int i = 0; i < n; i++) { if (q[i] == 'r') { ans += p; } else if (q[i] == 's') { ans += r; } else if (q[i] == 'p') { ans += s; } if (i < n - k && q[i] == q[i + k]) { q[i + k] = 'z'; } } cout << ans << endl; return 0; }
replace
28
29
28
29
0
p02820
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iostream> using namespace std; /*---------------------DEBUGGING--------------------------------------------*/ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif /*-------------------------------------------------------------------------------------*/ #define mp make_pair #define pb push_back #define ll long long #define pii pair<int, int> #define pcc pair<char, char> #define F first #define S second #define int long long #define pi 3.141592653589793238462643383279502 #define M 1000000007 #define rep(i, a, n) for (int i = a; i < n; i++) #define N 300005 #define vi vector<int> #define all(v) v.begin(), v.end() signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string st; cin >> st; string ans = ""; vector<int> v; for (int i = 0; i < st.length(); i++) { if (i < k) { if (st[i] == 'r') ans += 'p'; if (st[i] == 's') ans += 'r'; if (st[i] == 'p') ans += 's'; } else { if (st[i] == 'r') { if (ans[i - k] != 'p') ans += 'p'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } if (st[i] == 'p') { if (ans[i - k] != 's') ans += 's'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } if (st[i] == 's') { if (ans[i - k] != 'r') ans += 'r'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } } } int sum = 0; int j = 0; for (int i = 0; i < ans.length(); i++) { if (i == v[j] && j < v.size()) { j++; continue; } if (ans[i] == 'r') sum += r; if (ans[i] == 's') sum += s; if (ans[i] == 'p') sum += p; } cout << sum << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> using namespace std; /*---------------------DEBUGGING--------------------------------------------*/ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif /*-------------------------------------------------------------------------------------*/ #define mp make_pair #define pb push_back #define ll long long #define pii pair<int, int> #define pcc pair<char, char> #define F first #define S second #define int long long #define pi 3.141592653589793238462643383279502 #define M 1000000007 #define rep(i, a, n) for (int i = a; i < n; i++) #define N 300005 #define vi vector<int> #define all(v) v.begin(), v.end() signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string st; cin >> st; string ans = ""; vector<int> v; for (int i = 0; i < st.length(); i++) { if (i < k) { if (st[i] == 'r') ans += 'p'; if (st[i] == 's') ans += 'r'; if (st[i] == 'p') ans += 's'; } else { if (st[i] == 'r') { if (ans[i - k] != 'p') ans += 'p'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } if (st[i] == 'p') { if (ans[i - k] != 's') ans += 's'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } if (st[i] == 's') { if (ans[i - k] != 'r') ans += 'r'; else { if ((i + k) < st.length()) { if (st[i + k] == 's') ans += 's'; if (st[i + k] == 'r') ans += 'r'; if (st[i + k] == 'p') ans += 'p'; v.pb(i); } } } } } int sum = 0; int j = 0; for (int i = 0; i < ans.length(); i++) { if (j < v.size()) { if (i == v[j]) { j++; continue; } } if (ans[i] == 'r') sum += r; if (ans[i] == 's') sum += s; if (ans[i] == 'p') sum += p; } cout << sum << endl; }
replace
137
140
137
142
0
p02820
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> #define log(x) cout << x << endl #define pb push_back #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long lint; using namespace std; // <<fixed<<setprecision(6)<< int gcd(lint x, lint y) { return y == 0 ? x : gcd(y, x % y); } int Combination(int n, int r) { int num = 1; for (int i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } int main() { int n, k; int rr, ss, pp = 0; map<char, int> m; m['r'] = 0; m['s'] = 0; m['p'] = 0; int r, s, p; cin >> n >> k; cin >> r >> s >> p; vector<char> l, a; string st; cin >> st; for (int i = 0; i < st.size(); i++) { char j = st[i]; if (j == 'r') { l.pb(j); a.pb('p'); m['p']++; } else if (j == 's') { l.pb(j); a.pb('r'); m['r']++; } else if (j == 'p') { l.pb(j); a.pb('s'); m['s']++; } } for (int i = k; i < n; i++) { char j = a[i]; if (a[i - k] == j) { if (a[i + k] == j) { a[i] = 'x'; } m[j]--; } } int result = m['r'] * r + m['s'] * s + m['p'] * p; cout << result; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> #define log(x) cout << x << endl #define pb push_back #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long lint; using namespace std; // <<fixed<<setprecision(6)<< int gcd(lint x, lint y) { return y == 0 ? x : gcd(y, x % y); } int Combination(int n, int r) { int num = 1; for (int i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } int main() { int n, k; int rr, ss, pp = 0; map<char, int> m; m['r'] = 0; m['s'] = 0; m['p'] = 0; int r, s, p; cin >> n >> k; cin >> r >> s >> p; vector<char> l, a; string st; cin >> st; for (int i = 0; i < st.size(); i++) { char j = st[i]; if (j == 'r') { l.pb(j); a.pb('p'); m['p']++; } else if (j == 's') { l.pb(j); a.pb('r'); m['r']++; } else if (j == 'p') { l.pb(j); a.pb('s'); m['s']++; } } for (int i = k; i < n; i++) { char j = a[i]; if (a[i - k] == j) { if (i + k < n) { if (a[i + k] == j) { a[i] = 'x'; } } m[j]--; } } int result = m['r'] * r + m['s'] * s + m['p'] * p; cout << result; }
replace
65
67
65
69
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long int64; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; int score[3] = {R, S, P}; string H = "rsp"; string T; cin >> T; vector<string> str(N / K); rep(i, N) { str[i % K] += T[i]; } auto f = [&](const string &s) -> int { int N = s.size(); vector<vector<int>> dp(N + 1, vector<int>(3)); rep(i, N) rep(pre, 3) rep(hand, 3) { if (pre == hand) continue; int nscore = s[i] == H[(hand + 1) % 3] ? score[hand] : 0; chmax(dp[i + 1][hand], dp[i][pre] + nscore); } int ans = 0; rep(i, 3) ans = max(ans, dp[N][i]); return ans; }; int ans = 0; for (auto &s : str) { ans += f(s); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long int64; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int N, K, R, S, P; cin >> N >> K >> R >> S >> P; int score[3] = {R, S, P}; string H = "rsp"; string T; cin >> T; vector<string> str(K + 10); rep(i, N) { str[i % K] += T[i]; } auto f = [&](const string &s) -> int { int N = s.size(); vector<vector<int>> dp(N + 1, vector<int>(3)); rep(i, N) rep(pre, 3) rep(hand, 3) { if (pre == hand) continue; int nscore = s[i] == H[(hand + 1) % 3] ? score[hand] : 0; chmax(dp[i + 1][hand], dp[i][pre] + nscore); } int ans = 0; rep(i, 3) ans = max(ans, dp[N][i]); return ans; }; int ans = 0; for (auto &s : str) { ans += f(s); } cout << ans << '\n'; return 0; }
replace
26
27
26
27
0
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; // r, s, p ll score[3]; cin >> score[0] >> score[1] >> score[2]; string s; cin >> s; string spr = "spr"; ll ans = 0; for (int a = 0; a < k; a++) { ll dp[n + 1][3]; rep(i, n + 1) rep(j, 3) dp[i][j] = 0; for (int j = 0; j < 3; j++) { if (s[a] == spr[j]) dp[0][j] += score[j]; } int last = 0; int idx = a + k; for (; idx < n; idx += k) { int i = idx / k; last = idx; for (int j = 0; j < 3; j++) { for (int l = 0; l < 3; l++) { if (j == l) continue; if (s[idx] == spr[j]) dp[i][j] = max(dp[i][j], dp[i - 1][l] + score[j]); else dp[i][j] = max(dp[i][j], dp[i - 1][l]); } } } ans += max({dp[last / k][0], dp[last / k][1], dp[last / k][2]}); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; // r, s, p ll score[3]; cin >> score[0] >> score[1] >> score[2]; string s; cin >> s; string spr = "spr"; ll ans = 0; for (int a = 0; a < k; a++) { ll dp[n / k + 10][3]; rep(i, n / k + 10) rep(j, 3) dp[i][j] = 0; for (int j = 0; j < 3; j++) { if (s[a] == spr[j]) dp[0][j] += score[j]; } int last = 0; int idx = a + k; for (; idx < n; idx += k) { int i = idx / k; last = idx; for (int j = 0; j < 3; j++) { for (int l = 0; l < 3; l++) { if (j == l) continue; if (s[idx] == spr[j]) dp[i][j] = max(dp[i][j], dp[i - 1][l] + score[j]); else dp[i][j] = max(dp[i][j], dp[i - 1][l]); } } } ans += max({dp[last / k][0], dp[last / k][1], dp[last / k][2]}); } cout << ans << endl; }
replace
25
27
25
27
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string a; int cnt; int ans; int n, k, r, s, p; int main() { cin >> n >> k; cin >> r >> s >> p; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (a[i] == 'r') { cnt = p; } else if (a[i] == 's') { cnt = r; } else if (a[i] == 'p') { cnt = s; } if (i >= k and a[i] == a[i - k]) { cnt = 0; a[i] = ' '; } ans += cnt; } cout << ans; }
#include <bits/stdc++.h> using namespace std; string a; int cnt; int ans; int n, k, r, s, p; int main() { cin >> n >> k; cin >> r >> s >> p; cin >> a; for (int i = 0; i < n; i++) { if (a[i] == 'r') { cnt = p; } else if (a[i] == 's') { cnt = r; } else if (a[i] == 'p') { cnt = s; } if (i >= k and a[i] == a[i - k]) { cnt = 0; a[i] = ' '; } ans += cnt; } cout << ans; }
replace
9
12
9
10
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; ll gi() { ll x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } bool isprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0; return 1; } char S[100010]; int main() { #ifdef XZZSB freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); #endif int n = gi(), k = gi(), r = gi(), s = gi(), p = gi(), ans = 0; scanf("%s", S + 1); for (int i = 1; i <= k; ++i) for (int j = i; j <= n; j += k) { if (S[j] == S[j - k]) S[j] = '*'; else { if (S[j] == 'r') ans += p; else if (S[j] == 'p') ans += s; else ans += r; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> typedef long long ll; ll gi() { ll x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } bool isprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0; return 1; } char S[100010]; int main() { #ifdef XZZSB freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); #endif int n = gi(), k = gi(), r = gi(), s = gi(), p = gi(), ans = 0; scanf("%s", S + 1); for (int i = 1; i <= k; ++i) for (int j = i; j <= n; j += k) { if (j > k && S[j] == S[j - k]) S[j] = '*'; else { if (S[j] == 'r') ans += p; else if (S[j] == 'p') ans += s; else ans += r; } } printf("%d\n", ans); return 0; }
replace
27
28
27
28
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int val(char ch, int r, int s, int p) { if (ch == 'r') return r; if (ch == 'p') return p; if (ch == 's') return s; } int main() { int n, k, r, s, p, ans = 0; string t; cin >> n >> k >> r >> s >> p >> t; for (int i = 0; i < n; i++) { if (t[i] == 'r') t[i] = 'p'; else if (t[i] == 'p') t[i] = 's'; else if (t[i] == 's') t[i] = 'r'; ans += val(t[i], r, s, p); } for (int i = 0; i < n; i++) { if (t[i] == t[i + k]) { ans -= val(t[i + k], r, s, p); t[i + k] = 0; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int val(char ch, int r, int s, int p) { if (ch == 'r') return r; if (ch == 'p') return p; if (ch == 's') return s; } int main() { int n, k, r, s, p, ans = 0; string t; cin >> n >> k >> r >> s >> p >> t; for (int i = 0; i < n; i++) { if (t[i] == 'r') t[i] = 'p'; else if (t[i] == 'p') t[i] = 's'; else if (t[i] == 's') t[i] = 'r'; ans += val(t[i], r, s, p); } for (int i = 0; i + k < n; i++) { if (t[i] == t[i + k]) { ans -= val(t[i + k], r, s, p); t[i + k] = 0; } } cout << ans << endl; return 0; }
replace
25
26
25
26
0
p02820
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // const ll INF = 1LL <<60; // const int INF = 10000; // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const int MOD = 1e9 + 7; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } // for(int i = ; i < ; i++){} ll lmax(ll s, ll t) { if (s > t) { return s; } else { return t; } } ll lmin(ll s, ll t) { if (s < t) { return s; } else { return t; } } long long modpow(long long res, long long a, long long n, long long mod) { while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } IsPrime[0] = false; // 0は素数ではない IsPrime[1] = false; // 1は素数ではない for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる if (IsPrime[i]) // iが素数ならば for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は IsPrime[i * j] = false; // 素数ではない } // ここから開始 int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; vector<bool> rlist(n, false); vector<bool> slist(n, false); vector<bool> plist(n, false); for (int i = 0; i < t.length(); i++) { if (t[i] == 'r') { rlist[i] = true; } if (t[i] == 's') { slist[i] = true; } else if (t[i] == 'p') { plist[i] = true; } } int flg; ll sum = 0; for (int i = 0; i < n; i++) { if (rlist[i] == true && rlist[i + k] == true) { rlist[i + k] = false; } if (slist[i] == true && slist[i + k] == true) { slist[i + k] = false; } if (plist[i] == true && plist[i + k] == true) { plist[i + k] = false; } } for (int i = 0; i < n; i++) { if (rlist[i] == true) { // cout<<i<<endl; sum += p; } if (slist[i] == true) { // cout<<i<<endl; sum += r; } if (plist[i] == true) { // cout<<i<<endl; sum += s; } } // if(rlist.size()!=0){ // flg = rlist[0]; // for(int i = 0; i < rlist.size(); i++){ // if(r) // } // if(slist.size()!=0){ // flg = slist[0]; // cout<<endl; // for(int i = 0; i < slist.size(); i++){ // if(flg + k == slist[i]){ // cout<<"s"<<i<<" "; // } // else{ // sum+=r; // flg = slist[i]; // } // } // } // if(plist.size()!=0){ // flg = plist[0]; // cout<<endl; // for(int i = 0; i < plist.size(); i++){ // cout<<plist[i]<<" "; // if(flg + k == plist[i]){ // cout<<"p"<<i<<" "; // ; // } // else{ // sum+=s; // flg = plist[i]; // } // } // } cout << sum << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // const ll INF = 1LL <<60; // const int INF = 10000; // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const int MOD = 1e9 + 7; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } // for(int i = ; i < ; i++){} ll lmax(ll s, ll t) { if (s > t) { return s; } else { return t; } } ll lmin(ll s, ll t) { if (s < t) { return s; } else { return t; } } long long modpow(long long res, long long a, long long n, long long mod) { while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } IsPrime[0] = false; // 0は素数ではない IsPrime[1] = false; // 1は素数ではない for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる if (IsPrime[i]) // iが素数ならば for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は IsPrime[i * j] = false; // 素数ではない } // ここから開始 int main() { int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string t; cin >> t; vector<bool> rlist(n, false); vector<bool> slist(n, false); vector<bool> plist(n, false); for (int i = 0; i < t.length(); i++) { if (t[i] == 'r') { rlist[i] = true; } if (t[i] == 's') { slist[i] = true; } else if (t[i] == 'p') { plist[i] = true; } } int flg; ll sum = 0; for (int i = 0; i < n - k; i++) { if (rlist[i] == true && rlist[i + k] == true) { rlist[i + k] = false; } if (slist[i] == true && slist[i + k] == true) { slist[i + k] = false; } if (plist[i] == true && plist[i + k] == true) { plist[i + k] = false; } } for (int i = 0; i < n; i++) { if (rlist[i] == true) { // cout<<i<<endl; sum += p; } if (slist[i] == true) { // cout<<i<<endl; sum += r; } if (plist[i] == true) { // cout<<i<<endl; sum += s; } } // if(rlist.size()!=0){ // flg = rlist[0]; // for(int i = 0; i < rlist.size(); i++){ // if(r) // } // if(slist.size()!=0){ // flg = slist[0]; // cout<<endl; // for(int i = 0; i < slist.size(); i++){ // if(flg + k == slist[i]){ // cout<<"s"<<i<<" "; // } // else{ // sum+=r; // flg = slist[i]; // } // } // } // if(plist.size()!=0){ // flg = plist[0]; // cout<<endl; // for(int i = 0; i < plist.size(); i++){ // cout<<plist[i]<<" "; // if(flg + k == plist[i]){ // cout<<"p"<<i<<" "; // ; // } // else{ // sum+=s; // flg = plist[i]; // } // } // } cout << sum << endl; return 0; }
replace
157
158
157
158
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> // created [2019/12/29] 20:04:22 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T, usize n> using arr = T (&)[n]; template <typename T, usize n> using c_arr = const T (&)[n]; template <typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); } template <typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); } template <typename T> constexpr T msbp1(const T u) { return log2p1(u); } template <typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template <typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); } template <typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; } template <typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); } template <typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); } template <typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); } template <typename T> void bset(T &mask, const usize ind) { mask |= (static_cast<T>(1) << ind); } template <typename T> void breset(T &mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); } template <typename T> void bflip(T &mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); } template <typename T> void bset(T &mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template <typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); } template <typename T> bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); } template <typename T> bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template <typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template <typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; auto mfp = [](auto &&f) { return [=](auto &&...args) { return f(f, std::forward<decltype(args)>(args)...); }; }; template <typename T> T in() { T v; return std::cin >> v, v; } template <typename T, typename Uint, usize n, usize i> T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); } template <typename T, typename Uint, usize n, usize i> auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type &szs) { const usize s = (usize)szs[i]; std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s); for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); } return ans; } template <typename T, typename Uint, usize n> auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); } template <typename... Types> auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; } struct io_init { io_init() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(20); } void clear() { std::cin.tie(), std::ios::sync_with_stdio(true); } } io_setting; template <typename T> int out(const T &v) { return std::cout << v, 0; } template <typename T> int out(const std::vector<T> &v) { for (usize i = 0; i < v.size(); i++) { if (i > 0) { std::cout << ' '; } out(v[i]); } return std::cout << "\n", 0; } template <typename T1, typename T2> int out(const std::pair<T1, T2> &v) { return out(v.first), std::cout << ' ', out(v.second), 0; } template <typename T, typename... Args> int out(const T &v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; } template <typename... Args> int outln(const Args... args) { return out(args...), std::cout << '\n', 0; } template <typename... Args> void outel(const Args... args) { return out(args...), std::cout << std::endl, 0; } #define SHOW(...) static_cast<void>(0) constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template <typename T, typename Uint, usize n, usize i> auto make_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type, const T &v = T{}) { return v; } template <typename T, typename Uint, usize n, usize i> auto make_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type szs, const T &v = T{}) { const usize s = (usize)szs[i]; return std::vector<decltype(make_v<T, Uint, n, i + 1>(szs, v))>( s, make_v<T, Uint, n, i + 1>(szs, v)); } template <typename T, typename Uint, usize n> auto make_v(c_arr<Uint, n> szs, const T &t = T{}) { return make_v<T, Uint, n, 0>(szs, t); } int main() { const int N = in<int>(); const int K = in<int>(); const auto S = in_v<ll>({3}); const auto T = in<std::string>(); std::vector<std::string> Q(K); for (int i = 0; i < K; i++) { for (int j = i; j < N; j += K) { Q[i].push_back(T[j] == 's' ? 0 : T[j] == 'p' ? 1 : 2); } } ll ans = 0; for (int i = 0; i < K; i++) { const int N = Q[i].size(); auto dp = make_v({N + 1, 4}, -inf_v<ll>); dp[0][3] = 0; for (int j = 0; j < N; j++) { const int q = Q[i][j]; for (int p = 0; p <= 3; p++) { for (int np = 0; np < 3; np++) { if (p == np) { continue; } chmax(dp[i + 1][np], dp[i][p] + (np == q ? S[q] : 0LL)); } } } ll max = -inf_v<ll>; for (int p = 0; p < 3; p++) { chmax(max, dp[N][p]); } ans += max; } outln(ans); return 0; }
#include <bits/stdc++.h> // created [2019/12/29] 20:04:22 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T, usize n> using arr = T (&)[n]; template <typename T, usize n> using c_arr = const T (&)[n]; template <typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); } template <typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); } template <typename T> constexpr T msbp1(const T u) { return log2p1(u); } template <typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template <typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); } template <typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; } template <typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); } template <typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); } template <typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); } template <typename T> void bset(T &mask, const usize ind) { mask |= (static_cast<T>(1) << ind); } template <typename T> void breset(T &mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); } template <typename T> void bflip(T &mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); } template <typename T> void bset(T &mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template <typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); } template <typename T> bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); } template <typename T> bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template <typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template <typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; auto mfp = [](auto &&f) { return [=](auto &&...args) { return f(f, std::forward<decltype(args)>(args)...); }; }; template <typename T> T in() { T v; return std::cin >> v, v; } template <typename T, typename Uint, usize n, usize i> T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); } template <typename T, typename Uint, usize n, usize i> auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type &szs) { const usize s = (usize)szs[i]; std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s); for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); } return ans; } template <typename T, typename Uint, usize n> auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); } template <typename... Types> auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; } struct io_init { io_init() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(20); } void clear() { std::cin.tie(), std::ios::sync_with_stdio(true); } } io_setting; template <typename T> int out(const T &v) { return std::cout << v, 0; } template <typename T> int out(const std::vector<T> &v) { for (usize i = 0; i < v.size(); i++) { if (i > 0) { std::cout << ' '; } out(v[i]); } return std::cout << "\n", 0; } template <typename T1, typename T2> int out(const std::pair<T1, T2> &v) { return out(v.first), std::cout << ' ', out(v.second), 0; } template <typename T, typename... Args> int out(const T &v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; } template <typename... Args> int outln(const Args... args) { return out(args...), std::cout << '\n', 0; } template <typename... Args> void outel(const Args... args) { return out(args...), std::cout << std::endl, 0; } #define SHOW(...) static_cast<void>(0) constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template <typename T, typename Uint, usize n, usize i> auto make_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type, const T &v = T{}) { return v; } template <typename T, typename Uint, usize n, usize i> auto make_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type szs, const T &v = T{}) { const usize s = (usize)szs[i]; return std::vector<decltype(make_v<T, Uint, n, i + 1>(szs, v))>( s, make_v<T, Uint, n, i + 1>(szs, v)); } template <typename T, typename Uint, usize n> auto make_v(c_arr<Uint, n> szs, const T &t = T{}) { return make_v<T, Uint, n, 0>(szs, t); } int main() { const int N = in<int>(); const int K = in<int>(); const auto S = in_v<ll>({3}); const auto T = in<std::string>(); std::vector<std::string> Q(K); for (int i = 0; i < K; i++) { for (int j = i; j < N; j += K) { Q[i].push_back(T[j] == 's' ? 0 : T[j] == 'p' ? 1 : 2); } } ll ans = 0; for (int i = 0; i < K; i++) { const int N = Q[i].size(); auto dp = make_v({N + 1, 4}, -inf_v<ll>); dp[0][3] = 0; for (int j = 0; j < N; j++) { const int q = Q[i][j]; for (int p = 0; p <= 3; p++) { for (int np = 0; np < 3; np++) { if (p == np) { continue; } chmax(dp[j + 1][np], dp[j][p] + (np == q ? S[q] : 0LL)); } } } ll max = -inf_v<ll>; for (int p = 0; p < 3; p++) { chmax(max, dp[N][p]); } ans += max; } outln(ans); return 0; }
replace
173
174
173
174
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<int> to[100005]; int n; vector<int> dist; void dfs(int v, int d = 0, int p = -1) { dist[v] = d; for (int u : to[v]) { if (u == p) continue; dfs(u, d + 1, v); } } vector<int> calcDist(int s) { dist = vector<int>(n); dfs(s); return dist; } int main() { ll n, k; cin >> n >> k; ll r, s, p; cin >> r >> s >> p; string t; cin >> t; ll sum = 0; rep(i, t.size()) { if (t[i] == t[i + k]) { t[i + k] = 'x'; } switch (t[i]) { case 'r': sum += p; break; case 's': sum += r; break; case 'p': sum += s; default: break; } } cout << sum << endl; } // int main() { // ll n, m; // vector<ll> v; // rep(i,n) { // ll a; cin >> a; // v.push_back(a); // } // }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<int> to[100005]; int n; vector<int> dist; void dfs(int v, int d = 0, int p = -1) { dist[v] = d; for (int u : to[v]) { if (u == p) continue; dfs(u, d + 1, v); } } vector<int> calcDist(int s) { dist = vector<int>(n); dfs(s); return dist; } int main() { ll n, k; cin >> n >> k; ll r, s, p; cin >> r >> s >> p; string t; cin >> t; ll sum = 0; rep(i, t.size()) { if ((i + k) < n) { if (t[i] == t[i + k]) { t[i + k] = 'x'; } } switch (t[i]) { case 'r': sum += p; break; case 's': sum += r; break; case 'p': sum += s; default: break; } } cout << sum << endl; } // int main() { // ll n, m; // vector<ll> v; // rep(i,n) { // ll a; cin >> a; // v.push_back(a); // } // }
replace
67
69
67
71
-11
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 100000000000000005; const int maxn = 1e6 + 5; const int mod = 433494437; ll n, m; char str[maxn]; char cop[maxn]; map<char, ll> mp; int main() { ll r, s, p; // rock s paper scanf("%lld%lld", &n, &m); scanf("%lld%lld%lld%s", &r, &s, &p, str + 1); mp['r'] = r; mp['s'] = s; mp['p'] = p; for (int i = 1; i <= n; i++) { if (str[i] == 'r') cop[i] = 'p'; if (str[i] == 'p') cop[i] = 's'; if (str[i] == 's') cop[i] = 'r'; } ll res = 0; for (int i = 1; i <= m; i++) { for (int k = i; k <= n; k += m) { if (cop[k] != cop[k - m]) res += mp[cop[k]]; else cop[k] = '.'; } } printf("%lld\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 100000000000000005; const int maxn = 1e6 + 5; const int mod = 433494437; ll n, m; char str[maxn]; char cop[maxn]; map<char, ll> mp; int main() { ll r, s, p; // rock s paper scanf("%lld%lld", &n, &m); scanf("%lld%lld%lld%s", &r, &s, &p, str + 1); mp['r'] = r; mp['s'] = s; mp['p'] = p; for (int i = 1; i <= n; i++) { if (str[i] == 'r') cop[i] = 'p'; if (str[i] == 'p') cop[i] = 's'; if (str[i] == 's') cop[i] = 'r'; } ll res = 0; for (int i = 1; i <= m; i++) { res += mp[cop[i]]; for (int k = i + m; k <= n; k += m) { if (cop[k] != cop[k - m]) res += mp[cop[k]]; else cop[k] = '.'; } } printf("%lld\n", res); return 0; }
replace
27
28
27
29
0
p02820
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; string item; for (char ch : s) { if (ch == delim) { if (!item.empty()) { elems.push_back(item); } item.clear(); } else { item += ch; } } if (!item.empty()) { elems.push_back(item); } return elems; } string to_str_with_zero(int i, int w) { ostringstream sout; sout << std::setfill('0') << std::setw(w) << i; string s = sout.str(); return s; } int letter_to_int(char c) { return tolower(c) - 'a'; } int compare_array(vector<int> a1, vector<int> a2) { int n1 = a1.size(); int n2 = a2.size(); if (n1 != n2) { return n1 - n2; } for (int i = 0; i < n1; i++) { if (a1.at(i) != a2.at(i)) { return a1.at(i) - a2.at(i); } } return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } char int_to_char(int a) { if (a == -1) { return 'z'; } else { return 'a' + a; } } long nCr(int n, int r) { long ans = 1; for (int i = n; i > n - r; --i) { ans = ans * i; } for (int i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } 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; } int divide_count(int a, int divider) { int r = 0; while (a % divider == 0) { a /= divider; r++; } return r; } bool is_prime(int a) { int i = 2; while (i * i <= a) { if (a % i == 0) { return false; } i++; } return true; } vector<vector<int>> all_comb(int n, int k) { vector<vector<int>> combs(nCr(n, k), vector<int>(k)); for (int i = 0; i < k; i++) { combs[0][i] = i; combs[1][i] = i; } for (long i = 1; i < nCr(n, k); i++) { int p = 1; while (combs[i][k - p] == n - p) { p++; if (p > k) { break; } } combs[i][k - p]++; int q = combs[i][k - p]; for (int j = 1; j < p; j++) { combs[i][k - p + j] = q + j; } if (i < nCr(n, k) - 1) { for (int j = 0; j < k; j++) { combs[i + 1][j] = combs[i][j]; } } } return combs; } template <typename TYPE> void co(TYPE a) { cout << a << endl; } template <typename TYPE> void co_2(TYPE a, TYPE b) { cout << a << ' ' << b << endl; } template <typename TYPE> void co_l(vector<TYPE> as) { int n = as.size(); for (int i = 0; i < n; i++) { cout << as[i] << endl; } } template <typename TYPE> void co_s(vector<TYPE> as) { int n = as.size(); for (int i = 0; i < n; i++) { if (i > 0) { cout << ' '; } cout << as[i]; } cout << endl; } int main() { std::cout << std::setprecision(9); int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string str; cin >> str; vector<char> s_c(str.begin(), str.end()); int ans = 0; for (int i = 0; i < k; i++) { int rp = 0; int sp = 0; int pp = 0; for (int j = 0; j < n; j++) { int tmp_r = rp; int tmp_s = sp; int tmp_p = pp; switch (s_c[j * k + i]) { case 'r': rp = max(tmp_s, tmp_p); sp = max(tmp_p, tmp_r); pp = max(max(tmp_r, tmp_s) + p, tmp_p); break; case 's': rp = max(max(tmp_s, tmp_p) + r, tmp_r); sp = max(tmp_p, tmp_r); pp = max(tmp_r, tmp_s); break; case 'p': rp = max(tmp_s, tmp_p); sp = max(max(tmp_p, tmp_r) + s, tmp_s); pp = max(tmp_r, tmp_s); break; default: break; } } ans += max({rp, sp, pp}); } co(ans); }
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; string item; for (char ch : s) { if (ch == delim) { if (!item.empty()) { elems.push_back(item); } item.clear(); } else { item += ch; } } if (!item.empty()) { elems.push_back(item); } return elems; } string to_str_with_zero(int i, int w) { ostringstream sout; sout << std::setfill('0') << std::setw(w) << i; string s = sout.str(); return s; } int letter_to_int(char c) { return tolower(c) - 'a'; } int compare_array(vector<int> a1, vector<int> a2) { int n1 = a1.size(); int n2 = a2.size(); if (n1 != n2) { return n1 - n2; } for (int i = 0; i < n1; i++) { if (a1.at(i) != a2.at(i)) { return a1.at(i) - a2.at(i); } } return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } char int_to_char(int a) { if (a == -1) { return 'z'; } else { return 'a' + a; } } long nCr(int n, int r) { long ans = 1; for (int i = n; i > n - r; --i) { ans = ans * i; } for (int i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } 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; } int divide_count(int a, int divider) { int r = 0; while (a % divider == 0) { a /= divider; r++; } return r; } bool is_prime(int a) { int i = 2; while (i * i <= a) { if (a % i == 0) { return false; } i++; } return true; } vector<vector<int>> all_comb(int n, int k) { vector<vector<int>> combs(nCr(n, k), vector<int>(k)); for (int i = 0; i < k; i++) { combs[0][i] = i; combs[1][i] = i; } for (long i = 1; i < nCr(n, k); i++) { int p = 1; while (combs[i][k - p] == n - p) { p++; if (p > k) { break; } } combs[i][k - p]++; int q = combs[i][k - p]; for (int j = 1; j < p; j++) { combs[i][k - p + j] = q + j; } if (i < nCr(n, k) - 1) { for (int j = 0; j < k; j++) { combs[i + 1][j] = combs[i][j]; } } } return combs; } template <typename TYPE> void co(TYPE a) { cout << a << endl; } template <typename TYPE> void co_2(TYPE a, TYPE b) { cout << a << ' ' << b << endl; } template <typename TYPE> void co_l(vector<TYPE> as) { int n = as.size(); for (int i = 0; i < n; i++) { cout << as[i] << endl; } } template <typename TYPE> void co_s(vector<TYPE> as) { int n = as.size(); for (int i = 0; i < n; i++) { if (i > 0) { cout << ' '; } cout << as[i]; } cout << endl; } int main() { std::cout << std::setprecision(9); int n, k, r, s, p; cin >> n >> k >> r >> s >> p; string str; cin >> str; vector<char> s_c(str.begin(), str.end()); int ans = 0; for (int i = 0; i < k; i++) { int rp = 0; int sp = 0; int pp = 0; for (int j = 0; j * k + i < n; j++) { int tmp_r = rp; int tmp_s = sp; int tmp_p = pp; switch (s_c[j * k + i]) { case 'r': rp = max(tmp_s, tmp_p); sp = max(tmp_p, tmp_r); pp = max(max(tmp_r, tmp_s) + p, tmp_p); break; case 's': rp = max(max(tmp_s, tmp_p) + r, tmp_r); sp = max(tmp_p, tmp_r); pp = max(tmp_r, tmp_s); break; case 'p': rp = max(tmp_s, tmp_p); sp = max(max(tmp_p, tmp_r) + s, tmp_s); pp = max(tmp_r, tmp_s); break; default: break; } } ans += max({rp, sp, pp}); } co(ans); }
replace
178
179
178
179
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++) int Point(char T, int R, int S, int P) { switch (T) { case 'r': return P; case 's': return R; case 'p': return S; } } int main() { int N, K, R, S, P, sum; string T; cin >> N >> K >> R >> S >> P >> T; sum = 0; bool isWon = true; REP(i, 0, K) { int j = 0; while (i + K * j < N) { if (T[i + K * j] != T[i + K * (j + 1)] || !isWon) { sum += Point(T[i + K * j], R, S, P); if (!isWon) { isWon = !isWon; } } else { isWon = !isWon; } j++; } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++) int Point(char T, int R, int S, int P) { switch (T) { case 'r': return P; case 's': return R; case 'p': return S; } } int main() { int N, K, R, S, P, sum; string T; cin >> N >> K >> R >> S >> P >> T; sum = 0; bool isWon = true; string A(K, 'a'); T = T + A; REP(i, 0, K) { int j = 0; while (i + K * j < N) { if (T[i + K * j] != T[i + K * (j + 1)] || !isWon) { sum += Point(T[i + K * j], R, S, P); if (!isWon) { isWon = !isWon; } } else { isWon = !isWon; } j++; } } cout << sum << endl; }
replace
21
22
21
23
0
p02820
C++
Time Limit Exceeded
// atcoder/abc149/D/main.cpp // author: @___Johniel // github: https://github.com/johniel/ #include <bits/stdc++.h> #define each(i, c) for (auto &i : c) #define unless(cond) if (!(cond)) using namespace std; typedef long long int lli; typedef unsigned long long ull; typedef complex<double> point; template <typename P, typename Q> ostream &operator<<(ostream &os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename P, typename Q> istream &operator>>(istream &is, pair<P, Q> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { os << "("; each(i, v) os << i << ","; os << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(i, v) is >> i; return is; } template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); } template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; int r, s, p; string t; while (cin >> n >> k >> r >> s >> p >> t) { for (int i = 0; i < t.size(); ++i) { t[i] = toupper(t[i]); } map<char, char> win; win['P'] = 'S'; win['S'] = 'R'; win['R'] = 'P'; const int N = 1e5 + 5; static bool vis[N]; fill(vis, vis + N, false); vector<string> v; for (int i = 0; i < t.size(); ++i) { if (vis[i]) break; string x; for (int j = i; j < t.size(); j += k) { x += t[j]; vis[j] = true; } v.push_back(x); } // cout << v << endl; const int R = 0; const int P = 1; const int S = 2; const int X = 3; map<int, char> rev; rev[R] = 'R'; rev[P] = 'P'; rev[S] = 'S'; auto score = [&](char c) { if (c == R) return r; if (c == P) return p; if (c == S) return s; assert(false); }; lli sum = 0; each(x, v) { const int M = 4; static lli dp[N][M]; for (int i = 0; i < x.size() + 2; ++i) { for (int j = 0; j < M; ++j) { dp[i][j] = -(1LL << 60); } } dp[0][X] = 0; for (int i = 0; i < x.size(); ++i) { for (int last = 0; last <= 3; ++last) { if (dp[i][last] < 0) continue; for (int next = 0; next < 3; ++next) { if (last == next) continue; assert(rev[next]); if (win[x[i]] == rev[next]) { setmax(dp[i + 1][next], dp[i][last] + score(next)); } else { setmax(dp[i + 1][next], dp[i][last]); } } } } sum += *max_element(&dp[0][0], &dp[N - 1][M - 1] + 1); } cout << sum << endl; } return 0; }
// atcoder/abc149/D/main.cpp // author: @___Johniel // github: https://github.com/johniel/ #include <bits/stdc++.h> #define each(i, c) for (auto &i : c) #define unless(cond) if (!(cond)) using namespace std; typedef long long int lli; typedef unsigned long long ull; typedef complex<double> point; template <typename P, typename Q> ostream &operator<<(ostream &os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename P, typename Q> istream &operator>>(istream &is, pair<P, Q> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { os << "("; each(i, v) os << i << ","; os << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(i, v) is >> i; return is; } template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); } template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; int r, s, p; string t; while (cin >> n >> k >> r >> s >> p >> t) { for (int i = 0; i < t.size(); ++i) { t[i] = toupper(t[i]); } map<char, char> win; win['P'] = 'S'; win['S'] = 'R'; win['R'] = 'P'; const int N = 1e5 + 5; static bool vis[N]; fill(vis, vis + N, false); vector<string> v; for (int i = 0; i < t.size(); ++i) { if (vis[i]) break; string x; for (int j = i; j < t.size(); j += k) { x += t[j]; vis[j] = true; } v.push_back(x); } // cout << v << endl; const int R = 0; const int P = 1; const int S = 2; const int X = 3; map<int, char> rev; rev[R] = 'R'; rev[P] = 'P'; rev[S] = 'S'; auto score = [&](char c) { if (c == R) return r; if (c == P) return p; if (c == S) return s; assert(false); }; lli sum = 0; each(x, v) { const int M = 4; static lli dp[N][M]; for (int i = 0; i < x.size() + 2; ++i) { for (int j = 0; j < M; ++j) { dp[i][j] = -(1LL << 60); } } dp[0][X] = 0; for (int i = 0; i < x.size(); ++i) { for (int last = 0; last <= 3; ++last) { if (dp[i][last] < 0) continue; for (int next = 0; next < 3; ++next) { if (last == next) continue; assert(rev[next]); if (win[x[i]] == rev[next]) { setmax(dp[i + 1][next], dp[i][last] + score(next)); } else { setmax(dp[i + 1][next], dp[i][last]); } } } } lli mx = 0; for (int i = 0; i < x.size() + 2; ++i) { for (int j = 0; j < M; ++j) { setmax(mx, dp[i][j]); } } sum += mx; } cout << sum << endl; } return 0; }
replace
121
122
121
128
TLE
p02820
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <limits> #include <math.h> #include <stdio.h> #include <string> #include <vector> using namespace std; const long long INF = 1LL << 60; // 各桁の和を出力 long long Sum(long long n) { long long m = 0; while (n) { m += n % 10; n /= 10; } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } #define comuse Comuse() // nCk(comuseを使え) long long combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // pCk(comuseを使え) long long perm(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] % MOD) % MOD; } // 最小公倍数(aとbの) long long lcm(long long a, long long b) { long long n; n = a / __gcd(a, b) * b; return n; } // auto A = div(n) vector<long long> div(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) { ret.push_back(n / i); } } } sort(ret.begin(), ret.end()); return ret; } //(aのn乗をmodで割ったあまり) long long modpow(long long a, long long n, long long mod) { long long ans = 1; while (n > 0) { if (n & 1) { ans = ans * a % mod; } a = a * a % mod; n >>= 1; } return ans; } void solve(); const int MAX_N = 131072; // segment tree int NN; int seg[MAX_N * 2 - 1]; void seguse() { for (int i = 0; i < 2 * NN - 1; i++) { seg[i] = INT_MAX; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; solve(); } /////////////////////////////////////////////////////////// int N; int K; int R; int S; int P; string T; string Note; void solve() { cin >> N >> K >> R >> S >> P >> T; long long ans = 0; for (int i = 0; i < K; i++) { if (T[i] == 'r') { ans += P; Note[i] = 'r'; } else if (T[i] == 's') { ans += R; Note[i] = 's'; } else if (T[i] == 'p') { ans += S; Note[i] = 'p'; } } for (int i = K; i < N; i++) { if (T[i] == 'r' && Note[i - K] != 'r') { ans += P; Note[i] = 'r'; } else if (T[i] == 's' && Note[i - K] != 's') { ans += R; Note[i] = 's'; } else if (T[i] == 'p' && Note[i - K] != 'p') { ans += S; Note[i] = 'p'; } else { Note[i] = 'n'; } } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <limits> #include <math.h> #include <stdio.h> #include <string> #include <vector> using namespace std; const long long INF = 1LL << 60; // 各桁の和を出力 long long Sum(long long n) { long long m = 0; while (n) { m += n % 10; n /= 10; } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } #define comuse Comuse() // nCk(comuseを使え) long long combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // pCk(comuseを使え) long long perm(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] % MOD) % MOD; } // 最小公倍数(aとbの) long long lcm(long long a, long long b) { long long n; n = a / __gcd(a, b) * b; return n; } // auto A = div(n) vector<long long> div(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) { ret.push_back(n / i); } } } sort(ret.begin(), ret.end()); return ret; } //(aのn乗をmodで割ったあまり) long long modpow(long long a, long long n, long long mod) { long long ans = 1; while (n > 0) { if (n & 1) { ans = ans * a % mod; } a = a * a % mod; n >>= 1; } return ans; } void solve(); const int MAX_N = 131072; // segment tree int NN; int seg[MAX_N * 2 - 1]; void seguse() { for (int i = 0; i < 2 * NN - 1; i++) { seg[i] = INT_MAX; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; solve(); } /////////////////////////////////////////////////////////// int N; int K; int R; int S; int P; string T; string Note(1000000, ' '); void solve() { cin >> N >> K >> R >> S >> P >> T; long long ans = 0; for (int i = 0; i < K; i++) { if (T[i] == 'r') { ans += P; Note[i] = 'r'; } else if (T[i] == 's') { ans += R; Note[i] = 's'; } else if (T[i] == 'p') { ans += S; Note[i] = 'p'; } } for (int i = K; i < N; i++) { if (T[i] == 'r' && Note[i - K] != 'r') { ans += P; Note[i] = 'r'; } else if (T[i] == 's' && Note[i - K] != 's') { ans += R; Note[i] = 's'; } else if (T[i] == 'p' && Note[i - K] != 'p') { ans += S; Note[i] = 'p'; } else { Note[i] = 'n'; } } cout << ans << endl; }
replace
125
126
125
126
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, r, s, p; string t; cin >> n >> k >> r >> s >> p >> t; long long sum = 0; for (int i = 0; i < t.size(); i++) { if (t[i] == 'r') sum += p; else if (t[i] == 's') sum += r; else sum += s; } for (int i = 0; i < t.size(); i++) { if (t[i] == 'r' && t[i + k] == 'r') { sum -= p; t[i + k] = 'a'; } else if (t[i] == 's' && t[i + k] == 's') { sum -= r; t[i + k] = 'b'; } else if (t[i] == 'p' && t[i + k] == 'p') { sum -= s; t[i + k] = 'c'; } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, r, s, p; string t; cin >> n >> k >> r >> s >> p >> t; long long sum = 0; for (int i = 0; i < t.size(); i++) { if (t[i] == 'r') sum += p; else if (t[i] == 's') sum += r; else sum += s; } for (int i = 0; i < t.size() - k; i++) { if (t[i] == 'r' && t[i + k] == 'r') { sum -= p; t[i + k] = 'a'; } else if (t[i] == 's' && t[i + k] == 's') { sum -= r; t[i + k] = 'b'; } else if (t[i] == 'p' && t[i + k] == 'p') { sum -= s; t[i + k] = 'c'; } } cout << sum << endl; return 0; }
replace
16
17
16
17
0
p02820
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main(void) { long long N, K, R, S, P, i, i2, count, ans = 0, Rdec = 0, Sdec = 0, Pdec = 0, check[100000]; char T[100000], U; cin >> N >> K >> R >> S >> P >> T; for (i = 0; i < N; i++) { check[i] = 0; } for (i = 0; i < N; i++) { i2 = i; if (T[i] == T[i + K]) { count = 0; while (i + K < N && T[i] == T[i + K] && check[i] == 0) { U = T[i]; check[i] = 1; i += K; count++; } if (count % 2 == 0) { if (U == 'r') { ans -= P * count / 2; } else if (U == 's') { ans -= R * count / 2; } else { ans -= S * count / 2; } } else { if (U == 'r') { ans -= P * (count / 2 + 1); } else if (U == 's') { ans -= R * (count / 2 + 1); } else { ans -= S * (count / 2 + 1); } } } i = i2; } for (i = 0; i < N; i++) { if (T[i] == 'r') { ans += P; } else if (T[i] == 's') { ans += R; } else { ans += S; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main(void) { long long N, K, R, S, P, i, i2, count, ans = 0, Rdec = 0, Sdec = 0, Pdec = 0, check[1000000]; char T[1000000], U; cin >> N >> K >> R >> S >> P >> T; for (i = 0; i < N; i++) { check[i] = 0; } for (i = 0; i < N; i++) { i2 = i; if (T[i] == T[i + K]) { count = 0; while (i + K < N && T[i] == T[i + K] && check[i] == 0) { U = T[i]; check[i] = 1; i += K; count++; } if (count % 2 == 0) { if (U == 'r') { ans -= P * count / 2; } else if (U == 's') { ans -= R * count / 2; } else { ans -= S * count / 2; } } else { if (U == 'r') { ans -= P * (count / 2 + 1); } else if (U == 's') { ans -= R * (count / 2 + 1); } else { ans -= S * (count / 2 + 1); } } } i = i2; } for (i = 0; i < N; i++) { if (T[i] == 'r') { ans += P; } else if (T[i] == 's') { ans += R; } else { ans += S; } } cout << ans << endl; return 0; }
replace
11
13
11
13
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int main() { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; string T; cin >> T; vector<char> cnt(N); ll res = 0; for (int i = 0; i < N; ++i) { ll ans = 0; if (T[i] == 'r') { cnt[i] = 'p'; ans = P; } else if (T[i] == 's') { cnt[i] = 'r'; ans = R; } else if (T[i] == 'p') { cnt[i] = 's'; ans = S; } if (cnt[i - K] == cnt[i] && i >= K) { cnt[i] = 'a'; ans = 0; } res += ans; // cout << cnt[i] << " " << cnt[i - K] << " " << (cnt[i] == cnt[i - K]) << " // " << T[i] << endl; cout << res << endl; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int main() { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; string T; cin >> T; vector<char> cnt(N); ll res = 0; for (int i = 0; i < N; ++i) { ll ans = 0; if (T[i] == 'r') { cnt[i] = 'p'; ans = P; } else if (T[i] == 's') { cnt[i] = 'r'; ans = R; } else if (T[i] == 'p') { cnt[i] = 's'; ans = S; } if (i >= K) { if (cnt[i - K] == cnt[i]) { cnt[i] = 'a'; ans = 0; } } res += ans; // cout << cnt[i] << " " << cnt[i - K] << " " << (cnt[i] == cnt[i - K]) << " // " << T[i] << endl; cout << res << endl; } cout << res << endl; }
replace
31
34
31
37
0
p02820
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { ll N, K; cin >> N >> K; ll R, S, P; cin >> R >> S >> P; string s; cin >> s; // 勝てる数を手ごとに保存 vector<ll> v(3); rep(i, K) { ll prev = 3; // iはそれぞれの先頭 for (int j = 0; j < N; j += K) { // cout<<i+j<<endl; // jはkことばし if (s[i + j] == 'r') { // paper win if (prev != 0) { v[2]++; prev = 0; } else prev = 3; } else if (s[i + j] == 's') { // rock win if (prev != 1) { v[0]++; prev = 1; } else prev = 3; } else { // scissors win if (prev != 2) { v[1]++; prev = 2; } else prev = 3; } } } ll ans = 0; // rep(i,3)cout<<v[i]<<endl; ans += v[0] * R + v[1] * S + v[2] * P; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { ll N, K; cin >> N >> K; ll R, S, P; cin >> R >> S >> P; string s; cin >> s; // 勝てる数を手ごとに保存 vector<ll> v(3); rep(i, K) { ll prev = 3; // iはそれぞれの先頭 for (int j = 0; i + j < N; j += K) { // cout<<i+j<<endl; // jはkことばし if (s[i + j] == 'r') { // paper win if (prev != 0) { v[2]++; prev = 0; } else prev = 3; } else if (s[i + j] == 's') { // rock win if (prev != 1) { v[0]++; prev = 1; } else prev = 3; } else { // scissors win if (prev != 2) { v[1]++; prev = 2; } else prev = 3; } } } ll ans = 0; // rep(i,3)cout<<v[i]<<endl; ans += v[0] * R + v[1] * S + v[2] * P; cout << ans << endl; }
replace
45
46
45
46
0
p02820
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define FORR(i, m, n) for (ll i = m; i >= n; i--) #define REPO(i, n) for (ll i = 1; i <= n; i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(), n.end() #define MOD 1000000007 #define P pair<ll, ll> ll n, m, r[3], ans, t[110000]; string s; int main() { cin >> n >> m; REP(i, 3) cin >> r[i]; cin >> s; REP(i, n) { if (s[i] == 'r') t[i] = 1; if (s[i] == 's') t[i] = 2; if (s[i] == 'p') t[i] = 3; } REP(i, m) { ll dp[110000][3] = {}; ll j = 0; ll now = i; while (now < n) { REP(k, 3) { REP(l, 3) { if (k == l) continue; if ((l - t[now] + 3) % 3 == 1) { dp[j + 1][l] = max(dp[j + 1][l], dp[j][k] + r[l]); } else dp[j + 1][l] = max(dp[j + 1][l], dp[j][k]); } } now += m; j++; } ll t = 0; REP(l, 3) t = max(t, dp[j][l]); ans += t; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define FORR(i, m, n) for (ll i = m; i >= n; i--) #define REPO(i, n) for (ll i = 1; i <= n; i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(), n.end() #define MOD 1000000007 #define P pair<ll, ll> ll n, m, r[3], ans, t[110000]; string s; int main() { cin >> n >> m; REP(i, 3) cin >> r[i]; cin >> s; REP(i, n) { if (s[i] == 'r') t[i] = 1; if (s[i] == 's') t[i] = 2; if (s[i] == 'p') t[i] = 3; } REP(i, m) { vector<vector<ll>> dp(n / m + 10, vector<ll>(3)); ll j = 0; ll now = i; while (now < n) { REP(k, 3) { REP(l, 3) { if (k == l) continue; if ((l - t[now] + 3) % 3 == 1) { dp[j + 1][l] = max(dp[j + 1][l], dp[j][k] + r[l]); } else dp[j + 1][l] = max(dp[j + 1][l], dp[j][k]); } } now += m; j++; } ll t = 0; REP(l, 3) t = max(t, dp[j][l]); ans += t; } cout << ans << endl; }
replace
45
46
45
46
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = int64_t; ll N, K, R, S, P; string T; array<vector<ll>, 3> memo = {vector<ll>(100000, -1), vector<ll>(100000, -1), vector<ll>(100000, -1)}; array<char, 256> c2i; ll dfs(char hand, int index, int a) { if (index * K >= N) { return 0; } auto hand_index = index * K + a; auto &memo_r = memo[c2i[hand]][hand_index]; if (memo_r != -1) { return memo_r; } auto enemy_hand = T[hand_index]; ll score = 0; if (hand == 'r') { if (enemy_hand == 's') { score += R; } score += max(dfs('s', index + 1, a), dfs('p', index + 1, a)); } if (hand == 's') { if (enemy_hand == 'p') { score += S; } score += max(dfs('r', index + 1, a), dfs('p', index + 1, a)); } if (hand == 'p') { if (enemy_hand == 'r') { score += P; } score += max(dfs('r', index + 1, a), dfs('s', index + 1, a)); } memo_r = score; return score; } void main_() { cin >> N >> K >> R >> S >> P; cin >> T; c2i['r'] = 0; c2i['s'] = 1; c2i['p'] = 2; ll ans = 0; for (ll i = 0; i < K; ++i) { ans += max({ dfs('r', 0, i), dfs('s', 0, i), dfs('p', 0, i), }); } cout << ans << endl; } int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); main_(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; ll N, K, R, S, P; string T; array<vector<ll>, 3> memo = {vector<ll>(100000, -1), vector<ll>(100000, -1), vector<ll>(100000, -1)}; array<char, 256> c2i; ll dfs(char hand, int index, int a) { if (index * K + a >= N) { return 0; } auto hand_index = index * K + a; auto &memo_r = memo[c2i[hand]][hand_index]; if (memo_r != -1) { return memo_r; } auto enemy_hand = T[hand_index]; ll score = 0; if (hand == 'r') { if (enemy_hand == 's') { score += R; } score += max(dfs('s', index + 1, a), dfs('p', index + 1, a)); } if (hand == 's') { if (enemy_hand == 'p') { score += S; } score += max(dfs('r', index + 1, a), dfs('p', index + 1, a)); } if (hand == 'p') { if (enemy_hand == 'r') { score += P; } score += max(dfs('r', index + 1, a), dfs('s', index + 1, a)); } memo_r = score; return score; } void main_() { cin >> N >> K >> R >> S >> P; cin >> T; c2i['r'] = 0; c2i['s'] = 1; c2i['p'] = 2; ll ans = 0; for (ll i = 0; i < K; ++i) { ans += max({ dfs('r', 0, i), dfs('s', 0, i), dfs('p', 0, i), }); } cout << ans << endl; } int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); main_(); return 0; }
replace
12
13
12
13
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 100005; // ll dp[MAX_N][3]={0}; ll subans[MAX_N]; int main(void) { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; vector<string> machine(K, ""); for (int i = 0, j = 0; i < N; i++, j++) { char c; cin >> c; machine[j] += c; if (j == K - 1) j = -1; } for (int k = 0; k < K; k++) { vector<vector<ll>> dp(N / 3 + 1, vector<ll>(3, 0)); int last = machine[k].size(); for (int i = 0; i < last; i++) { if (machine[k][i] == 's') { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1] + R, dp[i][2] + R)); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0], dp[i][2])); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1], dp[i][0])); } else if (machine[k][i] == 'p') { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1], dp[i][2])); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0] + S, dp[i][2] + S)); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1], dp[i][0])); } else { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1], dp[i][2])); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0], dp[i][2])); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1] + P, dp[i][0] + P)); } } subans[k] = max(dp[last][0], dp[last][1]); subans[k] = max(subans[k], dp[last][2]); } ll ans = 0; for (int i = 0; i < K; i++) { ans += subans[i]; // cout << subans[i] << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 100005; // ll dp[MAX_N][3]={0}; ll subans[MAX_N]; int main(void) { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; vector<string> machine(K, ""); for (int i = 0, j = 0; i < N; i++, j++) { char c; cin >> c; machine[j] += c; if (j == K - 1) j = -1; } for (int k = 0; k < K; k++) { vector<vector<ll>> dp(N / K + 3, vector<ll>(3, 0)); int last = machine[k].size(); for (int i = 0; i < last; i++) { if (machine[k][i] == 's') { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1] + R, dp[i][2] + R)); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0], dp[i][2])); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1], dp[i][0])); } else if (machine[k][i] == 'p') { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1], dp[i][2])); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0] + S, dp[i][2] + S)); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1], dp[i][0])); } else { dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1], dp[i][2])); dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0], dp[i][2])); dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][1] + P, dp[i][0] + P)); } } subans[k] = max(dp[last][0], dp[last][1]); subans[k] = max(subans[k], dp[last][2]); } ll ans = 0; for (int i = 0; i < K; i++) { ans += subans[i]; // cout << subans[i] << endl; } cout << ans << endl; }
replace
24
25
24
25
-11
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll cnt[100010]; int main() { ll n, k; cin >> n >> k; ll r, s, p; cin >> r >> s >> p; string t; cin >> t; for (ll i = 0; i < n; i++) { char now = t[i]; if (cnt[i - k] != 0 && i - k >= 0) { if (t[i - k] == now) { continue; } } if (now == 'r') { cnt[i] = p; } else if (now == 's') { cnt[i] = r; } else { cnt[i] = s; } } ll ans = 0; for (ll i = 0; i < n; i++) { ans += cnt[i]; } cout << ans; // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll cnt[100010]; int main() { ll n, k; cin >> n >> k; ll r, s, p; cin >> r >> s >> p; string t; cin >> t; for (ll i = 0; i < n; i++) { char now = t[i]; if (i - k >= 0) { if (cnt[i - k] != 0 && t[i - k] == now) { continue; } } if (now == 'r') { cnt[i] = p; } else if (now == 's') { cnt[i] = r; } else { cnt[i] = s; } } ll ans = 0; for (ll i = 0; i < n; i++) { ans += cnt[i]; } cout << ans; // your code goes here return 0; }
replace
16
18
16
18
0
p02820
C++
Runtime Error
#ifndef LOCAL #pragma GCC optimize("O3") #endif #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define sim template <class c #define int long long #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << '\n'; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; const ll MOD = 1e9 + 7; const ll N = 2e5 + 10; const ll INF = 1e18 + 10; int m; int R, P, S; string s; vector<int> cost(4); vector<vector<int>> dp; int n, k; int dfs(int x, int cur) { if (x == m) { return 0; } if (dp[x][cur] != -1) return dp[x][cur]; int ans = 0; for (int c : {1, 2, 3}) { if (c != cur) { if (s[x] == 'r') { if (c == 3) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } else if (s[x] == 's') { if (c == 1) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } else if (s[x] == 'p') { if (c == 2) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } } } return dp[x][cur] = ans; } int solve() { m = (int)s.size(); dp = vector<vector<int>>((n + k - 1) / 2, vector<int>(4, -1)); return dfs(0, 0); } signed main() { fastio cin >> n >> k; cin >> R >> S >> P; cost[1] = R, cost[2] = S, cost[3] = P; string t; cin >> t; int ans = 0; for (int i = 0; i < k; i++) { s = ""; for (int j = i; j < n; j += k) { s.push_back(t[j]); } ans += solve(); } cout << ans << endl; return 0; }
#ifndef LOCAL #pragma GCC optimize("O3") #endif #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define sim template <class c #define int long long #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << '\n'; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; const ll MOD = 1e9 + 7; const ll N = 2e5 + 10; const ll INF = 1e18 + 10; int m; int R, P, S; string s; vector<int> cost(4); vector<vector<int>> dp; int n, k; int dfs(int x, int cur) { if (x == m) { return 0; } if (dp[x][cur] != -1) return dp[x][cur]; int ans = 0; for (int c : {1, 2, 3}) { if (c != cur) { if (s[x] == 'r') { if (c == 3) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } else if (s[x] == 's') { if (c == 1) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } else if (s[x] == 'p') { if (c == 2) ans = max(ans, cost[c] + dfs(x + 1, c)); else ans = max(ans, dfs(x + 1, c)); } } } return dp[x][cur] = ans; } int solve() { m = (int)s.size(); dp = vector<vector<int>>(m, vector<int>(4, -1)); return dfs(0, 0); } signed main() { fastio cin >> n >> k; cin >> R >> S >> P; cost[1] = R, cost[2] = S, cost[3] = P; string t; cin >> t; int ans = 0; for (int i = 0; i < k; i++) { s = ""; for (int j = i; j < n; j += k) { s.push_back(t[j]); } ans += solve(); } cout << ans << endl; return 0; }
replace
91
92
91
92
0
p02820
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) typedef long long ll; long long MOD = 1e9 + 7; const long long INF = 1LL << 60; using namespace std; 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; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; string t_sub[k]; rep(i, n) { int mod = i % k; t_sub[mod] += t[i]; } ll ans = 0; rep(i, k) { string t_tmp = t_sub[i]; // dp[i][j]: i回目にjを出した時にi回目までに得られる最高得点 ll dp[100010][3] = {0}; // 0: グー, 1: チョキ, 2: パー repi(j, 1, t_tmp.size() + 1) { if (t_tmp[j - 1] == 'r') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]) + p; } else if (t_tmp[j - 1] == 's') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]) + r; dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); } else if (t_tmp[j - 1] == 'p') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]) + s; dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); } } ans += max(dp[t_tmp.size()][0], max(dp[t_tmp.size()][1], dp[t_tmp.size()][2])); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) typedef long long ll; long long MOD = 1e9 + 7; const long long INF = 1LL << 60; using namespace std; 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; } int main() { int n, k; cin >> n >> k; int r, s, p; cin >> r >> s >> p; string t; cin >> t; string t_sub[k]; rep(i, n) { int mod = i % k; t_sub[mod] += t[i]; } ll ans = 0; rep(i, k) { string t_tmp = t_sub[i]; // dp[i][j]: i回目にjを出した時にi回目までに得られる最高得点 int dp[100010][3]; dp[0][0] = 0; // 0: グー, 1: チョキ, 2: パー dp[0][1] = 0; // 0: グー, 1: チョキ, 2: パー dp[0][2] = 0; // 0: グー, 1: チョキ, 2: パー repi(j, 1, t_tmp.size() + 1) { if (t_tmp[j - 1] == 'r') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]) + p; } else if (t_tmp[j - 1] == 's') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]) + r; dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]); dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); } else if (t_tmp[j - 1] == 'p') { dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]); dp[j][1] = max(dp[j - 1][2], dp[j - 1][0]) + s; dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]); } } ans += max(dp[t_tmp.size()][0], max(dp[t_tmp.size()][1], dp[t_tmp.size()][2])); } cout << ans << endl; return 0; }
replace
44
45
44
48
TLE
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) #define ALL(obj) (obj).begin(), (obj).end() #define MOD 1000000007 #define INF 1000000000 void solve_abc149_d() { ll N, K; ll p[3] = {0}; string T; ll P, Q, R; ll ans = 0; cin >> N >> K; cin >> p[0] >> p[1] >> p[2]; cin >> T; ll cnt = 0; ll v = 0; vector<char> L[10001]; rep(i, N) { // 勝ちとなる手 if (T[i] == 'r') v = 2; else if (T[i] == 's') v = 0; else if (T[i] == 'p') v = 1; L[cnt].push_back(v); cnt++; if (cnt == K) { cnt = 0; } } ans = 0; rep(i, K) { ans += p[L[i][0]]; rep2(j, 1, L[i].size()) { if ((L[i][j] != L[i][j - 1]) || L[i][j - 1] == -1) { ans += p[L[i][j]]; } else { L[i][j] = -1; } } } cout << ans << "\n"; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); solve_abc149_d(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) #define ALL(obj) (obj).begin(), (obj).end() #define MOD 1000000007 #define INF 1000000000 void solve_abc149_d() { ll N, K; ll p[3] = {0}; string T; ll P, Q, R; ll ans = 0; cin >> N >> K; cin >> p[0] >> p[1] >> p[2]; cin >> T; ll cnt = 0; ll v = 0; vector<char> L[100001]; rep(i, N) { // 勝ちとなる手 if (T[i] == 'r') v = 2; else if (T[i] == 's') v = 0; else if (T[i] == 'p') v = 1; L[cnt].push_back(v); cnt++; if (cnt == K) { cnt = 0; } } ans = 0; rep(i, K) { ans += p[L[i][0]]; rep2(j, 1, L[i].size()) { if ((L[i][j] != L[i][j - 1]) || L[i][j - 1] == -1) { ans += p[L[i][j]]; } else { L[i][j] = -1; } } } cout << ans << "\n"; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); solve_abc149_d(); return 0; }
replace
28
29
28
29
0
p02820
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAXN = 501; const int MAXM = 3; int n, k, r, s, p; int dp[MAXM][MAXN], cost[MAXM]; char arr[MAXN]; int getCost(int a, int b) { if ((a + 1) % MAXM == b) return cost[a]; else return 0; } int getNum(char c) { if (c == 'r') return 0; else if (c == 's') return 1; else return 2; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < 3; i++) { cin >> cost[i]; } for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { int tmp = i - k; int cur = getNum(arr[i]); for (int j = 0; j < 3; j++) { if (tmp < 0) { dp[j][i] = getCost(j, cur); } else { for (int t = 0; t < 3; t++) { if (j == t) continue; dp[j][i] = max(dp[j][i], dp[t][i - k] + getCost(j, cur)); } } } } int ans = 0; for (int i = n - 1; i >= max(n - k, 0); i--) { int sum = 0; for (int j = 0; j < 3; j++) { sum = max(sum, dp[j][i]); } ans += sum; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1; const int MAXM = 3; int n, k, r, s, p; int dp[MAXM][MAXN], cost[MAXM]; char arr[MAXN]; int getCost(int a, int b) { if ((a + 1) % MAXM == b) return cost[a]; else return 0; } int getNum(char c) { if (c == 'r') return 0; else if (c == 's') return 1; else return 2; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < 3; i++) { cin >> cost[i]; } for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { int tmp = i - k; int cur = getNum(arr[i]); for (int j = 0; j < 3; j++) { if (tmp < 0) { dp[j][i] = getCost(j, cur); } else { for (int t = 0; t < 3; t++) { if (j == t) continue; dp[j][i] = max(dp[j][i], dp[t][i - k] + getCost(j, cur)); } } } } int ans = 0; for (int i = n - 1; i >= max(n - k, 0); i--) { int sum = 0; for (int j = 0; j < 3; j++) { sum = max(sum, dp[j][i]); } ans += sum; } cout << ans << "\n"; return 0; }
replace
4
5
4
5
0
p02820
C++
Runtime Error
// Give me My Shotgun #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define PB push_back #define F first #define S second #define _sz(x) (int)x.size() #define debug(x) cerr << #x << " = " << x << endl typedef long long ll; typedef pair<int, int> pii; const int MAX_N = -1; const int inf = 2e9 + 19; ll n, k, r, p, s; string T, S; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; cin >> r >> s >> p; cin >> T; ll ans = 0; for (int i = 0; i < k; i++) { if (T[i] == 'r') S[i] = 'p', ans += p; if (T[i] == 'p') S[i] = 's', ans += s; if (T[i] == 's') S[i] = 'r', ans += r; } for (int i = k; i < n; i++) { if (T[i] == 'r') if (S[i - k] != 'p') ans += p, S[i] = 'p'; if (T[i] == 's') if (S[i - k] != 'r') ans += r, S[i] = 'r'; if (T[i] == 'p') if (S[i - k] != 's') ans += s, S[i] = 's'; } cout << ans; return (0); }
// Give me My Shotgun #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define PB push_back #define F first #define S second #define _sz(x) (int)x.size() #define debug(x) cerr << #x << " = " << x << endl typedef long long ll; typedef pair<int, int> pii; const int MAX_N = -1; const int inf = 2e9 + 19; ll n, k, r, p, s; string T, S; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; cin >> r >> s >> p; cin >> T; ll ans = 0; string tmp = "x"; for (int i = 0; i < n; i++) S += tmp; for (int i = 0; i < k; i++) { if (T[i] == 'r') S[i] = 'p', ans += p; if (T[i] == 'p') S[i] = 's', ans += s; if (T[i] == 's') S[i] = 'r', ans += r; } for (int i = k; i < n; i++) { if (T[i] == 'r') if (S[i - k] != 'p') ans += p, S[i] = 'p'; if (T[i] == 's') if (S[i - k] != 'r') ans += r, S[i] = 'r'; if (T[i] == 'p') if (S[i - k] != 's') ans += s, S[i] = 's'; } cout << ans; return (0); }
insert
29
29
29
32
0