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
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct iofix { ios_base::Init i; iofix() { cin.sync_with_stdio(0); cin.tie(0); cout.sync_with_stdio(0); cout.tie(0); cout.precision(10); cout << fixed; } } iofix; void solve() { int N; cin >> N; vector<int64_t> dp(3, 0); for (int i = 0; i < N; ++i) { vector<int64_t> cost(3); for (int c = 0; c < N; ++c) cin >> cost[c]; vector<int64_t> new_dp(3, 0); for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j != k) new_dp[k] = max(new_dp[k], dp[j] + cost[k]); } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}) << "\n"; } int main() { solve(); #ifndef Time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; struct iofix { ios_base::Init i; iofix() { cin.sync_with_stdio(0); cin.tie(0); cout.sync_with_stdio(0); cout.tie(0); cout.precision(10); cout << fixed; } } iofix; void solve() { int N; cin >> N; vector<int64_t> dp(3, 0); for (int i = 0; i < N; ++i) { vector<int64_t> cost(3); for (int c = 0; c < 3; ++c) cin >> cost[c]; vector<int64_t> new_dp(3, 0); for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j != k) new_dp[k] = max(new_dp[k], dp[j] + cost[k]); } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}) << "\n"; } int main() { solve(); #ifndef Time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
replace
20
21
20
21
0
Time elapsed: 0.032898 s.
p03162
C++
Runtime Error
#include <bits/stdc++.h> #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 repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n; cin >> n; vector<vector<int>> abc(100010, vector<int>(3)); reps(i, n) cin >> abc.at(i).at(0) >> abc.at(i).at(1) >> abc.at(i).at(2); vector<vector<int>> dp( 10010, vector<int>(3, 0)); // dp[i][j]->iๆ—ฅ็›ฎใพใงใฎๅนธ็ฆๅบฆใฎ็ทๅ’Œใฎmax,iๆ—ฅ็›ฎใฎๆดปๅ‹•ใฏj rep(i, n) { rep(j, 3) { rep(k, 3) { if (k == j) continue; dp.at(i + 1).at(k) = max(dp.at(i + 1).at(k), dp.at(i).at(j) + abc.at(i + 1).at(k)); } } } int ans = -1; rep(i, 3) ans = max(ans, dp.at(n).at(i)); cout << ans << endl; }
#include <bits/stdc++.h> #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 repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n; cin >> n; vector<vector<int>> abc(100010, vector<int>(3)); reps(i, n) cin >> abc.at(i).at(0) >> abc.at(i).at(1) >> abc.at(i).at(2); vector<vector<int>> dp( 100010, vector<int>(3, 0)); // dp[i][j]->iๆ—ฅ็›ฎใพใงใฎๅนธ็ฆๅบฆใฎ็ทๅ’Œใฎmax,iๆ—ฅ็›ฎใฎๆดปๅ‹•ใฏj rep(i, n) { rep(j, 3) { rep(k, 3) { if (k == j) continue; dp.at(i + 1).at(k) = max(dp.at(i + 1).at(k), dp.at(i).at(j) + abc.at(i + 1).at(k)); } } } int ans = -1; rep(i, 3) ans = max(ans, dp.at(n).at(i)); cout << ans << endl; }
replace
15
16
15
16
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define f0(i, n) for (long long int i = 0; i < n; i++) #define f1(i, n) for (long long int i = 1; i <= n; i++) #define f2(i, a, b) for (long long int i = a; i <= b; i++) #define sp << " " // giving space #define sp1 << " " << // giving space between two elements #define nl << "/n" // new line #define MOD 1000000007 // for mod #define ll long long #define ld long double using namespace std; // Vector #define vi vector<int> // integer vector #define vll vector<long long> // long long vector #define pb(v, i) v.push_back(i) // vector element insertion #define er(v, i) v.erase(v.begin() + i) // erase ith element in a vector #define erng(v, x) v.erase(v.begin(), v.begin() + x) // delete a range in array #define av(first, last, sum) accumulate(first, last, sum) // sum of vector #define vmax(v, x) *max_element(v, v + x) // max element in vector #define vmin(v, x) *min_element(v, v + x) // min element in vector #define sv(v) sort(v.begin(), v.end()) // sort complete vector #define svx(v, x) sort(v.begin(), v.begin() + x) // sort partial vector #define low(v, x) \ *lower_bound(v.begin(), v.end(), x) // lower bound of a number in vector #define up(v, x) \ *upper_bound(v.begin(), v.end(), x) // upper bound of a number in vector // Stack /* stack<int> s; //declaring stack s.push(1) // enter element in stack s.top() //returns top element in stack s.pop() //removes top element in stack */ // pair #define pii pair<int, int> // pair integers #define F first #define S second #define mp(a, b) \ make_pair(a, b) // entering pair element in vector(size not defined) // Hashmap /* map<string,string> a; //declaration a[โ€œabcโ€]=โ€xyzโ€; // element entry in map; gquiz1.insert(pair<int, int>(1, 40)); map<string,string>::iterator itr; //iterating map for (itr = a.begin(); itr!=a.end(); itr++){ cout <<(*itr).first << itr->second <<endl; } itr = companies.find("abc"); //finding element in map cout << itz->second; //*/ // FUNCTION TO FIND PRIME /*bool is_prime(int p){ for(int i = 2; i*i <= p; i++){ if(p % i == 0) return false; } return true; } */ /* //DSU by path compression using size int parent[100005]; int siz[100005]; bool vis[100005]; int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void make_set(int v) { parent[v] = v; siz[v] = 1; vis[v]=1; } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (siz[a] < siz[b]) swap(a, b); parent[b] = a; siz[a] += siz[b]; } } */ /* // DFS FUNCTION vector<int> graph[100005]; bool vis[100005]; void add_edge(int u,int v){ pb(graph[u],v); pb(graph[v],u); } void dfs(int i) { vis[i]=1; for(auto j : graph[i]) { if(!vis[j]) dfs(j); } } */ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, d, e, f; cin >> n; vector<ll> a(n), b(n), c(n); f0(i, n) cin >> a[i] >> b[i] >> c[i]; f0(i, n) { d = a[i]; e = b[i]; f = c[i]; if (i == n - 1) break; a[i + 1] = max(e + a[i + 1], f + a[i + 1]); b[i + 1] = max(d + b[i + 1], f + b[i + 1]); c[i + 1] = max(d + c[i + 1], e + c[i + 1]); } cout << max(d, max(e, f)); return 0; }
#include <bits/stdc++.h> #define f0(i, n) for (long long int i = 0; i < n; i++) #define f1(i, n) for (long long int i = 1; i <= n; i++) #define f2(i, a, b) for (long long int i = a; i <= b; i++) #define sp << " " // giving space #define sp1 << " " << // giving space between two elements #define nl << "/n" // new line #define MOD 1000000007 // for mod #define ll long long #define ld long double using namespace std; // Vector #define vi vector<int> // integer vector #define vll vector<long long> // long long vector #define pb(v, i) v.push_back(i) // vector element insertion #define er(v, i) v.erase(v.begin() + i) // erase ith element in a vector #define erng(v, x) v.erase(v.begin(), v.begin() + x) // delete a range in array #define av(first, last, sum) accumulate(first, last, sum) // sum of vector #define vmax(v, x) *max_element(v, v + x) // max element in vector #define vmin(v, x) *min_element(v, v + x) // min element in vector #define sv(v) sort(v.begin(), v.end()) // sort complete vector #define svx(v, x) sort(v.begin(), v.begin() + x) // sort partial vector #define low(v, x) \ *lower_bound(v.begin(), v.end(), x) // lower bound of a number in vector #define up(v, x) \ *upper_bound(v.begin(), v.end(), x) // upper bound of a number in vector // Stack /* stack<int> s; //declaring stack s.push(1) // enter element in stack s.top() //returns top element in stack s.pop() //removes top element in stack */ // pair #define pii pair<int, int> // pair integers #define F first #define S second #define mp(a, b) \ make_pair(a, b) // entering pair element in vector(size not defined) // Hashmap /* map<string,string> a; //declaration a[โ€œabcโ€]=โ€xyzโ€; // element entry in map; gquiz1.insert(pair<int, int>(1, 40)); map<string,string>::iterator itr; //iterating map for (itr = a.begin(); itr!=a.end(); itr++){ cout <<(*itr).first << itr->second <<endl; } itr = companies.find("abc"); //finding element in map cout << itz->second; //*/ // FUNCTION TO FIND PRIME /*bool is_prime(int p){ for(int i = 2; i*i <= p; i++){ if(p % i == 0) return false; } return true; } */ /* //DSU by path compression using size int parent[100005]; int siz[100005]; bool vis[100005]; int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void make_set(int v) { parent[v] = v; siz[v] = 1; vis[v]=1; } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (siz[a] < siz[b]) swap(a, b); parent[b] = a; siz[a] += siz[b]; } } */ /* // DFS FUNCTION vector<int> graph[100005]; bool vis[100005]; void add_edge(int u,int v){ pb(graph[u],v); pb(graph[v],u); } void dfs(int i) { vis[i]=1; for(auto j : graph[i]) { if(!vis[j]) dfs(j); } } */ int main() { ll n, d, e, f; cin >> n; vector<ll> a(n), b(n), c(n); f0(i, n) cin >> a[i] >> b[i] >> c[i]; f0(i, n) { d = a[i]; e = b[i]; f = c[i]; if (i == n - 1) break; a[i + 1] = max(e + a[i + 1], f + a[i + 1]); b[i + 1] = max(d + b[i + 1], f + b[i + 1]); c[i + 1] = max(d + c[i + 1], e + c[i + 1]); } cout << max(d, max(e, f)); return 0; }
delete
110
118
110
110
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pi pair<ll, ll> #define pii pair<ll, pi> #define pb push_back #define mk make_pair const int inf = 1e9; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n][3]; // on the ith day if he did j the work for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int dp[n][3]; for (int i = 0; i < n; i++) { for (int k = 0; k < 3; k++) { dp[i][k] = 0; } } dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pi pair<ll, ll> #define pii pair<ll, pi> #define pb push_back #define mk make_pair const int inf = 1e9; int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n][3]; // on the ith day if he did j the work for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int dp[n][3]; for (int i = 0; i < n; i++) { for (int k = 0; k < 3; k++) { dp[i][k] = 0; } } dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; }
replace
11
15
11
15
0
p03162
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; const int INT_INF = 2147483647; 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; } typedef pair<int, int> P; int dp[100005][3]; int main() { int n; cin >> n; int h[n + 1][3]; rep(i, n) cin >> h[i + 1][0] >> h[i + 1][1] >> h[i + 1][2]; for (int d = 1; d <= n; d++) { rep(i, 3) { rep(j, 3) { if (i == j) continue; chmax(dp[d][i], dp[d - 1][j] + h[d][i]); } } } int ans = 0; rep(i, n) chmax(ans, dp[n][i]); 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; const int INT_INF = 2147483647; 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; } typedef pair<int, int> P; int dp[100005][3]; int main() { int n; cin >> n; int h[n + 1][3]; rep(i, n) cin >> h[i + 1][0] >> h[i + 1][1] >> h[i + 1][2]; for (int d = 1; d <= n; d++) { rep(i, 3) { rep(j, 3) { if (i == j) continue; chmax(dp[d][i], dp[d - 1][j] + h[d][i]); } } } int ans = 0; rep(i, 3) chmax(ans, dp[n][i]); cout << ans << endl; }
replace
38
39
38
39
0
p03162
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <vector> typedef long long ll; // max ll constant = LLONG_MAX using namespace std; vector<vector<int>> A(100000, vector<int>(3)); vector<vector<int>> dp(10000, vector<int>(3, -1)); int idx, N; int f, s, ans = -1; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i][0] >> A[i][1] >> A[i][2]; } for (int j = 0; j < N; j++) { f = s = -1; for (int n = 0; n < 3; n++) { if (A[j][n] > f) { f = A[j][n]; idx = n; } } if (j == 0) { for (int x = 0; x < 3; x++) { if (A[j][x] == f) { dp[j][x] = f; } } } else { for (int n = 0; n < 3; n++) { for (int r = 0; r < 3; r++) { if (r == n || dp[j - 1][r] == -1) { continue; } else { dp[j][n] = max(dp[j][n], A[j][n] + dp[j - 1][r]); } } } } } // for(int u = 0; u < N; u++){ // cout << dp[u][0] << " " << dp[u][1] << " " << dp[u][2] << endl; // } for (int l = 0; l < 3; l++) { if (dp[N - 1][l] > ans) { ans = dp[N - 1][l]; } } cout << ans; }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> typedef long long ll; // max ll constant = LLONG_MAX using namespace std; vector<vector<int>> A(100000, vector<int>(3)); vector<vector<int>> dp(100000, vector<int>(3, -1)); int idx, N; int f, s, ans = -1; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i][0] >> A[i][1] >> A[i][2]; } for (int j = 0; j < N; j++) { f = s = -1; for (int n = 0; n < 3; n++) { if (A[j][n] > f) { f = A[j][n]; idx = n; } } if (j == 0) { for (int x = 0; x < 3; x++) { if (A[j][x] == f) { dp[j][x] = f; } } } else { for (int n = 0; n < 3; n++) { for (int r = 0; r < 3; r++) { if (r == n || dp[j - 1][r] == -1) { continue; } else { dp[j][n] = max(dp[j][n], A[j][n] + dp[j - 1][r]); } } } } } // for(int u = 0; u < N; u++){ // cout << dp[u][0] << " " << dp[u][1] << " " << dp[u][2] << endl; // } for (int l = 0; l < 3; l++) { if (dp[N - 1][l] > ans) { ans = dp[N - 1][l]; } } cout << ans; }
replace
10
11
10
11
0
p03162
C++
Runtime Error
/// dp solution #include <bits/stdc++.h> using namespace std; const int N = 10007; long long dp[N][3]; int main() { int n, A[N], B[N], C[N]; cin >> n; for (int i = 0; i < n; ++i) cin >> A[i] >> B[i] >> C[i]; dp[0][0] = A[0], dp[0][1] = B[0], dp[0][2] = C[0]; for (int i = 1; i < n; ++i) { dp[i][0] = A[i] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = B[i] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = C[i] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
/// dp solution #include <bits/stdc++.h> using namespace std; const int N = 100007; long long dp[N][3]; int main() { int n, A[N], B[N], C[N]; cin >> n; for (int i = 0; i < n; ++i) cin >> A[i] >> B[i] >> C[i]; dp[0][0] = A[0], dp[0][1] = B[0], dp[0][2] = C[0]; for (int i = 1; i < n; ++i) { dp[i][0] = A[i] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = B[i] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = C[i] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
replace
3
4
3
4
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MAX 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 hpns[10010][3]; // ๅ„ๅนธ็ฆๅบฆ int dp[10010][3]; // dp[i][j] => ๅ‰ๆ—ฅjใ‚’้ธใ‚“ใ ใ†ใˆใง้”ๆˆใงใใ‚‹ๆœ€ๅคงๅ€ค int N, a, b, c; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> a >> b >> c; hpns[i][0] = a; hpns[i][1] = b; hpns[i][2] = c; dp[i][0] = -1; dp[i][1] = -1; dp[i][2] = -1; } dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; chmax(dp[i][j], dp[i - 1][k] + hpns[i][j]); } } } cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX 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 hpns[100010][3]; // ๅ„ๅนธ็ฆๅบฆ int dp[100010][3]; // dp[i][j] => ๅ‰ๆ—ฅjใ‚’้ธใ‚“ใ ใ†ใˆใง้”ๆˆใงใใ‚‹ๆœ€ๅคงๅ€ค int N, a, b, c; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> a >> b >> c; hpns[i][0] = a; hpns[i][1] = b; hpns[i][2] = c; dp[i][0] = -1; dp[i][1] = -1; dp[i][2] = -1; } dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; chmax(dp[i][j], dp[i - 1][k] + hpns[i][j]); } } } cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl; return 0; }
replace
19
21
19
21
0
p03162
C++
Runtime Error
#include <iostream> using namespace std; long long n, f[4][100004], a[4][100005]; int main() { cin >> n; for (long long i = 1; i <= n; ++i) { cin >> a[i][1] >> a[i][2] >> a[i][3]; } f[1][1] = a[1][1]; f[1][2] = a[1][2]; f[1][3] = a[1][3]; for (long long i = 2; i <= n; ++i) { for (long long j = 1; j <= 3; ++j) { if (j == 1) { f[i][j] = max(f[i - 1][2], f[i - 1][3]) + a[i][j]; } else if (j == 2) { f[i][j] = max(f[i - 1][1], f[i - 1][3]) + a[i][j]; } else if (j == 3) { f[i][j] = max(f[i - 1][1], f[i - 1][2]) + a[i][j]; } } } cout << max(f[n][1], max(f[n][2], f[n][3])); return 0; }
#include <iostream> using namespace std; long long n, f[100005][4], a[100005][4]; int main() { cin >> n; for (long long i = 1; i <= n; ++i) { cin >> a[i][1] >> a[i][2] >> a[i][3]; } f[1][1] = a[1][1]; f[1][2] = a[1][2]; f[1][3] = a[1][3]; for (long long i = 2; i <= n; ++i) { for (long long j = 1; j <= 3; ++j) { if (j == 1) { f[i][j] = max(f[i - 1][2], f[i - 1][3]) + a[i][j]; } else if (j == 2) { f[i][j] = max(f[i - 1][1], f[i - 1][3]) + a[i][j]; } else if (j == 3) { f[i][j] = max(f[i - 1][1], f[i - 1][2]) + a[i][j]; } } } cout << max(f[n][1], max(f[n][2], f[n][3])); return 0; }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <cstdlib> #include <iostream> using namespace std; int n; long long a[1010]; long long b[1010]; long long c[1010]; long long dp[10010][3]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++j) { dp[i][j] = 0; } } for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++j) { if (j == 0) { dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; } else if (j == 1) { dp[i][j] = max(dp[i - 1][2], dp[i - 1][0]) + b[i]; } else if (j == 2) { dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; return 0; }
#include <cstdlib> #include <iostream> using namespace std; int n; long long a[100010]; long long b[100010]; long long c[100010]; long long dp[100010][3]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++j) { dp[i][j] = 0; } } for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++j) { if (j == 0) { dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; } else if (j == 1) { dp[i][j] = max(dp[i - 1][2], dp[i - 1][0]) + b[i]; } else if (j == 2) { dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; return 0; }
replace
5
9
5
9
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define fin for (i = 0; i < n; i++) #define vec vector<ll> #define pb push_back #define vecit vector<ll>::iterator #define vecp vector<pair<ll, ll>> #define vecpit vector<pair<ll, ll>>::iterator #define mapp map<ll, ll> #define mapr map<ll, pair<ll, ll>> #define maprit map<ll, pair<ll, ll>>::iterator #define mapit map<ll, ll>::iterator #define mod1 1000000007 #define INF 1000000000000 using namespace std; int main() { ll n; cin >> n; ll i, k, j, l; ll map1[n][4]; map1[0][1] = 0; map1[0][2] = 0; map1[0][3] = 0; for (i = 1; i <= n; i++) { cin >> j >> k >> l; map1[i][1] = j + max(map1[i - 1][2], map1[i - 1][3]); map1[i][2] = k + max(map1[i - 1][1], map1[i - 1][3]); map1[i][3] = l + max(map1[i - 1][2], map1[i - 1][1]); } cout << max(max(map1[i - 1][1], map1[i - 1][2]), map1[i - 1][3]); }
#include <bits/stdc++.h> #define ll long long int #define fin for (i = 0; i < n; i++) #define vec vector<ll> #define pb push_back #define vecit vector<ll>::iterator #define vecp vector<pair<ll, ll>> #define vecpit vector<pair<ll, ll>>::iterator #define mapp map<ll, ll> #define mapr map<ll, pair<ll, ll>> #define maprit map<ll, pair<ll, ll>>::iterator #define mapit map<ll, ll>::iterator #define mod1 1000000007 #define INF 1000000000000 using namespace std; int main() { ll n; cin >> n; ll i, k, j, l; ll map1[n + 1][4]; map1[0][1] = 0; map1[0][2] = 0; map1[0][3] = 0; for (i = 1; i <= n; i++) { cin >> j >> k >> l; map1[i][1] = j + max(map1[i - 1][2], map1[i - 1][3]); map1[i][2] = k + max(map1[i - 1][1], map1[i - 1][3]); map1[i][3] = l + max(map1[i - 1][2], map1[i - 1][1]); } cout << max(max(map1[i - 1][1], map1[i - 1][2]), map1[i - 1][3]); }
replace
19
20
19
20
-11
p03162
C++
Time Limit Exceeded
// author: chinmay0402 // One day your whole life will flash before your eyes, make sure you make it // worth watching #include <bits/stdc++.h> using namespace std; // policy based data structures #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define ll long long int #define lld long double #define fl float #define vs vector<string> #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define fst first #define scd second #define sll set<ll> #define mll map<ll, ll> #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define INF (ll)10000000000000000 #define MOD (ll)1000000007 #define pb push_back #define msl map<string, ll> #define test \ ll t; \ cin >> t; \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define max3(a, b, c) max(a, max(b, c)) #define lcm(a, b) (a * b / __gcd(a, b)) #define all(a) a.begin(), a.end() #define sz(a) a.size(); #define present(c, x) (c.find(x) != c.end()); #define c_sum accumulate(all(c), (ll)0); #define forn(i, n) for (ll i = 0; i < n; i++) #define for1(i, n) for (ll i = 1; i <= n; i++) #define fornr(i, n) for (ll i = n - 1; i >= 0; i--) #define forab(i, a, b, c) for (ll i = a; i <= b; i += c) template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T1> void read(T &x, T1 &y) { cin >> x >> y; } template <typename T, typename T1, typename T2> void read(T &x, T1 &y, T2 &z) { cin >> x >> y >> z; } template <typename T, typename T1, typename T2, typename T3> void read(T &x, T1 &y, T2 &z, T3 &a) { cin >> x >> y >> z >> a; } template <typename T> void reada(T oneD, ll n) { for (ll i = 0; i < n; i++) cin >> oneD[i]; } template <typename T> void readv(vector<T> &oneD, ll n) { forn(i, n) { ll x; read(x); oneD.push_back(x); } } vll graph[100001]; template <typename T> void readg(vector<T> graph[100001], ll n) { forn(i, n) { ll x, y; cin >> x >> y; graph[x].pb(y); graph[y].pb(x); } } #define iread1(n) \ ll n; \ read(n); #define iread2(n, m) \ ll n, m; \ read(n, m); #define iread3(x, y, z) \ ll x, y, z; \ read(x, y, z); ll gcd(ll a, ll b) { if (a == 0) return b; else return gcd(b % a, a); } ll gcdExt(ll a, ll b, ll &x, ll &y) { if (a == 0) { x = 0; y = 1; return b; } ll x1, y1; ll gcd = gcdExt(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return gcd; } ll pwr(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a *= a; b >>= 1; } return res; } ll pwrm(ll a, ll b, ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } ll pwrm_which_works_too(ll a, ll b, ll m) { a %= m; if (a == 0) return 0; else if (b == 0) return 1; else if (b & 1) return (a * pwrm(a, b / 2, m) % m * pwrm(a, b / 2, m) % m) % m; else return (pwrm(a, b / 2, m) % m * pwrm(a, b / 2, m) % m) % m; } ll no_of_divisors(ll n) { ll c = 0; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) c = c + 1; else c = c + 2; } } return c; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf(1000001); void Sieve_spf() { ll n = 1000001; forn(i, n) sieve[i] = i; sieve[0] = -1; sieve[1] = -1; forab(i, 2, n, 2) sieve[i] = 2; forab(i, 3, n, 2) if (sieve[i] == i) forab(j, i * i, n, i) if (sieve[j] == j) sieve[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } bool isInt(ll a, ll b) { if ((lld)a / (lld)b == a / b) return true; else return false; } ll solve(ll curr, ll r, ll c, ll n, ll a[][3]) { if (r < n - 1) { if (c == 0) { ll k = max(solve(curr + a[r + 1][1], r + 1, 1, n, a), solve(curr + a[r + 1][2], r + 1, 2, n, a)); return k; } else if (c == 1) { ll k = max(solve(curr + a[r + 1][0], r + 1, 0, n, a), solve(curr + a[r + 1][2], r + 1, 2, n, a)); return k; } else { ll k = max(solve(curr + a[r + 1][1], r + 1, 1, n, a), solve(curr + a[r + 1][0], r + 1, 0, n, a)); return k; } } else { return curr; } } int main() { #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif // START OF PROGRAM LOGIC flash iread1(n); ll a[n][3]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 3; j++) { cin >> a[i][j]; } } cout << max(solve(0, -1, 0, n, a), max(solve(0, -1, 1, n, a), solve(0, -1, 2, n, a))) << "\n"; // END OF PROGRAM LOGIC return 0; }
// author: chinmay0402 // One day your whole life will flash before your eyes, make sure you make it // worth watching #include <bits/stdc++.h> using namespace std; // policy based data structures #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define ll long long int #define lld long double #define fl float #define vs vector<string> #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define fst first #define scd second #define sll set<ll> #define mll map<ll, ll> #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define INF (ll)10000000000000000 #define MOD (ll)1000000007 #define pb push_back #define msl map<string, ll> #define test \ ll t; \ cin >> t; \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define max3(a, b, c) max(a, max(b, c)) #define lcm(a, b) (a * b / __gcd(a, b)) #define all(a) a.begin(), a.end() #define sz(a) a.size(); #define present(c, x) (c.find(x) != c.end()); #define c_sum accumulate(all(c), (ll)0); #define forn(i, n) for (ll i = 0; i < n; i++) #define for1(i, n) for (ll i = 1; i <= n; i++) #define fornr(i, n) for (ll i = n - 1; i >= 0; i--) #define forab(i, a, b, c) for (ll i = a; i <= b; i += c) template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T1> void read(T &x, T1 &y) { cin >> x >> y; } template <typename T, typename T1, typename T2> void read(T &x, T1 &y, T2 &z) { cin >> x >> y >> z; } template <typename T, typename T1, typename T2, typename T3> void read(T &x, T1 &y, T2 &z, T3 &a) { cin >> x >> y >> z >> a; } template <typename T> void reada(T oneD, ll n) { for (ll i = 0; i < n; i++) cin >> oneD[i]; } template <typename T> void readv(vector<T> &oneD, ll n) { forn(i, n) { ll x; read(x); oneD.push_back(x); } } vll graph[100001]; template <typename T> void readg(vector<T> graph[100001], ll n) { forn(i, n) { ll x, y; cin >> x >> y; graph[x].pb(y); graph[y].pb(x); } } #define iread1(n) \ ll n; \ read(n); #define iread2(n, m) \ ll n, m; \ read(n, m); #define iread3(x, y, z) \ ll x, y, z; \ read(x, y, z); ll gcd(ll a, ll b) { if (a == 0) return b; else return gcd(b % a, a); } ll gcdExt(ll a, ll b, ll &x, ll &y) { if (a == 0) { x = 0; y = 1; return b; } ll x1, y1; ll gcd = gcdExt(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return gcd; } ll pwr(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a *= a; b >>= 1; } return res; } ll pwrm(ll a, ll b, ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } ll pwrm_which_works_too(ll a, ll b, ll m) { a %= m; if (a == 0) return 0; else if (b == 0) return 1; else if (b & 1) return (a * pwrm(a, b / 2, m) % m * pwrm(a, b / 2, m) % m) % m; else return (pwrm(a, b / 2, m) % m * pwrm(a, b / 2, m) % m) % m; } ll no_of_divisors(ll n) { ll c = 0; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) c = c + 1; else c = c + 2; } } return c; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf(1000001); void Sieve_spf() { ll n = 1000001; forn(i, n) sieve[i] = i; sieve[0] = -1; sieve[1] = -1; forab(i, 2, n, 2) sieve[i] = 2; forab(i, 3, n, 2) if (sieve[i] == i) forab(j, i * i, n, i) if (sieve[j] == j) sieve[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } bool isInt(ll a, ll b) { if ((lld)a / (lld)b == a / b) return true; else return false; } ll solve(ll curr, ll r, ll c, ll n, ll a[][3]) { if (r < n - 1) { if (c == 0) { ll k = max(solve(curr + a[r + 1][1], r + 1, 1, n, a), solve(curr + a[r + 1][2], r + 1, 2, n, a)); return k; } else if (c == 1) { ll k = max(solve(curr + a[r + 1][0], r + 1, 0, n, a), solve(curr + a[r + 1][2], r + 1, 2, n, a)); return k; } else { ll k = max(solve(curr + a[r + 1][1], r + 1, 1, n, a), solve(curr + a[r + 1][0], r + 1, 0, n, a)); return k; } } else { return curr; } } int main() { #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif // START OF PROGRAM LOGIC flash iread1(n); ll a[n][3]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 3; j++) { cin >> a[i][j]; } } ll h[n], b[n], s[n]; h[0] = a[0][2]; s[0] = a[0][0]; b[0] = a[0][1]; for (ll i = 1; i < n; i++) { h[i] = a[i][2] + max(b[i - 1], s[i - 1]); s[i] = a[i][0] + max(b[i - 1], h[i - 1]); b[i] = a[i][1] + max(h[i - 1], s[i - 1]); } cout << max(h[n - 1], max(b[n - 1], s[n - 1])) << "\n"; // END OF PROGRAM LOGIC return 0; }
replace
226
229
226
236
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[10001][3]; int main() { int n; cin >> n; for (int i = 0; i < 10001; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } vector<int> a(n); vector<int> b(n); vector<int> c(n); for (int i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; cin >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n"; }
#include <bits/stdc++.h> using namespace std; int dp[100001][3]; int main() { int n; cin >> n; for (int i = 0; i < 10001; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } vector<int> a(n); vector<int> b(n); vector<int> c(n); for (int i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; cin >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n"; }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin >> n; ll a[n][3]; ll i, j; for (i = 0; i < n; i++) { for (j = 0; j < 3; j++) { cin >> a[i][j]; } } ll dp[n][n]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin >> n; ll a[n][3]; ll i, j; for (i = 0; i < n; i++) { for (j = 0; j < 3; j++) { cin >> a[i][j]; } } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
replace
15
16
15
16
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n; int mem[MAXN][4]; int a[MAXN], b[MAXN], c[MAXN]; int solve(int i, int prev) { if (i == n) return 0; int &ret = mem[i][prev]; int c1 = -1e9, c2 = -1e9, c3 = -1e9; if (prev != 1) c1 = solve(i + 1, 1) + a[i]; if (prev != 2) c2 = solve(i + 1, 2) + b[i]; if (prev != 3) c3 = solve(i + 1, 3) + c[i]; ret = max(c1, max(c2, c3)); return ret; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; memset(mem, -1, sizeof(mem)); cout << solve(0, 0); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n; int mem[MAXN][4]; int a[MAXN], b[MAXN], c[MAXN]; int solve(int i, int prev) { if (i == n) return 0; int &ret = mem[i][prev]; if (ret != -1) return ret; int c1 = -1e9, c2 = -1e9, c3 = -1e9; if (prev != 1) c1 = solve(i + 1, 1) + a[i]; if (prev != 2) c2 = solve(i + 1, 2) + b[i]; if (prev != 3) c3 = solve(i + 1, 3) + c[i]; ret = max(c1, max(c2, c3)); return ret; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; memset(mem, -1, sizeof(mem)); cout << solve(0, 0); }
insert
14
14
14
16
TLE
p03162
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int k[3][10001]; int dp[3][10001] = {}; for (int i = 0; i < n; i++) { cin >> k[0][i + 1] >> k[1][i + 1] >> k[2][i + 1]; } for (int i = 0; i < n; i++) { dp[0][i + 1] = max(dp[1][i], dp[2][i]) + k[0][i + 1]; dp[1][i + 1] = max(dp[0][i], dp[2][i]) + k[1][i + 1]; dp[2][i + 1] = max(dp[1][i], dp[0][i]) + k[2][i + 1]; } cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int k[3][100001]; int dp[3][100001] = {}; for (int i = 0; i < n; i++) { cin >> k[0][i + 1] >> k[1][i + 1] >> k[2][i + 1]; } for (int i = 0; i < n; i++) { dp[0][i + 1] = max(dp[1][i], dp[2][i]) + k[0][i + 1]; dp[1][i + 1] = max(dp[0][i], dp[2][i]) + k[1][i + 1]; dp[2][i + 1] = max(dp[1][i], dp[0][i]) + k[2][i + 1]; } cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) << endl; return 0; }
replace
10
12
10
12
0
p03162
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; typedef long long ll; const ll INF = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); i++) vector<vector<ll>> memo(10000, vector<ll>(3, -1)); ll N; int dp(vector<vector<int>> &ABC, ll i, ll j) { if (i == 0) return 0; if (memo[i][j] != -1) return memo[i][j]; return memo[i][j] = max(dp(ABC, i - 1, (j + 1) % 3) + ABC[i][j], dp(ABC, i - 1, (j + 2) % 3) + ABC[i][j]); } int main() { cin >> N; vector<vector<int>> ABC(N + 1, vector<int>(3)); ABC[0][0] = 0, ABC[0][1] = 0, ABC[0][2] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < 3; j++) { cin >> ABC[i][j]; } } cout << max(max(dp(ABC, N, 0), dp(ABC, N, 1)), dp(ABC, N, 2)) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; typedef long long ll; const ll INF = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); i++) vector<vector<ll>> memo(100007, vector<ll>(3, -1)); ll N; int dp(vector<vector<int>> &ABC, ll i, ll j) { if (i == 0) return 0; if (memo[i][j] != -1) return memo[i][j]; return memo[i][j] = max(dp(ABC, i - 1, (j + 1) % 3) + ABC[i][j], dp(ABC, i - 1, (j + 2) % 3) + ABC[i][j]); } int main() { cin >> N; vector<vector<int>> ABC(N + 1, vector<int>(3)); ABC[0][0] = 0, ABC[0][1] = 0, ABC[0][2] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < 3; j++) { cin >> ABC[i][j]; } } cout << max(max(dp(ABC, N, 0), dp(ABC, N, 1)), dp(ABC, N, 2)) << endl; return 0; }
replace
19
20
19
20
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #ifdef DEBUG #define PRINT(x) \ cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " \ << (x) << endl; #define PRINTA(a, first, last) \ cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \ << (first) << ", " << (last) << ")" << endl; \ for (int i = (first); i < (last); ++i) { \ cout << #a << "[" << i << "] = " << (a)[i] << endl; \ } #else #define PRINT(x) #define PRINTA(a, first, last) #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define MOD 1000000007 using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; template <class T, class U> void amax(T &x, U y) { if (x < y) x = y; } template <class T, class U> void amin(T &x, U y) { if (x > y) x = y; } int main(void) { constexpr int N_MAX = 1000; int N; int a[3][N_MAX]; cin >> N; REP(i, N) REP(j, 3) cin >> a[j][i]; int dp[3][N_MAX]; REP(i, 3) dp[i][0] = a[i][0]; FOR(i, 1, N) { REP(j, 3) { dp[j][i] = 0; REP(k, 3) { if (k != j) { amax(dp[j][i], dp[k][i - 1] + a[j][i]); } } // printf("dp[%d][%d] = %d\n", j, i, dp[j][i]); } } int result = 0; REP(i, 3) amax(result, dp[i][N - 1]); cout << result << endl; return 0; }
#include <bits/stdc++.h> #ifdef DEBUG #define PRINT(x) \ cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " \ << (x) << endl; #define PRINTA(a, first, last) \ cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \ << (first) << ", " << (last) << ")" << endl; \ for (int i = (first); i < (last); ++i) { \ cout << #a << "[" << i << "] = " << (a)[i] << endl; \ } #else #define PRINT(x) #define PRINTA(a, first, last) #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define MOD 1000000007 using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; template <class T, class U> void amax(T &x, U y) { if (x < y) x = y; } template <class T, class U> void amin(T &x, U y) { if (x > y) x = y; } int main(void) { constexpr int N_MAX = 100000; int N; int a[3][N_MAX]; cin >> N; REP(i, N) REP(j, 3) cin >> a[j][i]; int dp[3][N_MAX]; REP(i, 3) dp[i][0] = a[i][0]; FOR(i, 1, N) { REP(j, 3) { dp[j][i] = 0; REP(k, 3) { if (k != j) { amax(dp[j][i], dp[k][i - 1] + a[j][i]); } } // printf("dp[%d][%d] = %d\n", j, i, dp[j][i]); } } int result = 0; REP(i, 3) amax(result, dp[i][N - 1]); cout << result << endl; return 0; }
replace
42
43
42
43
0
p03162
C++
Runtime Error
#include <cstring> #include <iostream> #include <string> using namespace std; int dp[10001][3]; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n; cin >> n; memset(dp, 0, sizeof(dp)); int a[n][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } // for (int i=0; i<=n; i++) { // cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl; // } int max = 0; chmax(max, dp[n][0]); chmax(max, dp[n][1]); chmax(max, dp[n][2]); cout << max << endl; }
#include <cstring> #include <iostream> #include <string> using namespace std; int dp[100001][3]; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n; cin >> n; memset(dp, 0, sizeof(dp)); int a[n][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } // for (int i=0; i<=n; i++) { // cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl; // } int max = 0; chmax(max, dp[n][0]); chmax(max, dp[n][1]); chmax(max, dp[n][2]); cout << max << endl; }
replace
6
7
6
7
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; int dp[100005][4]; vector<vector<int>> v; int n; int solve(int days, int prev) { if (days > n) return 0; if (dp[days][prev] != -1) return dp[days][prev]; int ans = INT_MIN; for (int i = 1; i <= 3; i++) { if (i == prev) continue; ans = max(ans, solve(days + 1, i) + v[days][i]); } return ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n; v.resize(n + 1); for (int i = 1; i <= n; i++) { v[i].resize(4); for (int j = 1; j <= 3; j++) cin >> v[i][j]; } cout << solve(1, 0); return 0; }
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; int dp[100005][4]; vector<vector<int>> v; int n; int solve(int days, int prev) { if (days > n) return 0; if (dp[days][prev] != -1) return dp[days][prev]; int ans = INT_MIN; for (int i = 1; i <= 3; i++) { if (i == prev) continue; ans = max(ans, solve(days + 1, i) + v[days][i]); } return dp[days][prev] = ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n; v.resize(n + 1); for (int i = 1; i <= n; i++) { v[i].resize(4); for (int j = 1; j <= 3; j++) cin >> v[i][j]; } cout << solve(1, 0); return 0; }
replace
23
24
23
24
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int MX = 1e5 + 5; int dp[MX][4]; vector<vector<int>> v; int n; int solve(int days, int prev) { if (days == n + 1) return 0; if (dp[days][prev] != -1) return dp[days][prev]; long long ans = -1e17; for (int i = 1; i <= 3; i++) { if (i != prev) { ans = max(ans, solve(days + 1, i) + v[days][i]); } } return dp[prev][prev] = ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n; v.resize(n + 1); for (int i = 1; i <= n; i++) { v[i].resize(4); for (int j = 1; j <= 3; j++) cin >> v[i][j]; } cout << solve(1, 0); return 0; }
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int MX = 1e5 + 5; int dp[MX][4]; vector<vector<int>> v; int n; int solve(int days, int prev) { if (days == n + 1) return 0; if (dp[days][prev] != -1) return dp[days][prev]; long long ans = -1e17; for (int i = 1; i <= 3; i++) { if (i != prev) { ans = max(ans, solve(days + 1, i) + v[days][i]); } } return dp[days][prev] = ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n; v.resize(n + 1); for (int i = 1; i <= n; i++) { v[i].resize(4); for (int j = 1; j <= 3; j++) cin >> v[i][j]; } cout << solve(1, 0); return 0; }
replace
24
25
24
25
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define all(v) v.begin(), v.end() #define sz(v) (int)((v).size()) using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; 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; } vi a(10000), b(10000), c(10000); vvi dp(100000, vi(3, 0)); int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 1; i < N; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } int ans = max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define all(v) v.begin(), v.end() #define sz(v) (int)((v).size()) using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; 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; } int N_MAX = 100000; vi a(N_MAX), b(N_MAX), c(N_MAX); vvi dp(N_MAX, vi(3, 0)); int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 1; i < N; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } int ans = max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])); cout << ans << endl; return 0; }
replace
28
30
28
31
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define INF (1e10) #define mp make_pair #define pb push_back #define A 0 #define B 1 #define C 2 using namespace std; typedef long long int lo; lo dp[10000005][3], arr[10000005][3], n; lo f(lo i, lo c) { if (i == n) return dp[i][c] = arr[i][c]; if (dp[i][c] != 0) return dp[i][c]; if (c == A) { return dp[i][c] = max(f(i + 1, B) + arr[i][c], f(i + 1, C) + arr[i][c]); } else if (c == B) { return dp[i][c] = max(f(i + 1, A) + arr[i][c], f(i + 1, C) + arr[i][c]); } else { return dp[i][c] = max(f(i + 1, A) + arr[i][c], f(i + 1, B) + arr[i][c]); } } int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); cin >> n; for (lo i = 1; i <= n; i++) { lo a, b, c; cin >> a >> b >> c; arr[i][A] = a; arr[i][B] = b; arr[i][C] = c; } cout << max(f(1, A), max(f(1, B), f(1, C))); }
#include <bits/stdc++.h> #define INF (1e10) #define mp make_pair #define pb push_back #define A 0 #define B 1 #define C 2 using namespace std; typedef long long int lo; lo dp[10000005][3], arr[10000005][3], n; lo f(lo i, lo c) { if (i == n) return dp[i][c] = arr[i][c]; if (dp[i][c] != 0) return dp[i][c]; if (c == A) { return dp[i][c] = max(f(i + 1, B) + arr[i][c], f(i + 1, C) + arr[i][c]); } else if (c == B) { return dp[i][c] = max(f(i + 1, A) + arr[i][c], f(i + 1, C) + arr[i][c]); } else { return dp[i][c] = max(f(i + 1, A) + arr[i][c], f(i + 1, B) + arr[i][c]); } } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); cin >> n; for (lo i = 1; i <= n; i++) { lo a, b, c; cin >> a >> b >> c; arr[i][A] = a; arr[i][B] = b; arr[i][C] = c; } cout << max(f(1, A), max(f(1, B), f(1, C))); }
replace
24
26
24
26
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifndef ONLINE_JUDGE #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #endif #define ll long long int #define endl '\n' #define pb push_back #define vectl vector<ll> #define vecti vector<int> #define debugh cout << "here" << endl; #define loopi(i, n) for (ll i = 0; i < n; i++) #define loopj(j, n) for (ll j = 0; j < n; j++) #define loop2(i, a, b) for (int i = a; i < b; i++) #define mp make_pair #define ip(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i] #define op(a, n) \ for (ll i = 0; i < n; i++) \ cout << a[i] << " " #define gcd(a, b) __gcd((a), (b))` #define lcm(a, b) (((a) * (b)) / gcd((a), (b))) #define mem(x, n) memset(x, n, sizeof(x)) #define cn cout << "\n"; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testcase \ ll t; \ cin >> t; \ while (t--) const ll INF = 1e18; const ll N = 100005; const ll MOD = 1e9 + 7; int main() { fast // testcase // { ll n; cin >> n; int a[n][n]; loopi(i, n) { for (ll j = 0; j < 3; j++) { // debugh cin >> a[i][j]; } } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (ll i = 1; i < n; i++) { dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]); } ll ans = max(dp[n - 1][0], dp[n - 1][1]); ans = max(ans, dp[n - 1][2]); cout << ans << endl; // } return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifndef ONLINE_JUDGE #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #endif #define ll long long int #define endl '\n' #define pb push_back #define vectl vector<ll> #define vecti vector<int> #define debugh cout << "here" << endl; #define loopi(i, n) for (ll i = 0; i < n; i++) #define loopj(j, n) for (ll j = 0; j < n; j++) #define loop2(i, a, b) for (int i = a; i < b; i++) #define mp make_pair #define ip(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i] #define op(a, n) \ for (ll i = 0; i < n; i++) \ cout << a[i] << " " #define gcd(a, b) __gcd((a), (b))` #define lcm(a, b) (((a) * (b)) / gcd((a), (b))) #define mem(x, n) memset(x, n, sizeof(x)) #define cn cout << "\n"; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testcase \ ll t; \ cin >> t; \ while (t--) const ll INF = 1e18; const ll N = 100005; const ll MOD = 1e9 + 7; int main() { fast // testcase // { ll n; cin >> n; int a[n][3]; loopi(i, n) { for (ll j = 0; j < 3; j++) { // debugh cin >> a[i][j]; } } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (ll i = 1; i < n; i++) { dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]); } ll ans = max(dp[n - 1][0], dp[n - 1][1]); ans = max(ans, dp[n - 1][2]); cout << ans << endl; // } return 0; }
replace
75
76
75
76
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll mod = 1e9 + 7; #define rep(i, a, b) for (ll i = a; i < b; i++) void swap(ll &a, ll &b) { ll t = a; a = b; b = t; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll pow(ll a, ll b) { a %= mod; ll ans = 1; while (b > 0) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b /= 2; } return ans; } int main() { ios_base ::sync_with_stdio(0); cin.tie(0); /// 1 2 3 4 .... ll n; cin >> n; ll a[n][3]; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } ll dp[3][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + a[i][0], dp[i - 1][2] + a[i][0]); dp[i][1] = max(dp[i - 1][0] + a[i][1], dp[i - 1][2] + a[i][1]); dp[i][2] = max(dp[i - 1][0] + a[i][2], dp[i - 1][1] + a[i][2]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll mod = 1e9 + 7; #define rep(i, a, b) for (ll i = a; i < b; i++) void swap(ll &a, ll &b) { ll t = a; a = b; b = t; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll pow(ll a, ll b) { a %= mod; ll ans = 1; while (b > 0) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b /= 2; } return ans; } int main() { ios_base ::sync_with_stdio(0); cin.tie(0); /// 1 2 3 4 .... ll n; cin >> n; ll a[n][3]; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + a[i][0], dp[i - 1][2] + a[i][0]); dp[i][1] = max(dp[i - 1][0] + a[i][1], dp[i - 1][2] + a[i][1]); dp[i][2] = max(dp[i - 1][0] + a[i][2], dp[i - 1][1] + a[i][2]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
replace
47
48
47
48
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const int N_MAX = 10010; int main() { int n; cin >> n; vector<int> A(N_MAX), B(N_MAX), C(N_MAX); for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i]; } // dp[i][j]: iๆ—ฅ็›ฎใซjใ‚’ใ‚„ใฃใŸๆ™‚ใฎๅนธ็ฆๅบฆ // j: 0 => A, 1 => B, 2 => C int dp[N_MAX][3] = {}; for (int i = 0; i < n; i++) { dp[i + 1][0] = max(dp[i][1] + B[i], dp[i][2] + C[i]); dp[i + 1][1] = max(dp[i][0] + A[i], dp[i][2] + C[i]); dp[i + 1][2] = max(dp[i][0] + A[i], dp[i][1] + B[i]); } int ans; ans = max({dp[n][0], dp[n][1], dp[n][2]}); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const int N_MAX = 100100; int main() { int n; cin >> n; vector<int> A(N_MAX), B(N_MAX), C(N_MAX); for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i]; } // dp[i][j]: iๆ—ฅ็›ฎใซjใ‚’ใ‚„ใฃใŸๆ™‚ใฎๅนธ็ฆๅบฆ // j: 0 => A, 1 => B, 2 => C int dp[N_MAX][3] = {}; for (int i = 0; i < n; i++) { dp[i + 1][0] = max(dp[i][1] + B[i], dp[i][2] + C[i]); dp[i + 1][1] = max(dp[i][0] + A[i], dp[i][2] + C[i]); dp[i + 1][2] = max(dp[i][0] + A[i], dp[i][1] + B[i]); } int ans; ans = max({dp[n][0], dp[n][1], dp[n][2]}); cout << ans << endl; return 0; }
replace
4
5
4
5
0
p03162
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll n, a[100100][3]; ll dp[100100][3]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = max(dp[i + 1][i], dp[i][j] + a[i][k]); } } } ll res = 0; for (int i = 0; i < 3; i++) { res = max(res, dp[n][i]); } cout << res << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll n, a[100100][3]; ll dp[100100][3]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll res = 0; for (int i = 0; i < 3; i++) { res = max(res, dp[n][i]); } cout << res << endl; }
replace
46
47
46
47
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define localin \ freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\inputf.in", "r", stdin); #define localout \ freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\outputf.in", "w", stdout); const int MAX = 2e5 + 5; #define ld long double #define endl "\n" #define pb push_back #define ff first #define ss second #define vi vector<int> #define tot(v) v.begin(), v.end() #define rtcheck \ cout << "saurabh\n"; \ exit(0); #define vcheck(x) cout << #x << " " << x << endl; #define pint pair<int, int> #define forn for (int i = 0; i < n; i++) const int modu = 1e9 + 7; const int inf = 1e17; struct activity { int A, B, C; }; int solve(vector<activity> ar, int n) { int dp[n][3]; dp[0][0] = ar[0].A; dp[0][1] = ar[0].B; dp[0][2] = ar[0].C; for (int i = 1; i < n; i++) { dp[i][0] = ar[i].A + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = ar[i].B + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = ar[i].C + max(dp[i - 1][1], dp[i - 1][0]); } int res = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); return res; } int32_t main() { fast; int t; t = 1; // cin>>t; while (t--) { int n; cin >> n; vector<activity> ar; for (int i = 0; i < n; i++) { cin >> ar[i].A; cin >> ar[i].B; cin >> ar[i].C; } int ans = solve(ar, n); cout << ans << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define int long long #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define localin \ freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\inputf.in", "r", stdin); #define localout \ freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\outputf.in", "w", stdout); const int MAX = 2e5 + 5; #define ld long double #define endl "\n" #define pb push_back #define ff first #define ss second #define vi vector<int> #define tot(v) v.begin(), v.end() #define rtcheck \ cout << "saurabh\n"; \ exit(0); #define vcheck(x) cout << #x << " " << x << endl; #define pint pair<int, int> #define forn for (int i = 0; i < n; i++) const int modu = 1e9 + 7; const int inf = 1e17; struct activity { int A, B, C; }; int solve(vector<activity> ar, int n) { int dp[n][3]; dp[0][0] = ar[0].A; dp[0][1] = ar[0].B; dp[0][2] = ar[0].C; for (int i = 1; i < n; i++) { dp[i][0] = ar[i].A + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = ar[i].B + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = ar[i].C + max(dp[i - 1][1], dp[i - 1][0]); } int res = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); return res; } int32_t main() { fast; int t; t = 1; // cin>>t; while (t--) { int n; cin >> n; vector<activity> ar(n + 1); for (int i = 0; i < n; i++) { cin >> ar[i].A; cin >> ar[i].B; cin >> ar[i].C; } int ans = solve(ar, n); cout << ans << endl; } }
replace
63
64
63
64
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define pll pair<ll, ll> #define vll vector<pll> #define vl vector<ll> #define f first #define s second #define N 50000 #define pb push_back #define mp make_pair #define MAP map<ll, ll> #define INF 1000000000 #define mod 1000000007 #define foo(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, a, b) for (ll i = (a); i >= (b); i--) #define sl set<ll> #define sll set<pll> #define ub upper_bound #define lb lower_bound using namespace std; ll a[100000]; ll dp[1000][3]; int main() { fastio; ll n, a, b, c; vl A, B, C; cin >> n; foo(i, 0, n - 1) { cin >> a >> b >> c; A.pb(a); B.pb(b); C.pb(c); } foo(i, 1, n) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i - 1]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B[i - 1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i - 1]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); }
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define pll pair<ll, ll> #define vll vector<pll> #define vl vector<ll> #define f first #define s second #define N 50000 #define pb push_back #define mp make_pair #define MAP map<ll, ll> #define INF 1000000000 #define mod 1000000007 #define foo(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, a, b) for (ll i = (a); i >= (b); i--) #define sl set<ll> #define sll set<pll> #define ub upper_bound #define lb lower_bound using namespace std; ll a[100000]; ll dp[100001][3]; int main() { fastio; ll n, a, b, c; vl A, B, C; cin >> n; foo(i, 0, n - 1) { cin >> a >> b >> c; A.pb(a); B.pb(b); C.pb(c); } foo(i, 1, n) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i - 1]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B[i - 1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i - 1]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); }
replace
25
26
25
26
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rp(i, n) for (int i = 0; i < (int)(n); ++i) #define rep(i, x, n) for (int i = (x); i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define TRACE(x...) #define PRINT(x...) #define WATCH(x) TRACE(cout << #x << " = " << x << endl) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; typedef vector<vll> vvll; const int MAXN = 10010; ll dp[MAXN][3]; ll mat[MAXN][3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rp(i, n) rp(j, 3) cin >> mat[i][j]; rp(j, 3) dp[0][j] = mat[0][j]; rep(i, 1, n) { rp(j, 3) { dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + mat[i][j]; } } ll resp = 0; rp(j, 3) resp = max(dp[n - 1][j], resp); cout << resp << '\n'; return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rp(i, n) for (int i = 0; i < (int)(n); ++i) #define rep(i, x, n) for (int i = (x); i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define TRACE(x...) #define PRINT(x...) #define WATCH(x) TRACE(cout << #x << " = " << x << endl) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; typedef vector<vll> vvll; const int MAXN = 100010; ll dp[MAXN][3]; ll mat[MAXN][3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rp(i, n) rp(j, 3) cin >> mat[i][j]; rp(j, 3) dp[0][j] = mat[0][j]; rep(i, 1, n) { rp(j, 3) { dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + mat[i][j]; } } ll resp = 0; rp(j, 3) resp = max(dp[n - 1][j], resp); cout << resp << '\n'; return 0; }
replace
31
32
31
32
0
p03162
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define db(x) cerr << #x << " == " << x << endl #define all(container) container.begin(), container.end() #define mp(i, j) make_pair(i, j) #define pb push_back typedef pair<int, int> pii; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<pii> vii; template <typename T> void print_vector_debug(const T &t) { cout << "[DEBUG] VECTOR:"; for (auto i = t.cbegin(); i != t.cend(); ++i) { if ((i + 1) != t.cend()) { cout << *i << " "; } else { cout << *i << endl; } } } #define MAXN 100005 int N; int vals[MAXN][3]; int vis[MAXN][4], dp[MAXN][4]; int solve(int idx, int last) { if (idx == N) { return 0; } if (vis[idx][last]) { return dp[idx][last]; } int res = 0; for (int i = 0; i < 3; i++) { if (i != last) { res = max(res, solve(idx + 1, i) + vals[idx][i]); } } dp[idx][last] = res; return res; } int main() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d%d%d", &vals[i][0], &vals[i][1], &vals[i][2]); } printf("%d\n", solve(0, 3)); return 0; }
#include "bits/stdc++.h" using namespace std; #define db(x) cerr << #x << " == " << x << endl #define all(container) container.begin(), container.end() #define mp(i, j) make_pair(i, j) #define pb push_back typedef pair<int, int> pii; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<pii> vii; template <typename T> void print_vector_debug(const T &t) { cout << "[DEBUG] VECTOR:"; for (auto i = t.cbegin(); i != t.cend(); ++i) { if ((i + 1) != t.cend()) { cout << *i << " "; } else { cout << *i << endl; } } } #define MAXN 100005 int N; int vals[MAXN][3]; int vis[MAXN][4], dp[MAXN][4]; int solve(int idx, int last) { if (idx == N) { return 0; } if (vis[idx][last]) { return dp[idx][last]; } vis[idx][last] = 1; int res = 0; for (int i = 0; i < 3; i++) { if (i != last) { res = max(res, solve(idx + 1, i) + vals[idx][i]); } } dp[idx][last] = res; return res; } int main() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d%d%d", &vals[i][0], &vals[i][1], &vals[i][2]); } printf("%d\n", solve(0, 3)); return 0; }
insert
39
39
39
40
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fi first #define sec second #define MOD 1000000007 #define pb push_back #define test cout << "debuged\n"; #define INF 10000000000 #define si 1000000 #define debug(x) cout << x << "\n"; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output", "w", stdout); #endif ll n; cin >> n; vector<ll> a(n + 1), b(n + 1), c(n + 1); for (ll i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; ll dp[n + 1][3]; dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1]; for (ll i = 2; i <= n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fi first #define sec second #define MOD 1000000007 #define pb push_back #define test cout << "debuged\n"; #define INF 10000000000 #define si 1000000 #define debug(x) cout << x << "\n"; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vector<ll> a(n + 1), b(n + 1), c(n + 1); for (ll i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; ll dp[n + 1][3]; dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1]; for (ll i = 2; i <= n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); }
replace
15
19
15
16
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03162
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 1; i <= n; ++i) typedef long long ll; const int inf = 100100100; const ll INF = 1LL << 60; const int MOD = (int)1e9 + 7; // aใจbใฎใ†ใกๅคงใใ„ๅ€คใ‚’aใจใ—ใฆๆŽก็”จใ™ใ‚‹ template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int N_MAX = 11000; int n; cin >> n; vector<int> a(N_MAX); vector<int> b(N_MAX); vector<int> c(N_MAX); rep(i, n) cin >> a[i] >> b[i] >> c[i]; vector<vector<ll>> dp(N_MAX, vector<ll>(3, 0)); rep(i, n) { chmax(dp[i + 1][0], dp[i][1] + a[i]); chmax(dp[i + 1][0], dp[i][2] + a[i]); chmax(dp[i + 1][1], dp[i][0] + b[i]); chmax(dp[i + 1][1], dp[i][2] + b[i]); chmax(dp[i + 1][2], dp[i][0] + c[i]); chmax(dp[i + 1][2], dp[i][1] + c[i]); } cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 1; i <= n; ++i) typedef long long ll; const int inf = 100100100; const ll INF = 1LL << 60; const int MOD = (int)1e9 + 7; // aใจbใฎใ†ใกๅคงใใ„ๅ€คใ‚’aใจใ—ใฆๆŽก็”จใ™ใ‚‹ template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int N_MAX = 110000; int n; cin >> n; vector<int> a(N_MAX); vector<int> b(N_MAX); vector<int> c(N_MAX); rep(i, n) cin >> a[i] >> b[i] >> c[i]; vector<vector<ll>> dp(N_MAX, vector<ll>(3, 0)); rep(i, n) { chmax(dp[i + 1][0], dp[i][1] + a[i]); chmax(dp[i + 1][0], dp[i][2] + a[i]); chmax(dp[i + 1][1], dp[i][0] + b[i]); chmax(dp[i + 1][1], dp[i][2] + b[i]); chmax(dp[i + 1][2], dp[i][0] + c[i]); chmax(dp[i + 1][2], dp[i][1] + c[i]); } cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl; return 0; }
replace
31
32
31
32
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[10004][3]; int main() { int n; cin >> n; int ar[n][3]; for (int i = 0; i < n; i++) { cin >> ar[i][0] >> ar[i][1] >> ar[i][2]; } dp[0][0] = ar[0][0]; dp[0][1] = ar[0][1]; dp[0][2] = ar[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + ar[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100004][3]; int main() { int n; cin >> n; int ar[n][3]; for (int i = 0; i < n; i++) { cin >> ar[i][0] >> ar[i][1] >> ar[i][2]; } dp[0][0] = ar[0][0]; dp[0][1] = ar[0][1]; dp[0][2] = ar[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + ar[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; return 0; }
replace
3
4
3
4
0
p03162
C++
Runtime Error
// Includes #include <algorithm> #include <assert.h> #include <bitset> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <utility> #include <vector> // Defines #define pb push_back #define mp make_pair #define fr first #define sc second #define MOD 1000000007 #define len(x) x.size() #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define all(v) v.begin(), v.end() #define alla(a, n) a, a + n #define mem(name, value) memset(name, value, sizeof(name)) #define f(i, a) for (int i = 0; i < a; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vll> vvll; typedef vector<string> vs; int arr[100005][3], dp[100005][3]; int n; int calc(int i, int k) { if (i == -1) return 0; if (dp[i][k] != -1) return dp[i][k]; return dp[i][k] = max(arr[i][k] + calc(i - 1, (k + 1) % 3), arr[i][k] + calc(i - 1, (k + 2) % 3)); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; f(i, n) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } mem(dp, -1); int a1 = calc(n - 1, 0); mem(dp, -1); int a2 = calc(n - 1, 1); mem(dp, -1); int a3 = calc(n - 1, 2); cout << max(a1, max(a2, a3)) << "\n"; return 0; }
// Includes #include <algorithm> #include <assert.h> #include <bitset> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <utility> #include <vector> // Defines #define pb push_back #define mp make_pair #define fr first #define sc second #define MOD 1000000007 #define len(x) x.size() #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define all(v) v.begin(), v.end() #define alla(a, n) a, a + n #define mem(name, value) memset(name, value, sizeof(name)) #define f(i, a) for (int i = 0; i < a; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vll> vvll; typedef vector<string> vs; int arr[100005][3], dp[100005][3]; int n; int calc(int i, int k) { if (i == -1) return 0; if (dp[i][k] != -1) return dp[i][k]; return dp[i][k] = max(arr[i][k] + calc(i - 1, (k + 1) % 3), arr[i][k] + calc(i - 1, (k + 2) % 3)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; f(i, n) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } mem(dp, -1); int a1 = calc(n - 1, 0); mem(dp, -1); int a2 = calc(n - 1, 1); mem(dp, -1); int a3 = calc(n - 1, 2); cout << max(a1, max(a2, a3)) << "\n"; return 0; }
delete
66
70
66
66
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define ld long double #define ull unsigned long long int #define MOD (ll)(1e9 + 7) #define vi vector<int> #define vl vector<long> #define vll vector<ll> #define vs vector<string> #define pll pair<ll, ll> #define mll map<ll, ll> #define len(x) x.length() #define all(x) x.begin(), x.end() #define deb1(x) cout << #x << " " << x << endl; #define deb2(x, y) cout << #x << " " << x << ' ' << #y << " " << y << endl; #define deb3(x, y, z) \ cout << #x << " " << x << ' ' << #y << " " << y << ' ' << #z \ << " " << z << endl; #define debug1(x) cerr << #x << " " << x << endl; #define debug2(x, y) \ cerr << #x << " " << x << ' ' << #y << " " << y << endl; #define debug3(x, y, z) \ cerr << #x << " " << x << ' ' << #y << " " << y << ' ' << #z \ << " " << z << endl; #define info(s) cerr << s << " " << endl; #define fr(a, b, c) for (auto a = b; b < c ? a < c : a > c; b < c ? a++ : a--) #define frc(a, b, c) for (auto a = b; a != c; a++) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define clr(x) memset(x, 0, sizeof(x)) #define GR (double)(1 + sqrt(5)) / 2 #define fib(n) (ll) round(pow(GR, n) / sqrt(5)) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define out1(x) cout << x << " " << endl #define out2(x, y) cout << x << " " << y << endl #define SORT(a) sort(all(a)); #define SORTR(a) sort(all(a), greater<ll>()); #define ARRAY(a, n) \ vll a; \ fr(i, 0, n) { \ ll temp; \ cin >> temp; \ a.pb(temp); \ } #define PRINT(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define MAX 100050 #define pb push_back #define mp make_pair #define F first #define S second template <typename T> ostream &operator<<(ostream &out, const vector<T> &v); template <typename T> istream &operator>>(istream &in, vector<T> &v); int dp[100004][3]; int happniess(vi &a, vi &b, vi &c, int n, int x) { if (n == 0) return 0; int ans1, ans2, ans3; ans1 = ans2 = ans3 = INT_MIN; if (x != 1) ans1 = a[n - 1] + happniess(a, b, c, n - 1, 1); if (x != 2) ans2 = b[n - 1] + happniess(a, b, c, n - 1, 2); if (x != 3) ans3 = c[n - 1] + happniess(a, b, c, n - 1, 3); return max({ans1, ans2, ans3}); } void solve() { int n; cin >> n; vi a(n), b(n), c(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; memset(dp, -1, sizeof(dp)); int ans = happniess(a, b, c, n, 0); cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif FIO; ll test; test = 1; // cin>>test;for(ll i=1;i<=test;i++) solve(); return 0; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { int i = 0; for (T x : v) { out << x; (i++ != v.size()) ? out << ' ' : out << '\n'; } return out; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (T &i : v) in >> i; return in; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define ld long double #define ull unsigned long long int #define MOD (ll)(1e9 + 7) #define vi vector<int> #define vl vector<long> #define vll vector<ll> #define vs vector<string> #define pll pair<ll, ll> #define mll map<ll, ll> #define len(x) x.length() #define all(x) x.begin(), x.end() #define deb1(x) cout << #x << " " << x << endl; #define deb2(x, y) cout << #x << " " << x << ' ' << #y << " " << y << endl; #define deb3(x, y, z) \ cout << #x << " " << x << ' ' << #y << " " << y << ' ' << #z \ << " " << z << endl; #define debug1(x) cerr << #x << " " << x << endl; #define debug2(x, y) \ cerr << #x << " " << x << ' ' << #y << " " << y << endl; #define debug3(x, y, z) \ cerr << #x << " " << x << ' ' << #y << " " << y << ' ' << #z \ << " " << z << endl; #define info(s) cerr << s << " " << endl; #define fr(a, b, c) for (auto a = b; b < c ? a < c : a > c; b < c ? a++ : a--) #define frc(a, b, c) for (auto a = b; a != c; a++) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define clr(x) memset(x, 0, sizeof(x)) #define GR (double)(1 + sqrt(5)) / 2 #define fib(n) (ll) round(pow(GR, n) / sqrt(5)) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define out1(x) cout << x << " " << endl #define out2(x, y) cout << x << " " << y << endl #define SORT(a) sort(all(a)); #define SORTR(a) sort(all(a), greater<ll>()); #define ARRAY(a, n) \ vll a; \ fr(i, 0, n) { \ ll temp; \ cin >> temp; \ a.pb(temp); \ } #define PRINT(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define MAX 100050 #define pb push_back #define mp make_pair #define F first #define S second template <typename T> ostream &operator<<(ostream &out, const vector<T> &v); template <typename T> istream &operator>>(istream &in, vector<T> &v); int dp[100004][3]; int happniess(vi &a, vi &b, vi &c, int n, int x) { // if(n==0) // return 0; // int ans1,ans2,ans3; // ans1=ans2=ans3=INT_MIN; // if(x!=1) // ans1 = a[n-1]+happniess(a,b,c,n-1,1); // if(x!=2) // ans2 = b[n-1]+happniess(a,b,c,n-1,2); // if(x!=3) // ans3 = c[n-1]+happniess(a,b,c,n-1,3); // return max({ans1,ans2,ans3}); dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 1; i < n; i++) { dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]); } return max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); } void solve() { int n; cin >> n; vi a(n), b(n), c(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; memset(dp, -1, sizeof(dp)); int ans = happniess(a, b, c, n, 0); cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif FIO; ll test; test = 1; // cin>>test;for(ll i=1;i<=test;i++) solve(); return 0; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { int i = 0; for (T x : v) { out << x; (i++ != v.size()) ? out << ' ' : out << '\n'; } return out; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (T &i : v) in >> i; return in; }
replace
68
79
68
90
TLE
p03162
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A, B, C; vector<long long> Ma, Mb, Mc; for (int i = 0; i < N; i++) { int a, b, c; cin >> a >> b >> c; A.push_back(a); B.push_back(b); C.push_back(c); } Ma.push_back(A[0]); Mb.push_back(B[0]); Mc.push_back(C[0]); for (int i = 1; i < N; i++) { Ma[i] = max(Mb[i - 1] + A[i], Mc[i - 1] + A[i]); Mb[i] = max(Ma[i - 1] + B[i], Mc[i - 1] + B[i]); Mc[i] = max(Ma[i - 1] + C[i], Mb[i - 1] + C[i]); } cout << max(Ma[N - 1], max(Mb[N - 1], Mc[N - 1])); return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A, B, C; vector<long long> Ma, Mb, Mc; for (int i = 0; i < N; i++) { int a, b, c; cin >> a >> b >> c; A.push_back(a); B.push_back(b); C.push_back(c); } Ma.push_back(A[0]); Mb.push_back(B[0]); Mc.push_back(C[0]); for (int i = 1; i < N; i++) { Ma.push_back(max(Mb[i - 1] + A[i], Mc[i - 1] + A[i])); Mb.push_back(max(Ma[i - 1] + B[i], Mc[i - 1] + B[i])); Mc.push_back(max(Ma[i - 1] + C[i], Mb[i - 1] + C[i])); } cout << max(Ma[N - 1], max(Mb[N - 1], Mc[N - 1])); return 0; }
replace
23
26
23
26
0
p03162
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <math.h> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> //------------------------------------------------------------------------------ #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define ll long long #define pb emplace_back #define mp make_pair #define sf scanf #define pf printf #define F first #define S second //------------------------------------------------------------------------------ using namespace std; ll int n, dp[100010][4], a[100010][4] = {0}; ll int vacation(ll int day, ll int last_activity) { if (dp[day][last_activity] != -1) return dp[day][last_activity]; if (day >= n) return 0; ll int happy = -999999999999; for (int i = 0; i < 3; i++) { if (i != last_activity) happy = max(happy, a[day][i] + vacation(day + 1, i)); } return happy; } int main() { fio; memset(dp, -1, sizeof(dp)); ll int x; sf("%lld", &n); for (ll int i = 0; i < n; i++) for (int j = 0; j < 3; j++) sf("%lld", &a[i][j]); x = vacation(0, 5); pf("%lld\n", x); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <math.h> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> //------------------------------------------------------------------------------ #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define ll long long #define pb emplace_back #define mp make_pair #define sf scanf #define pf printf #define F first #define S second //------------------------------------------------------------------------------ using namespace std; ll int n, dp[100010][4], a[100010][4] = {0}; ll int vacation(ll int day, ll int last_activity) { if (dp[day][last_activity] != -1) return dp[day][last_activity]; if (day >= n) return 0; ll int happy = -999999999999; for (int i = 0; i < 3; i++) { if (i != last_activity) happy = max(happy, a[day][i] + vacation(day + 1, i)); } return dp[day][last_activity] = happy; } int main() { fio; memset(dp, -1, sizeof(dp)); ll int x; sf("%lld", &n); for (ll int i = 0; i < n; i++) for (int j = 0; j < 3; j++) sf("%lld", &a[i][j]); x = vacation(0, 5); pf("%lld\n", x); return 0; }
replace
40
41
40
41
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int func(int n, int m, int A[][3], int dp[][3]) { if (n < 0) return 0; if (n == 0) return 0; int maxi = 0; for (int i = 0; i <= 2; i++) { if (i != m) { int x = A[n - 1][i] + func(n - 1, i, A, dp); if (x > maxi) maxi = x; } } return dp[n][m] = maxi; } int main() { int n; cin >> n; int A[n][3]; for (int i = 0; i < n; i++) cin >> A[i][0] >> A[i][1] >> A[i][2]; int dp[n + 1][3]; for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i][j] = -1; dp[n][0] = max(A[n - 1][1] + func(n - 1, 1, A, dp), A[n - 1][2] + func(n - 1, 2, A, dp)); dp[n][1] = max(A[n - 1][0] + func(n - 1, 0, A, dp), A[n - 1][2] + func(n - 1, 2, A, dp)); dp[n][2] = max(A[n - 1][0] + func(n - 1, 0, A, dp), A[n - 1][1] + func(n - 1, 1, A, dp)); cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl; }
#include <bits/stdc++.h> using namespace std; int func(int n, int m, int A[][3], int dp[][3]) { if (n < 0) return 0; if (n == 0) return 0; if (dp[n][m] != -1) return dp[n][m]; int maxi = 0; for (int i = 0; i <= 2; i++) { if (i != m) { int x = A[n - 1][i] + func(n - 1, i, A, dp); if (x > maxi) maxi = x; } } return dp[n][m] = maxi; } int main() { int n; cin >> n; int A[n][3]; for (int i = 0; i < n; i++) cin >> A[i][0] >> A[i][1] >> A[i][2]; int dp[n + 1][3]; for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i][j] = -1; dp[n][0] = max(A[n - 1][1] + func(n - 1, 1, A, dp), A[n - 1][2] + func(n - 1, 2, A, dp)); dp[n][1] = max(A[n - 1][0] + func(n - 1, 0, A, dp), A[n - 1][2] + func(n - 1, 2, A, dp)); dp[n][2] = max(A[n - 1][0] + func(n - 1, 0, A, dp), A[n - 1][1] + func(n - 1, 1, A, dp)); cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl; }
insert
7
7
7
9
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long a[100001], b[100001], c[100001], dp[1001][1001], n; long long cal(long long idx, long long v) { // cout<<dp[idx][v]<<' '<<idx<<endl; if (idx > n) return 0; if (dp[idx][v] != -1) return dp[idx][v]; else dp[idx][v] = 0; if (v == 0) dp[idx][v] = max(cal(idx + 1, 1) + a[idx], max(cal(idx + 1, 2) + b[idx], cal(idx + 1, 3) + c[idx])); if (v == 1) dp[idx][v] = max(cal(idx + 1, v + 1) + b[idx], cal(idx + 1, v + 2) + c[idx]); if (v == 2) dp[idx][v] = max(cal(idx + 1, v - 1) + a[idx], cal(idx + 1, v + 1) + c[idx]); if (v == 3) dp[idx][v] = max(cal(idx + 1, v - 2) + a[idx], cal(idx + 1, v - 1) + b[idx]); return dp[idx][v]; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for (int i = 1; i <= n; i++) for (int j = 0; j <= 3; j++) dp[i][j] = -1; cout << cal(1, 0); }
#include <bits/stdc++.h> using namespace std; long long a[100001], b[100001], c[100001], dp[100001][3], n; long long cal(long long idx, long long v) { // cout<<dp[idx][v]<<' '<<idx<<endl; if (idx > n) return 0; if (dp[idx][v] != -1) return dp[idx][v]; else dp[idx][v] = 0; if (v == 0) dp[idx][v] = max(cal(idx + 1, 1) + a[idx], max(cal(idx + 1, 2) + b[idx], cal(idx + 1, 3) + c[idx])); if (v == 1) dp[idx][v] = max(cal(idx + 1, v + 1) + b[idx], cal(idx + 1, v + 2) + c[idx]); if (v == 2) dp[idx][v] = max(cal(idx + 1, v - 1) + a[idx], cal(idx + 1, v + 1) + c[idx]); if (v == 3) dp[idx][v] = max(cal(idx + 1, v - 2) + a[idx], cal(idx + 1, v - 1) + b[idx]); return dp[idx][v]; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for (int i = 1; i <= n; i++) for (int j = 0; j <= 3; j++) dp[i][j] = -1; cout << cal(1, 0); }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1e9 + 5 using namespace std; int solve() { int n; cin >> n; vector<int> dp(3); for (int day = 0; day < n; day++) { vector<int> new_dp(3); vector<int> a(3); for (int i = 0; i < 3; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + a[j]); } } } dp = new_dp; } return max({dp[0], dp[1], dp[2]}); } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); /* int t; cin >> t; while (t--) */ cout << solve() << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1e9 + 5 using namespace std; int solve() { int n; cin >> n; vector<int> dp(3); for (int day = 0; day < n; day++) { vector<int> new_dp(3); vector<int> a(3); for (int i = 0; i < 3; i++) { cin >> a[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + a[j]); } } } dp = new_dp; } return max({dp[0], dp[1], dp[2]}); } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); /* int t; cin >> t; while (t--) */ cout << solve() << "\n"; return 0; }
replace
19
21
19
21
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; 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; cin >> n; vector<vector<int>> data(n, vector<int>(3)); REP(i, n) { REP(j, 3) { cin >> data[i][j]; } } vector<vector<ll>> dp(100010, vector<ll>(3)); REP(i, n) { REP(j, 3) { REP(k, 3) { if (j != k) chmax(dp[i + 1][k], dp[i][j] + data[i][k]); } } } ll ans = 0; REP(i, n) ans = max(ans, dp[n][i]); cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; 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; cin >> n; vector<vector<int>> data(n, vector<int>(3)); REP(i, n) { REP(j, 3) { cin >> data[i][j]; } } vector<vector<ll>> dp(100010, vector<ll>(3)); REP(i, n) { REP(j, 3) { REP(k, 3) { if (j != k) chmax(dp[i + 1][k], dp[i][j] + data[i][k]); } } } ll ans = 0; REP(i, 3) ans = max(ans, dp[n][i]); cout << ans << endl; }
replace
42
43
42
43
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long lli; typedef long double lld; #define mod 1000000007 #define mod2 998244353 #define fori(n) for (int i = 0; i < n; i++) #define forj(n) for (int j = 0; j < n; j++) #define pb push_back #define mp make_pair #define F first #define S second #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define sortvec(a) sort(a.begin(), a.end()) #define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl #define cerr \ if (true) \ cerr void print() { cout << endl; } template <typename T, typename... Args> void print(T a, Args... args) { cout << a << " "; print(args...); } lli llipowerp(lli x, lli y, lli p = LLONG_MAX) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } lli binarySearch(vector<int> arr, int l, int r, int x) { if (r >= l) { lli mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } template <typename T> inline void printvec(vector<T> inp) { for (auto it : inp) cout << it << " "; cout << endl; } //--------------------------------------------------------------------------------- vector<vector<int>> h; int dp[(int)1e5 + 5][3]; int fill(int n, int i) { if (dp[n][i] != -1) return dp[n][i]; if (n == 1) { return h[1][i]; } return max(h[n][i] + fill(n - 1, (i + 1) % 3), h[n][i] + fill(n - 1, (i + 2) % 3)); } int main() { int n; cin >> n; h.resize(n + 1); fori(n + 1) h[i].resize(3); fori(n) { cin >> h[i + 1][0] >> h[i + 1][1] >> h[i + 1][2]; } memset(dp, -1, sizeof(dp)); cout << max({fill(n, 0), fill(n, 1), fill(n, 2)}) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long lli; typedef long double lld; #define mod 1000000007 #define mod2 998244353 #define fori(n) for (int i = 0; i < n; i++) #define forj(n) for (int j = 0; j < n; j++) #define pb push_back #define mp make_pair #define F first #define S second #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define sortvec(a) sort(a.begin(), a.end()) #define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl #define cerr \ if (true) \ cerr void print() { cout << endl; } template <typename T, typename... Args> void print(T a, Args... args) { cout << a << " "; print(args...); } lli llipowerp(lli x, lli y, lli p = LLONG_MAX) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } lli binarySearch(vector<int> arr, int l, int r, int x) { if (r >= l) { lli mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } template <typename T> inline void printvec(vector<T> inp) { for (auto it : inp) cout << it << " "; cout << endl; } //--------------------------------------------------------------------------------- vector<vector<int>> h; int dp[(int)1e5 + 5][3]; int fill(int n, int i) { if (dp[n][i] != -1) return dp[n][i]; if (n == 1) { return h[1][i]; } dp[n][i] = max(h[n][i] + fill(n - 1, (i + 1) % 3), h[n][i] + fill(n - 1, (i + 2) % 3)); return dp[n][i]; } int main() { int n; cin >> n; h.resize(n + 1); fori(n + 1) h[i].resize(3); fori(n) { cin >> h[i + 1][0] >> h[i + 1][1] >> h[i + 1][2]; } memset(dp, -1, sizeof(dp)); cout << max({fill(n, 0), fill(n, 1), fill(n, 2)}) << endl; }
replace
61
63
61
64
TLE
p03162
C++
Runtime Error
// Author:: Pham Ngoc Minh- Chuyen Thai Binh #include <bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long #define fl float #define db double #define ii pair<ll, ll> #define pii pair<ii, ii> #define ford(i, a, b) for (int i = a; i <= b; i++) #define foru(i, a, b) for (int i = a; i >= b; i--) #define forv(i, a, b) for (int i = a; i < b; i++) #define oo 10000000000001 #define ooo -1000000000001 #define bost \ ios_base::sync_with_stdio(false); \ cin.tie(0); int const maxn = 1e4 + 5; int n, dp[5][maxn], a, b, c; int main() { bost cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b >> c; dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + a; dp[2][i] = max(dp[1][i - 1], dp[3][i - 1]) + b; dp[3][i] = max(dp[1][i - 1], dp[2][i - 1]) + c; } cout << max(dp[1][n], max(dp[2][n], dp[3][n])); return 0; } // I love Chuyen Thai Binh Verry much ! Now, you alaways in my code of me <3 // Chuyen Thai Binh La Nha :>>
// Author:: Pham Ngoc Minh- Chuyen Thai Binh #include <bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long #define fl float #define db double #define ii pair<ll, ll> #define pii pair<ii, ii> #define ford(i, a, b) for (int i = a; i <= b; i++) #define foru(i, a, b) for (int i = a; i >= b; i--) #define forv(i, a, b) for (int i = a; i < b; i++) #define oo 10000000000001 #define ooo -1000000000001 #define bost \ ios_base::sync_with_stdio(false); \ cin.tie(0); int const maxn = 1e5 + 5; int n, dp[5][maxn], a, b, c; int main() { bost cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b >> c; dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + a; dp[2][i] = max(dp[1][i - 1], dp[3][i - 1]) + b; dp[3][i] = max(dp[1][i - 1], dp[2][i - 1]) + c; } cout << max(dp[1][n], max(dp[2][n], dp[3][n])); return 0; } // I love Chuyen Thai Binh Verry much ! Now, you alaways in my code of me <3 // Chuyen Thai Binh La Nha :>>
replace
18
19
18
19
0
p03162
Python
Time Limit Exceeded
import sys sys.setrecursionlimit(10**6) n = int(input()) abc = [list(map(int, input().split())) for _ in range(n)] def recur(i, last_index, v): if i == n: return v res = -1 for j in range(3): if j == last_index: continue res = max(res, recur(i + 1, j, v + abc[i][j])) return res print(recur(0, -1, 0))
import sys sys.setrecursionlimit(10**6) n = int(input()) abc = [list(map(int, input().split())) for _ in range(n)] dp = [[0, 0, 0] for _ in range(n)] dp[0] = abc[0] for i in range(1, n): dp[i][0] = abc[i][0] + max(dp[i - 1][1], dp[i - 1][2]) dp[i][1] = abc[i][1] + max(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = abc[i][2] + max(dp[i - 1][0], dp[i - 1][1]) print(max(dp[-1]))
replace
7
20
7
14
TLE
p03162
Python
Time Limit Exceeded
import numpy as np N = int(input()) values = np.array([list(map(int, input().split(" "))) for _ in range(N)]) dp = np.zeros(shape=(N, 3), dtype=int) dp[0] = values[0] for i in range(1, N): dp[i][0] = np.max(values[i][0] + dp[i - 1][1:3]) dp[i][1] = np.max(values[i][1] + dp[i - 1][0::2]) dp[i][2] = np.max(values[i][2] + dp[i - 1][:2]) print(np.max(dp[N - 1]))
import numpy as np N = int(input()) values = np.array([list(map(int, input().split(" "))) for _ in range(N)]) dp = np.zeros(shape=(N, 3), dtype=int) dp[0] = values[0] for i in range(1, N): prev = dp[i - 1] dp[i][0] = values[i][0] + max(prev[1], prev[2]) dp[i][1] = values[i][1] + max(prev[0], prev[2]) dp[i][2] = values[i][2] + max(prev[0], prev[1]) print(np.max(dp[N - 1]))
replace
10
13
10
14
TLE
p03162
Python
Runtime Error
import sys sys.setrecursionlimit(10**7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) ABC = [[int(x) for x in readline().split()] for _ in range(N)] dp = [[0] * 3 for _ in range(10 * 5 + 10)] for i in range(N): for j in range(3): for k in range(3): if j != k: dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + ABC[i][k]) ans = max(dp[N]) print(ans)
import sys sys.setrecursionlimit(10**7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) ABC = [[int(x) for x in readline().split()] for _ in range(N)] dp = [[0] * 3 for _ in range(10**5 + 10)] for i in range(N): for j in range(3): for k in range(3): if j != k: dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + ABC[i][k]) ans = max(dp[N]) print(ans)
replace
11
12
11
12
0
p03162
C++
Runtime Error
#include <stdio.h> #include <vector> using namespace std; const int C = 150001; int n, k, a, b, c, dp[2][C]; int abs(int a) { return (a > 0) ? (a) : (-a); } int main() { int j; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d %d", &a, &b, &c); dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a; dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b; dp[2][i] = max(dp[1][i - 1], dp[0][i - 1]) + c; } printf("%d\n", max(dp[2][n], max(dp[1][n], dp[0][n]))); return 0; }
#include <stdio.h> #include <vector> using namespace std; const int C = 150001; int n, k, a, b, c, dp[3][C]; int abs(int a) { return (a > 0) ? (a) : (-a); } int main() { int j; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d %d", &a, &b, &c); dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a; dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b; dp[2][i] = max(dp[1][i - 1], dp[0][i - 1]) + c; } printf("%d\n", max(dp[2][n], max(dp[1][n], dp[0][n]))); return 0; }
replace
5
6
5
6
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { int N; cin >> N; ll dp[11000][2][2][2]; for (int i = 0; i < 11000; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 2; l++) dp[i][j][k][l] = 0; ll a[N + 1]; ll b[N + 1]; ll c[N + 1]; for (int i = 0; i < N; i++) { cin >> a[i + 1] >> b[i + 1] >> c[i + 1]; } dp[1][1][0][0] = a[1]; dp[1][0][1][0] = b[1]; dp[1][0][0][1] = c[1]; for (int i = 1; i < N; i++) { dp[i + 1][1][0][0] = max(dp[i][0][1][0], dp[i][0][0][1]) + a[i + 1]; dp[i + 1][0][1][0] = max(dp[i][1][0][0], dp[i][0][0][1]) + b[i + 1]; dp[i + 1][0][0][1] = max(dp[i][1][0][0], dp[i][0][1][0]) + c[i + 1]; } ll ans = max(dp[N][1][0][0], dp[N][0][1][0]); ans = max(ans, dp[N][0][0][1]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { int N; cin >> N; ll dp[110000][2][2][2]; for (int i = 0; i < 110000; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 2; l++) dp[i][j][k][l] = 0; ll a[N + 1]; ll b[N + 1]; ll c[N + 1]; for (int i = 0; i < N; i++) { cin >> a[i + 1] >> b[i + 1] >> c[i + 1]; } dp[1][1][0][0] = a[1]; dp[1][0][1][0] = b[1]; dp[1][0][0][1] = c[1]; for (int i = 1; i < N; i++) { dp[i + 1][1][0][0] = max(dp[i][0][1][0], dp[i][0][0][1]) + a[i + 1]; dp[i + 1][0][1][0] = max(dp[i][1][0][0], dp[i][0][0][1]) + b[i + 1]; dp[i + 1][0][0][1] = max(dp[i][1][0][0], dp[i][0][1][0]) + c[i + 1]; } ll ans = max(dp[N][1][0][0], dp[N][0][1][0]); ans = max(ans, dp[N][0][0][1]); cout << ans << endl; return 0; }
replace
6
8
6
8
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template <typename T, typename U> using mapv = map<T, vector<U>>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } #define MOD097 1000000007 ///// For Debug #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } // ๆๅ‡บๆ™‚ใฏใ‚ณใƒกใƒณใƒˆใ‚ขใ‚ฆใƒˆ // #define LOCAL #define DEBUG_ #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// struct ABC { ll a; ll b; ll c; }; int main() { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll N; cin >> N; vector<ABC> X(N); rep(i, N) { ll a, b, c; cin >> a >> b >> c; X[i] = {a, b, c}; } vector<vecl> dp(N + 1, vecl(3, 0)); rep(i, N) { auto x = X[i]; ll a = x.a; ll b = x.b; ll c = x.c; chmax(dp[i + 1]['b'], max(dp[i]['a'] + b, dp[i]['c'] + b)); chmax(dp[i + 1]['c'], max(dp[i]['a'] + c, dp[i]['b'] + c)); chmax(dp[i + 1]['a'], max(dp[i]['b'] + a, dp[i]['c'] + a)); } ll ans = 0; rep(i, 3) { ans = max(ans, dp[N]['a' + i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template <typename T, typename U> using mapv = map<T, vector<U>>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } #define MOD097 1000000007 ///// For Debug #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } // ๆๅ‡บๆ™‚ใฏใ‚ณใƒกใƒณใƒˆใ‚ขใ‚ฆใƒˆ // #define LOCAL #define DEBUG_ #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// struct ABC { ll a; ll b; ll c; }; int main() { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll N; cin >> N; vector<ABC> X(N); rep(i, N) { ll a, b, c; cin >> a >> b >> c; X[i] = {a, b, c}; } vector<vecl> dp(N + 1, vecl(300, 0)); rep(i, N) { auto x = X[i]; ll a = x.a; ll b = x.b; ll c = x.c; chmax(dp[i + 1]['b'], max(dp[i]['a'] + b, dp[i]['c'] + b)); chmax(dp[i + 1]['c'], max(dp[i]['a'] + c, dp[i]['b'] + c)); chmax(dp[i + 1]['a'], max(dp[i]['b'] + a, dp[i]['c'] + a)); } ll ans = 0; rep(i, 3) { ans = max(ans, dp[N]['a' + i]); } cout << ans << endl; return 0; }
replace
128
129
128
129
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define nl "\n" #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define bs binary_search #define pll pair<ll, ll> #define ppll pair<ll, pll> #define sll stack<ll> #define qll queue<ll> #define vll vector<ll> #define vpll vector<pll> #define vc vector<char> #define matrix vector<vector<ll>> #define all(x) x.begin(), x.end() #define loop(i, s, n) for (ll i = s; i < n; i++) #define rloop(i, s, n) for (ll i = s; i >= n; i--) #define test \ ll t; \ cin >> t; \ while (t--) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll mod = 1000000007; double pi = 3.1415926535; // const ll mxn = 1e6 + 1; // ll a[mxn]; // ll num_generator() // { // return rand() % 1000; // } // void array_generator(ll n) // { // loop(i, 0, n) a[i] = rand() % 100; // } void solve() { ll n; cin >> n; ll a[n][3]; loop(i, 0, n) { loop(j, 0, 3) cin >> a[i][j]; } ll dp[n + 1][4]; memset(dp, 0, sizeof(dp)); loop(i, 1, n + 1) { loop(j, 1, 4) { if (j == 1) dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j + 1], dp[i - 1][j + 2]); else if (j == 2) dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j - 1], dp[i - 1][j + 1]); else dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j - 2], dp[i - 1][j - 1]); } } cout << max({dp[n][1], dp[n][2], dp[n][3]}) << nl; } int main() { fast_io; #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif // test{ solve(); // } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define nl "\n" #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define bs binary_search #define pll pair<ll, ll> #define ppll pair<ll, pll> #define sll stack<ll> #define qll queue<ll> #define vll vector<ll> #define vpll vector<pll> #define vc vector<char> #define matrix vector<vector<ll>> #define all(x) x.begin(), x.end() #define loop(i, s, n) for (ll i = s; i < n; i++) #define rloop(i, s, n) for (ll i = s; i >= n; i--) #define test \ ll t; \ cin >> t; \ while (t--) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll mod = 1000000007; double pi = 3.1415926535; // const ll mxn = 1e6 + 1; // ll a[mxn]; // ll num_generator() // { // return rand() % 1000; // } // void array_generator(ll n) // { // loop(i, 0, n) a[i] = rand() % 100; // } void solve() { ll n; cin >> n; ll a[n][3]; loop(i, 0, n) { loop(j, 0, 3) cin >> a[i][j]; } ll dp[n + 1][4]; memset(dp, 0, sizeof(dp)); loop(i, 1, n + 1) { loop(j, 1, 4) { if (j == 1) dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j + 1], dp[i - 1][j + 2]); else if (j == 2) dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j - 1], dp[i - 1][j + 1]); else dp[i][j] = a[i - 1][j - 1] + max(dp[i - 1][j - 2], dp[i - 1][j - 1]); } } cout << max({dp[n][1], dp[n][2], dp[n][3]}) << nl; } int main() { fast_io; // #ifndef ONLINE_JUDGE // freopen("input1.txt", "r", stdin); // freopen("output1.txt", "w", stdout); // #endif // test{ solve(); // } return 0; }
replace
68
72
68
72
-11
p03162
C++
Runtime Error
#include <iostream> using namespace std; typedef long long ll; ll dp[100005][3]; int main(int argc, char *argv[]) { int N, a[10005] = {0}, b[10005] = {0}, c[10005] = {0}; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 0; i < N; i++) { dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1]); dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1]); dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1]); } cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl; return 0; }
#include <iostream> using namespace std; typedef long long ll; ll dp[100005][3]; int main(int argc, char *argv[]) { int N, a[100005] = {0}, b[100005] = {0}, c[100005] = {0}; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (int i = 0; i < N; i++) { dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1]); dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1]); dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1]); } cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl; return 0; }
replace
9
10
9
10
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { int n; cin >> n; int a[n + 1][3]; rep(1, n + 1) cin >> a[i][0] >> a[i][1] >> a[i][2]; int dp[n + 1][3]; int count[n][3]; rep0(3) dp[0][i] = count[0][i] = 0; rep(1, n + 1) { repi(j, 0, 3) { int m = 0; repi(k, 0, 3) if (k != j) m = max(m, dp[i - 1][k] + a[i][j]); dp[i][j] = m; // cout<<m<<endl; } repi(j, 0, 3) count[i][j] = 1; repi(j, 0, 3) { if (count[i - 1][j] == 1) continue; if (dp[i][j] <= dp[i - 1][j] + a[i][j]) { count[i][j] = count[i - 1][j] + 1; dp[i][j] = dp[i - 1][j] + a[i][j]; } } // repi(j,0,3) cout<<dp[i][j]<<" ";cout<<endl; } int ans = 0; rep0(3) ans = max(ans, dp[n][i]); cout << ans; r0 } signed main() { asdf #ifndef ONLINE_JUDGE inputoutput #endif int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { int n; cin >> n; int a[n + 1][3]; rep(1, n + 1) cin >> a[i][0] >> a[i][1] >> a[i][2]; int dp[n + 1][3]; int count[n][3]; rep0(3) dp[0][i] = count[0][i] = 0; rep(1, n + 1) { repi(j, 0, 3) { int m = 0; repi(k, 0, 3) if (k != j) m = max(m, dp[i - 1][k] + a[i][j]); dp[i][j] = m; // cout<<m<<endl; } repi(j, 0, 3) count[i][j] = 1; repi(j, 0, 3) { if (count[i - 1][j] == 1) continue; if (dp[i][j] <= dp[i - 1][j] + a[i][j]) { count[i][j] = count[i - 1][j] + 1; dp[i][j] = dp[i - 1][j] + a[i][j]; } } // repi(j,0,3) cout<<dp[i][j]<<" ";cout<<endl; } int ans = 0; rep0(3) ans = max(ans, dp[n][i]); cout << ans; r0 } signed main() { asdf int t = 1; // cin>>t; while (t--) { solve(); } }
replace
112
115
112
113
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vb = vector<bool>; using vs = vector<string>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const ld eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define pb push_back #define eb emplace_back #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) ll activities[10005][3] = {0}; ll scoreAfterDay[10005][3] = {0}; int main() { cin.sync_with_stdio(0); ll n; cin >> n; FOR(i, 1, n + 1) { ll a, b, c; cin >> a >> b >> c; activities[i][0] = a; activities[i][1] = b; activities[i][2] = c; } FOR(i, 1, n + 1) { FOR(j, 0, 3) { ll max = 0; FOR(k, 0, 3) { if (k != j) { ll tmp = scoreAfterDay[i - 1][k] + activities[i][j]; if (tmp > max) max = tmp; } } scoreAfterDay[i][j] = max; } } cout << max(max(scoreAfterDay[n][0], scoreAfterDay[n][1]), scoreAfterDay[n][2]); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vb = vector<bool>; using vs = vector<string>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const ld eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define pb push_back #define eb emplace_back #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) ll activities[100005][3] = {0}; ll scoreAfterDay[100005][3] = {0}; int main() { cin.sync_with_stdio(0); ll n; cin >> n; FOR(i, 1, n + 1) { ll a, b, c; cin >> a >> b >> c; activities[i][0] = a; activities[i][1] = b; activities[i][2] = c; } FOR(i, 1, n + 1) { FOR(j, 0, 3) { ll max = 0; FOR(k, 0, 3) { if (k != j) { ll tmp = scoreAfterDay[i - 1][k] + activities[i][j]; if (tmp > max) max = tmp; } } scoreAfterDay[i][j] = max; } } cout << max(max(scoreAfterDay[n][0], scoreAfterDay[n][1]), scoreAfterDay[n][2]); }
replace
28
30
28
30
0
p03162
C++
Time Limit Exceeded
// Suraj Saste #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define pi pair<ll, ll> #define in insert #define fe first #define se second #define ms(x, i) memset(x, i, sizeof(x)) #define prec(x) cout << std::setprecision(x) #define mod 1000000007 #define all(x) x.begin(), x.end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) ll fpow(ll n, ll k, ll p = mod) { ll r = 1; n = n % p; while (k > 0) { if (k & 1) { r = (r * n) % p; } k = k >> 1; n = (n * n) % p; } return r; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } int main() { fast; ll n; cin >> n; ll a[n][3]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 3; j++) cin >> a[i][j]; } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (ll i = 1; i < n; i++) { for (ll j = 0; j < n; j++) { if (j == 0) { dp[i][j] = max(a[i][j] + dp[i - 1][1], a[i][j] + dp[i - 1][2]); } else if (j == 1) { dp[i][j] = max(a[i][j] + dp[i - 1][0], a[i][j] + dp[i - 1][2]); } else dp[i][j] = max(a[i][j] + dp[i - 1][1], a[i][j] + dp[i - 1][0]); } } ll ans = -1; for (ll j = 0; j < 3; j++) { ans = max(ans, dp[n - 1][j]); } cout << ans; return 0; }
// Suraj Saste #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define pi pair<ll, ll> #define in insert #define fe first #define se second #define ms(x, i) memset(x, i, sizeof(x)) #define prec(x) cout << std::setprecision(x) #define mod 1000000007 #define all(x) x.begin(), x.end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) ll fpow(ll n, ll k, ll p = mod) { ll r = 1; n = n % p; while (k > 0) { if (k & 1) { r = (r * n) % p; } k = k >> 1; n = (n * n) % p; } return r; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } int main() { fast; ll n; cin >> n; ll a[n][3]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 3; j++) cin >> a[i][j]; } ll dp[n][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (ll i = 1; i < n; i++) { for (ll j = 0; j < 3; j++) { if (j == 0) { dp[i][j] = max(a[i][j] + dp[i - 1][1], a[i][j] + dp[i - 1][2]); } else if (j == 1) { dp[i][j] = max(a[i][j] + dp[i - 1][0], a[i][j] + dp[i - 1][2]); } else dp[i][j] = max(a[i][j] + dp[i - 1][1], a[i][j] + dp[i - 1][0]); } } ll ans = -1; for (ll j = 0; j < 3; j++) { ans = max(ans, dp[n - 1][j]); } cout << ans; return 0; }
replace
58
59
58
59
TLE
p03162
C++
Time Limit Exceeded
#include <fstream> #include <iostream> #include <vector> using namespace std; int rezolvare(int n, vector<int> a, vector<int> b, vector<int> c, int imp, int **&memo) { int rezultat = 0; if (n == -1) return 0; if (memo[n][imp] != 0) return memo[n][imp]; if (imp == 0) { int temp1, temp2, temp3; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp1, max(temp2, temp3)); } else if (imp == 1) { int temp2, temp3; temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp2, temp3); } else if (imp == 2) { int temp1, temp3; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp1, temp3); } else if (imp == 3) { int temp1, temp2; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); rezultat = max(temp1, temp2); } memo[n][imp] = rezultat; return rezultat; } int main() { // ifstream fin("date.in"); vector<int> a, b, c; int n, **memo, valoare; cin >> n; memo = new int *[n](); for (int i = 0; i < n; i++) { memo[i] = new int[4](); cin >> valoare; a.push_back(valoare); cin >> valoare; b.push_back(valoare); cin >> valoare; c.push_back(valoare); } rezolvare(n - 1, a, b, c, 0, memo); cout << memo[n - 1][0]; return 0; }
#include <fstream> #include <iostream> #include <vector> using namespace std; int rezolvare(int n, vector<int> &a, vector<int> &b, vector<int> &c, int imp, int **&memo) { int rezultat = 0; if (n == -1) return 0; if (memo[n][imp] != 0) return memo[n][imp]; if (imp == 0) { int temp1, temp2, temp3; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp1, max(temp2, temp3)); } else if (imp == 1) { int temp2, temp3; temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp2, temp3); } else if (imp == 2) { int temp1, temp3; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp3 = c[n] + rezolvare(n - 1, a, b, c, 3, memo); rezultat = max(temp1, temp3); } else if (imp == 3) { int temp1, temp2; temp1 = a[n] + rezolvare(n - 1, a, b, c, 1, memo); temp2 = b[n] + rezolvare(n - 1, a, b, c, 2, memo); rezultat = max(temp1, temp2); } memo[n][imp] = rezultat; return rezultat; } int main() { // ifstream fin("date.in"); vector<int> a, b, c; int n, **memo, valoare; cin >> n; memo = new int *[n](); for (int i = 0; i < n; i++) { memo[i] = new int[4](); cin >> valoare; a.push_back(valoare); cin >> valoare; b.push_back(valoare); cin >> valoare; c.push_back(valoare); } rezolvare(n - 1, a, b, c, 0, memo); cout << memo[n - 1][0]; return 0; }
replace
4
5
4
5
TLE
p03162
C++
Runtime Error
/* Competitive programming template Author: Aswin Sampath */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<int> vi; typedef priority_queue<ll, vl, greater<ll>()> pq_ll_min; typedef priority_queue<ll> pq_ll_max; typedef stack<ll> s; typedef queue<ll> q; #define pi 3.141592653589793 #define PI acos(-1.0) #define space " " #define endl '\n' #define F first #define S second #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define FAST \ { \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ } #define testcase \ ll t; \ cin >> t; \ while (t--) #define dbxstl(x) \ { \ for (auto ele : x) \ cout << ele << space; \ cout << endl; \ } #define dbxval(x) \ { cout << x << endl; } const ll INF = 1e18 + 7; const ll MOD = 1e9 + 7; void solve() { printf("Hello\n"); } int main(int argc, char const *argv[]) { ll n; cin >> n; vector<ll> dp(3, 0); for (int days = 0; days < n; days++) { vector<ll> temp(3, 0); vector<ll> params(3); for (int i = 0; i < 3; i++) { cin >> params[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { if (i != j) { temp[j] = max(temp[j], dp[i] + params[j]); } } } dp = temp; } ll ans = max({dp[0], dp[1], dp[2]}); cout << ans << endl; return 0; }
/* Competitive programming template Author: Aswin Sampath */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<int> vi; typedef priority_queue<ll, vl, greater<ll>()> pq_ll_min; typedef priority_queue<ll> pq_ll_max; typedef stack<ll> s; typedef queue<ll> q; #define pi 3.141592653589793 #define PI acos(-1.0) #define space " " #define endl '\n' #define F first #define S second #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define FAST \ { \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ } #define testcase \ ll t; \ cin >> t; \ while (t--) #define dbxstl(x) \ { \ for (auto ele : x) \ cout << ele << space; \ cout << endl; \ } #define dbxval(x) \ { cout << x << endl; } const ll INF = 1e18 + 7; const ll MOD = 1e9 + 7; void solve() { printf("Hello\n"); } int main(int argc, char const *argv[]) { ll n; cin >> n; vector<ll> dp(3, 0); for (int days = 0; days < n; days++) { vector<ll> temp(3, 0); vector<ll> params(3); for (int i = 0; i < 3; i++) { cin >> params[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { temp[j] = max(temp[j], dp[i] + params[j]); } } } dp = temp; } ll ans = max({dp[0], dp[1], dp[2]}); cout << ans << endl; return 0; }
replace
65
66
65
66
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf (int)(1e18) #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define rep(i, j, n) for (int i = j; i < n; i++) #define all(p) p.begin(), p.end() #define ub(a, b) upper_bound(all(a), b) #define lb(a, b) lower_bound(all(a), b) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void run() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { run(); int n; cin >> n; vector<vector<int>> a(n, vector<int>(3, 0)); rep(i, 0, n) { rep(j, 0, 3) cin >> a[i][j]; } vector<vector<int>> dp(n, vector<int>(3, 0)); rep(i, 0, 3) dp[0][i] = a[0][i]; for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (k == j) { continue; } dp[i][j] = max(a[i][j] + dp[i - 1][k], dp[i][j]); } } } int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf (int)(1e18) #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define rep(i, j, n) for (int i = j; i < n; i++) #define all(p) p.begin(), p.end() #define ub(a, b) upper_bound(all(a), b) #define lb(a, b) lower_bound(all(a), b) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void run() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { run(); int n; cin >> n; vector<vector<int>> a(n, vector<int>(3, 0)); rep(i, 0, n) { rep(j, 0, 3) cin >> a[i][j]; } vector<vector<int>> dp(n, vector<int>(3, 0)); rep(i, 0, 3) dp[0][i] = a[0][i]; for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (k == j) { continue; } dp[i][j] = max(a[i][j] + dp[i - 1][k], dp[i][j]); } } } int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); cout << ans << endl; return 0; }
delete
34
38
34
34
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) typedef long long ll; #define MOD 1000000007 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; int main() { ll n, a[10000000][3]; cin >> n; FOR(i, n) { FOR(j, 3) { cin >> a[i][j]; } } ll dp[10000000][3] = {0}; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) { continue; } chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; for (int i = 0; i < 3; i++) { chmax(ans, dp[n][i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) typedef long long ll; #define MOD 1000000007 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; int main() { ll n, a[10000000][3]; cin >> n; FOR(i, n) { FOR(j, 3) { cin >> a[i][j]; } } ll dp[1000000][3] = {0}; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) { continue; } chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; for (int i = 0; i < 3; i++) { chmax(ans, dp[n][i]); } cout << ans << endl; }
replace
29
30
29
30
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define Fast_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int32_t main() { Fast_IO #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; int in[3]; int ou[3]; vector<int> dp(3, 0); for (int ii = 0; ii < n; ii++) { vector<int> dpo(3, 0); for (int j = 0; j < 3; j++) { cin >> in[j]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { dpo[j] = max(dpo[j], dp[i] + in[j]); } } } dp = dpo; } cout << max({dp[0], dp[1], dp[2]}); }
#include <bits/stdc++.h> using namespace std; #define Fast_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int32_t main() { Fast_IO #ifdef __WIN32 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; int in[3]; int ou[3]; vector<int> dp(3, 0); for (int ii = 0; ii < n; ii++) { vector<int> dpo(3, 0); for (int j = 0; j < 3; j++) { cin >> in[j]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { dpo[j] = max(dpo[j], dp[i] + in[j]); } } } dp = dpo; } cout << max({dp[0], dp[1], dp[2]}); }
replace
9
10
9
10
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int MOD = 1000000007; const long long INF = 1LL << 60; 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; } ll abc[10010][3]{}; ll dp[10010][3]{}; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> abc[i][j]; for (int a = 0; a < N; ++a) { for (int b = 0; b < 3; ++b) { for (int c = 0; c < 3; ++c) { if (b == c) continue; chmax(dp[a + 1][c], dp[a][b] + abc[a][c]); } } } ll res = 0; for (int i = 0; i < 3; ++i) chmax(res, dp[N][i]); cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int MOD = 1000000007; const long long INF = 1LL << 60; 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; } ll abc[100100][3]{}; ll dp[100100][3]{}; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> abc[i][j]; for (int a = 0; a < N; ++a) { for (int b = 0; b < 3; ++b) { for (int c = 0; c < 3; ++c) { if (b == c) continue; chmax(dp[a + 1][c], dp[a][b] + abc[a][c]); } } } ll res = 0; for (int i = 0; i < 3; ++i) chmax(res, dp[N][i]); cout << res << endl; return 0; }
replace
25
27
25
27
0
p03162
C++
Runtime Error
// [amitdu6ey] // g++ -std=c++11 -o2 -Wall filename.cpp -o filename #include <bits/stdc++.h> #define hell 1000000009 #define bug1(x) cout << "$ " << x << " $" << endl #define bug2(x) cout << "% " << x << " %" << endl #define bug3(x) cout << "# " << x << " #" << endl #define ll long long #define pb push_back #define mp make_pair #define tr(z) for (auto it = z.begin(); it != z.end(); it++) #define rloop(i, a, b) for (long long i = a; i >= b; i--) #define loop(i, a, b) for (long long i = a; i < b; i++) #define vbool vector<bool> #define vvbool vector<vector<bool>> #define vchar vector<char> #define vi vector<int> #define vvi vector<vector<int>> #define pll pair<long long, long long> #define vll vector<long long> #define vvl vector<vector<long long>> #define ninf numeric_limits<long long>::min() #define pinf numeric_limits<long long>::max() #define comp(a, b) (abs(a - b) < 1e-9) // to compare doubles using namespace std; ll a[10009][3]; ll dp[10009][3]; ll n; ll f(ll x, ll l) { if (dp[l][x] != 0) return dp[l][x]; else if (l >= n) return 0; else if (x == 0) return dp[l][x] = a[l][x] + max(f(1, l + 1), f(2, l + 1)); else if (x == 1) return dp[l][x] = a[l][x] + max(f(0, l + 1), f(2, l + 1)); else if (x == 2) return dp[l][x] = a[l][x] + max(f(0, l + 1), f(1, l + 1)); } void solve() { cin >> n; loop(i, 0, n) { loop(j, 0, 3) { cin >> a[i][j]; } } loop(i, 0, 10009) { loop(j, 0, 3) { dp[i][j] = 0; } } cout << max({f(0, 0), f(1, 0), f(2, 0)}) << "\n"; return; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int test_cases = 1; // cin>>test_cases; while (test_cases--) { solve(); } return 0; }
// [amitdu6ey] // g++ -std=c++11 -o2 -Wall filename.cpp -o filename #include <bits/stdc++.h> #define hell 1000000009 #define bug1(x) cout << "$ " << x << " $" << endl #define bug2(x) cout << "% " << x << " %" << endl #define bug3(x) cout << "# " << x << " #" << endl #define ll long long #define pb push_back #define mp make_pair #define tr(z) for (auto it = z.begin(); it != z.end(); it++) #define rloop(i, a, b) for (long long i = a; i >= b; i--) #define loop(i, a, b) for (long long i = a; i < b; i++) #define vbool vector<bool> #define vvbool vector<vector<bool>> #define vchar vector<char> #define vi vector<int> #define vvi vector<vector<int>> #define pll pair<long long, long long> #define vll vector<long long> #define vvl vector<vector<long long>> #define ninf numeric_limits<long long>::min() #define pinf numeric_limits<long long>::max() #define comp(a, b) (abs(a - b) < 1e-9) // to compare doubles using namespace std; ll a[100009][3]; ll dp[100009][3]; ll n; ll f(ll x, ll l) { if (dp[l][x] != 0) return dp[l][x]; else if (l >= n) return 0; else if (x == 0) return dp[l][x] = a[l][x] + max(f(1, l + 1), f(2, l + 1)); else if (x == 1) return dp[l][x] = a[l][x] + max(f(0, l + 1), f(2, l + 1)); else if (x == 2) return dp[l][x] = a[l][x] + max(f(0, l + 1), f(1, l + 1)); } void solve() { cin >> n; loop(i, 0, n) { loop(j, 0, 3) { cin >> a[i][j]; } } loop(i, 0, 10009) { loop(j, 0, 3) { dp[i][j] = 0; } } cout << max({f(0, 0), f(1, 0), f(2, 0)}) << "\n"; return; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int test_cases = 1; // cin>>test_cases; while (test_cases--) { solve(); } return 0; }
replace
26
28
26
28
0
p03162
Python
Runtime Error
# dp[iๆ—ฅ็›ฎ][i-1ๆ—ฅ็›ฎใซใฉใ‚Œใ‚’้ธใ‚“ใ ใ‹] = iๆ—ฅ็›ฎใพใงใฎๆœ€ๅคงใฎๅนธ็ฆๅบฆ n = int(input()) a, b, c = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)] for i in range(n): a[i], b[i], c[i] = map(int, input().split()) dp = [[-1 for _ in range(3)] for _ in range(n + 1)] for i in range(3): dp[0][i] = 0 def rec(i, choice): if dp[i][choice] > 0: return dp[i][choice] if i == n: return 0 ret = 0 # ใƒซใƒผใƒ—ใ˜ใ‚ƒใชใใฆifใงใ‚„ใฃใฆใ‚‹ใฎใงใใ‚Œใžใ‚Œ็ขบๅฎŸใซๅคงใใ„ๅ€คใŒๅ…ฅใ‚‹๏ผˆใฎใงๆ›ดๆ–ฐใ™ใ‚‹ๅฟ…่ฆใŒใชใ„๏ผ‰ if choice == 0: ret = a[i] + max(rec(i + 1, 1), rec(i + 1, 2)) elif choice == 1: ret = b[i] + max(rec(i + 1, 0), rec(i + 1, 2)) elif choice == 2: ret = c[i] + max(rec(i + 1, 0), rec(i + 1, 1)) dp[i][choice] = ret return ret print(max(rec(0, 0), rec(0, 1), rec(0, 2)))
# dp[iๆ—ฅ็›ฎ][i-1ๆ—ฅ็›ฎใซใฉใ‚Œใ‚’้ธใ‚“ใ ใ‹] = iๆ—ฅ็›ฎใพใงใฎๆœ€ๅคงใฎๅนธ็ฆๅบฆ import sys sys.setrecursionlimit(10**8) n = int(input()) a, b, c = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)] for i in range(n): a[i], b[i], c[i] = map(int, input().split()) dp = [[-1 for _ in range(3)] for _ in range(n + 1)] for i in range(3): dp[0][i] = 0 def rec(i, choice): if dp[i][choice] > 0: return dp[i][choice] if i == n: return 0 ret = 0 # ใƒซใƒผใƒ—ใ˜ใ‚ƒใชใใฆifใงใ‚„ใฃใฆใ‚‹ใฎใงใใ‚Œใžใ‚Œ็ขบๅฎŸใซๅคงใใ„ๅ€คใŒๅ…ฅใ‚‹๏ผˆใฎใงๆ›ดๆ–ฐใ™ใ‚‹ๅฟ…่ฆใŒใชใ„๏ผ‰ if choice == 0: ret = a[i] + max(rec(i + 1, 1), rec(i + 1, 2)) elif choice == 1: ret = b[i] + max(rec(i + 1, 0), rec(i + 1, 2)) elif choice == 2: ret = c[i] + max(rec(i + 1, 0), rec(i + 1, 1)) dp[i][choice] = ret return ret print(max(rec(0, 0), rec(0, 1), rec(0, 2)))
insert
1
1
1
5
0
p03162
C++
Runtime Error
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N; long long a[10010][3]; long long dp[10010][3]; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j]; for (int i = 0; i < N; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } long long res = 0; for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]); cout << res << endl; return 0; }
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N; long long a[100010][3]; long long dp[100010][3]; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j]; for (int i = 0; i < N; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } long long res = 0; for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]); cout << res << endl; return 0; }
replace
21
23
21
23
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define fo(i, n) for (int i = 0; i < n; i++) #define rfo(i, n) for (int i = n - 1; i >= 0; i--) #define Fo(i, q, n) for (int i = q; i < n; i++) #define rFo(i, q, n) for (int i = n - 1; i >= q; i--) #define fO(i, n, k) for (int i = 0; i < n; i += k) #define FO(i, q, n, k) for (int i = q; i < n; i += k) #define zero(a, n) memset(a, 0, sizeof(a[0]) * n) #define pb push_back #define mp make_pair #define F first #define S second #define endl "\n" #define Endl "\n" #define trace(x) cerr << #x << ": " << x << " " << endl; using namespace std; const int MOD = 1000000007; void print() { cout << endl; } template <typename T, typename... Types> void print(T var1, Types... var2) { cout << var1 << " "; print(var2...); } // ceil of a/b template <typename T> T fceil(T a, T b) { return (T)(a + b - 1) / b; } // const int N=2e5; // int arr[N+1]; int main() { int n; cin >> n; vector<int> a(n, 0); vector<int> b(n, 0); vector<int> c(n, 0); fo(i, n) { cin >> a[i] >> b[i] >> c[i]; } if (n == 1) { cout << max({a[0], b[0], c[0]}) << endl; return 0; } vector<vector<int>> dp(n, vector<int>(n, 0)); dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; fo(i, n) { if (i == 0) { continue; } dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i]; } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; return 0; } /*NOTE: Take MOD after sorting and not before sorting!*/
#include <bits/stdc++.h> #define ll long long #define fo(i, n) for (int i = 0; i < n; i++) #define rfo(i, n) for (int i = n - 1; i >= 0; i--) #define Fo(i, q, n) for (int i = q; i < n; i++) #define rFo(i, q, n) for (int i = n - 1; i >= q; i--) #define fO(i, n, k) for (int i = 0; i < n; i += k) #define FO(i, q, n, k) for (int i = q; i < n; i += k) #define zero(a, n) memset(a, 0, sizeof(a[0]) * n) #define pb push_back #define mp make_pair #define F first #define S second #define endl "\n" #define Endl "\n" #define trace(x) cerr << #x << ": " << x << " " << endl; using namespace std; const int MOD = 1000000007; void print() { cout << endl; } template <typename T, typename... Types> void print(T var1, Types... var2) { cout << var1 << " "; print(var2...); } // ceil of a/b template <typename T> T fceil(T a, T b) { return (T)(a + b - 1) / b; } // const int N=2e5; // int arr[N+1]; int main() { int n; cin >> n; vector<int> a(n, 0); vector<int> b(n, 0); vector<int> c(n, 0); fo(i, n) { cin >> a[i] >> b[i] >> c[i]; } vector<vector<int>> dp(n, vector<int>(3, 0)); dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; fo(i, n) { if (i == 0) { continue; } dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i]; } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; return 0; } /*NOTE: Take MOD after sorting and not before sorting!*/
replace
35
40
35
37
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int #define all(x) x.begin(), x.end() #define MOD 1000000007 #define vi vector<int> #define pii pair<int, int> #define INF (int)1e9 #define pb push_back #define fastIO \ ios::sync_with_stdio(0); \ cin.tie(0); vector<vi> arr; int n; int cache[100010][3]; int dpSol(int i, int ch) { if (i == n) return 0; int &res = cache[i][ch]; if (ch == 0) return res = max(arr[i][1] + dpSol(i + 1, 1), arr[i][2] + dpSol(i + 1, 2)); if (ch == 1) return res = max(arr[i][0] + dpSol(i + 1, 0), arr[i][2] + dpSol(i + 1, 2)); return res = max(arr[i][0] + dpSol(i + 1, 0), arr[i][1] + dpSol(i + 1, 1)); } int main() { fastIO cin >> n; memset(cache, -1, sizeof(cache)); arr = vector<vi>(n, vi(3)); for (int i = 0; i < n; ++i) cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; cout << max({dpSol(0, 0), dpSol(0, 1), dpSol(0, 2)}); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define all(x) x.begin(), x.end() #define MOD 1000000007 #define vi vector<int> #define pii pair<int, int> #define INF (int)1e9 #define pb push_back #define fastIO \ ios::sync_with_stdio(0); \ cin.tie(0); vector<vi> arr; int n; int cache[100010][3]; int dpSol(int i, int ch) { if (i == n) return 0; int &res = cache[i][ch]; if (res != -1) return res; if (ch == 0) return res = max(arr[i][1] + dpSol(i + 1, 1), arr[i][2] + dpSol(i + 1, 2)); if (ch == 1) return res = max(arr[i][0] + dpSol(i + 1, 0), arr[i][2] + dpSol(i + 1, 2)); return res = max(arr[i][0] + dpSol(i + 1, 0), arr[i][1] + dpSol(i + 1, 1)); } int main() { fastIO cin >> n; memset(cache, -1, sizeof(cache)); arr = vector<vi>(n, vi(3)); for (int i = 0; i < n; ++i) cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; cout << max({dpSol(0, 0), dpSol(0, 1), dpSol(0, 2)}); return 0; }
insert
22
22
22
24
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<vector<ll>> a(n, vector<ll>(n)); for (int i = 0; i < n; i++) { cin >> a[i][0]; cin >> a[i][1]; cin >> a[i][2]; } ll dp[100010][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, dp[n][i]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; ll a[100010][3] = {}; ll dp[100010][3] = {}; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, dp[n][i]); cout << ans << endl; return 0; }
replace
7
14
7
12
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int dp[n][n]; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; if (i == 0) { dp[i][0] = a; dp[i][1] = b; dp[i][2] = c; } else { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c; } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int dp[112345][3]; // int dp[n][n]; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; if (i == 0) { dp[i][0] = a; dp[i][1] = b; dp[i][2] = c; } else { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c; } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; }
replace
5
6
5
7
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define loop(a, b, inc) for (int i = a; i <= b; i += inc) typedef pair<int, int> pii; typedef pair<int, string> ps; typedef unsigned long long int llu; typedef long long int ll; typedef unsigned u; const int MOD = 1e7 + 9, MAXN = 1e5 + 100; int dp[MAXN][5], tab[MAXN][5]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; loop(1, n, 1) { for (int j = 1; j <= 3; ++j) cin >> tab[i][j]; } for (int j = 1; j <= n; ++j) { dp[n][j] = tab[n][j]; } for (int i = n - 1; i >= 0; --i) { for (int j = 1; j <= 3; ++j) { for (int k = 1; k <= 3; ++k) { if (k != j) dp[i][j] = max(dp[i][j], dp[i + 1][k] + tab[i][j]); } } // cout << dp[i][1] <<" "<< dp[i][2] << " " << dp[i][3] << endl; } cout << max(max(dp[0][1], dp[0][2]), dp[0][3]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define loop(a, b, inc) for (int i = a; i <= b; i += inc) typedef pair<int, int> pii; typedef pair<int, string> ps; typedef unsigned long long int llu; typedef long long int ll; typedef unsigned u; const int MOD = 1e7 + 9, MAXN = 1e6 + 100; int dp[MAXN][5], tab[MAXN][5]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; loop(1, n, 1) { for (int j = 1; j <= 3; ++j) cin >> tab[i][j]; } for (int j = 1; j <= n; ++j) { dp[n][j] = tab[n][j]; } for (int i = n - 1; i >= 0; --i) { for (int j = 1; j <= 3; ++j) { for (int k = 1; k <= 3; ++k) { if (k != j) dp[i][j] = max(dp[i][j], dp[i + 1][k] + tab[i][j]); } } // cout << dp[i][1] <<" "<< dp[i][2] << " " << dp[i][3] << endl; } cout << max(max(dp[0][1], dp[0][2]), dp[0][3]) << endl; return 0; }
replace
9
10
9
10
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> using namespace std; const int Nmax = 1e5 + 5; int N, S, Max, p; int a[Nmax][3], dp[Nmax][3]; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) { scanf("%d%d%d", a[i][0], a[i][1], a[i][2]); for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) if (j != k) dp[i][j] = max(dp[i - 1][k], dp[i][j]); dp[i][j] += a[i][j]; } } printf("%d", max({dp[N][0], dp[N][1], dp[N][2]})); /// cout << dp[N][0] << " " << dp[N][1] << " " << dp[N][2]; return 0; }
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> using namespace std; const int Nmax = 1e5 + 5; int N, S, Max, p; int a[Nmax][3], dp[Nmax][3]; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) { scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]); for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) if (j != k) dp[i][j] = max(dp[i - 1][k], dp[i][j]); dp[i][j] += a[i][j]; } } printf("%d", max({dp[N][0], dp[N][1], dp[N][2]})); /// cout << dp[N][0] << " " << dp[N][1] << " " << dp[N][2]; return 0; }
replace
13
14
13
14
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define PI acos(-1) #define mx 1000 int fx[] = {0, 0, -1, 1}; int fy[] = {1, -1, 0, 0}; int a[mx], b[mx], c[mx]; int dp[mx][3]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, i, j, res = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (i = 1; i <= n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } res = max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]); cout << res << endl; return 0; } /* 3 10 40 70 20 50 80 30 60 90 */
#include <bits/stdc++.h> using namespace std; #define ll long long #define PI acos(-1) #define mx 100005 int fx[] = {0, 0, -1, 1}; int fy[] = {1, -1, 0, 0}; int a[mx], b[mx], c[mx]; int dp[mx][3]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, i, j, res = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (i = 1; i <= n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i]; } res = max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]); cout << res << endl; return 0; } /* 3 10 40 70 20 50 80 30 60 90 */
replace
4
5
4
5
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> dp(3, 0); for (int day = 0; day < n; day++) { vector<int> c(3, 0); vector<int> new_dp(3, 0); for (int i = 0; i < 3; i++) { cin >> c[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + c[j]); } } } dp = new_dp; } cout << max(dp[0], max(dp[1], dp[2])) << endl; return 0; };
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> dp(3, 0); for (int day = 0; day < n; day++) { vector<int> c(3, 0); vector<int> new_dp(3, 0); for (int i = 0; i < 3; i++) { cin >> c[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + c[j]); } } } dp = new_dp; } cout << max(dp[0], max(dp[1], dp[2])) << endl; return 0; };
replace
15
16
15
16
0
p03162
C++
Runtime Error
// Utkarsh-raj #include <bits/stdc++.h> #define ll long long int #define vc vector #define mod 100000000007 #define mp make_pair #define pb push_back #define nl cout << endl; #define ff first #define ss second using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ifstream myFile("task.in"); if (!myFile.fail()) { assert(freopen("task.in", "r", stdin)); } int n; cin >> n; ll arr[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } } for (int i = 1; i < n; i++) { arr[i][0] += max(arr[i - 1][1], arr[i - 1][2]); arr[i][1] += max(arr[i - 1][0], arr[i - 1][2]); arr[i][2] += max(arr[i - 1][0], arr[i - 1][1]); } cout << max(arr[n - 1][0], max(arr[n - 1][1], arr[n - 1][2])) << endl; return 0; }
// Utkarsh-raj #include <bits/stdc++.h> #define ll long long int #define vc vector #define mod 100000000007 #define mp make_pair #define pb push_back #define nl cout << endl; #define ff first #define ss second using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ifstream myFile("task.in"); if (!myFile.fail()) { assert(freopen("task.in", "r", stdin)); } int n; cin >> n; ll arr[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } } for (int i = 1; i < n; i++) { arr[i][0] += max(arr[i - 1][1], arr[i - 1][2]); arr[i][1] += max(arr[i - 1][0], arr[i - 1][2]); arr[i][2] += max(arr[i - 1][0], arr[i - 1][1]); } cout << max(arr[n - 1][0], max(arr[n - 1][1], arr[n - 1][2])) << endl; return 0; }
replace
27
28
27
28
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) FOR(i, 0, b) #define INF mugen #define dump(x) cerr << #x << "=" << x << endl #define all(a) (a).begin(), (a).end() typedef vector<int> vi; typedef vector<vi> vii; typedef vector<vii> viii; typedef pair<int, int> P; template <class T> void chmin(T &a, T const &b) { if (b < a) a = b; } template <typename T> string to_string(const T &n) { ostringstream stm; stm << n; return stm.str(); } inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } using ll = long long; const ll mod = LLONG_MAX; ll N, ans; ll dp[11234][2][2][2]; // i็•ช็›ฎใฎๆ—ฅใฎๆœ€ๅคงใฎๅนธ็ฆ i-1ๆ—ฅ็›ฎใซไฝฟใฃใŸใ‹ใฉใ†ใ‹ ll a[112345], b[112345], c[112345]; signed main() { cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, N) { dp[i + 1][1][0][0] = max(dp[i][0][1][0] + a[i], dp[i][0][0][1] + a[i]); dp[i + 1][0][1][0] = max(dp[i][1][0][0] + b[i], dp[i][0][0][1] + b[i]); dp[i + 1][0][0][1] = max(dp[i][1][0][0] + c[i], dp[i][0][1][0] + c[i]); } ans = max({dp[N][0][0][1], dp[N][0][1][0], dp[N][1][0][0]}); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) FOR(i, 0, b) #define INF mugen #define dump(x) cerr << #x << "=" << x << endl #define all(a) (a).begin(), (a).end() typedef vector<int> vi; typedef vector<vi> vii; typedef vector<vii> viii; typedef pair<int, int> P; template <class T> void chmin(T &a, T const &b) { if (b < a) a = b; } template <typename T> string to_string(const T &n) { ostringstream stm; stm << n; return stm.str(); } inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } using ll = long long; const ll mod = LLONG_MAX; ll N, ans; ll dp[112345][2][2][2]; // i็•ช็›ฎใฎๆ—ฅใฎๆœ€ๅคงใฎๅนธ็ฆ i-1ๆ—ฅ็›ฎใซไฝฟใฃใŸใ‹ใฉใ†ใ‹ ll a[112345], b[112345], c[112345]; signed main() { cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, N) { dp[i + 1][1][0][0] = max(dp[i][0][1][0] + a[i], dp[i][0][0][1] + a[i]); dp[i + 1][0][1][0] = max(dp[i][1][0][0] + b[i], dp[i][0][0][1] + b[i]); dp[i + 1][0][0][1] = max(dp[i][1][0][0] + c[i], dp[i][0][1][0] + c[i]); } ans = max({dp[N][0][0][1], dp[N][0][1][0], dp[N][1][0][0]}); cout << ans << endl; }
replace
30
31
30
31
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long cache[10005][3]; long long vacate(vector<long long> *v, int n, int i, int activity) { if (i >= n) { return 0; } if (activity != -1 && cache[i][activity] != -1) { return cache[i][activity]; } long long points = 0; for (int m = 0; m < 3; m++) { if (activity != m) { points = max(points, v[i][m] + vacate(v, n, i + 1, m)); } } cache[i][activity] = points; return points; } int main() { int n; cin >> n; vector<long long> v[n]; int a, b, c; for (int i = 0; i < n; i++) { cin >> a >> b >> c; v[i].push_back(a); v[i].push_back(b); v[i].push_back(c); } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cache[i][j] = -1; } } long long points = vacate(v, n, 0, -1); cout << points << endl; }
#include <bits/stdc++.h> using namespace std; long long cache[100005][3]; long long vacate(vector<long long> *v, int n, int i, int activity) { if (i >= n) { return 0; } if (activity != -1 && cache[i][activity] != -1) { return cache[i][activity]; } long long points = 0; for (int m = 0; m < 3; m++) { if (activity != m) { points = max(points, v[i][m] + vacate(v, n, i + 1, m)); } } cache[i][activity] = points; return points; } int main() { int n; cin >> n; vector<long long> v[n]; int a, b, c; for (int i = 0; i < n; i++) { cin >> a >> b >> c; v[i].push_back(a); v[i].push_back(b); v[i].push_back(c); } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cache[i][j] = -1; } } long long points = vacate(v, n, 0, -1); cout << points << endl; }
replace
3
4
3
4
0
p03162
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <stack> #include <string> #include <type_traits> using namespace std; using ll = long long; typedef pair<int, int> P; #define rep(i, N) for (long long i = 0; i < (long long)N; ++i) static int mod = 1000000007; static int large = 1000000000; int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int N; int a[100001]; int b[100001]; int c[100001]; int dp[100001][3]; inline int change(int x, int i) { if (x == 0) return a[i - 1]; else if (x == 1) return b[i - 1]; else if (x == 2) return c[i - 1]; return -1; } // iๆ—ฅ็›ฎ,jใง้Šใถ int f(int i, int j) { if (dp[i][j] != -1) dp[i][j]; if (i == 0) return dp[0][j] = 0; int sec = 0; rep(k, 3) { if (k != j) { sec = max(sec, f(i - 1, k) + change(j, i)); } } return dp[i][j] = sec; } int main() { cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, 100001) { rep(j, 3) { dp[i][j] = -1; } } cout << max(f(N, 0), max(f(N, 1), f(N, 2))) << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <stack> #include <string> #include <type_traits> using namespace std; using ll = long long; typedef pair<int, int> P; #define rep(i, N) for (long long i = 0; i < (long long)N; ++i) static int mod = 1000000007; static int large = 1000000000; int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int N; int a[100001]; int b[100001]; int c[100001]; int dp[100001][3]; inline int change(int x, int i) { if (x == 0) return a[i - 1]; else if (x == 1) return b[i - 1]; else if (x == 2) return c[i - 1]; return -1; } // iๆ—ฅ็›ฎ,jใง้Šใถ int f(int i, int j) { if (dp[i][j] != -1) return dp[i][j]; if (i == 0) return dp[0][j] = 0; int sec = 0; rep(k, 3) { if (k != j) { sec = max(sec, f(i - 1, k) + change(j, i)); } } return dp[i][j] = sec; } int main() { cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, 100001) { rep(j, 3) { dp[i][j] = -1; } } cout << max(f(N, 0), max(f(N, 1), f(N, 2))) << endl; return 0; }
replace
49
50
49
50
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; int a[100005][4]; int dp[100005][4]; // int mx=INT_MIN; int solve(int i, int f) { if (i == n) return 0; if (dp[i][f] != -1) return dp[i][f]; int mx = INT_MIN; if (f == 0) { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][2] + solve(i + 1, 2)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else if (f == 1) { mx = max(mx, a[i][2] + solve(i + 1, 2)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else if (f == 2) { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][2] + solve(i + 1, 2)); } return dp[n][f] = mx; } int main() { // int n; cin >> n; // int a[n][3]; for (int i = 0; i < n; i++) for (int j = 1; j <= 3; j++) cin >> a[i][j]; memset(dp, -1, sizeof(dp)); cout << solve(0, 0); }
#include <bits/stdc++.h> using namespace std; int n; int a[100005][4]; int dp[100005][4]; // int mx=INT_MIN; int solve(int i, int f) { if (i == n) return 0; if (dp[i][f] != -1) return dp[i][f]; int mx = INT_MIN; if (f == 0) { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][2] + solve(i + 1, 2)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else if (f == 1) { mx = max(mx, a[i][2] + solve(i + 1, 2)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else if (f == 2) { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][3] + solve(i + 1, 3)); } else { mx = max(mx, a[i][1] + solve(i + 1, 1)); mx = max(mx, a[i][2] + solve(i + 1, 2)); } return dp[i][f] = mx; } int main() { // int n; cin >> n; // int a[n][3]; for (int i = 0; i < n; i++) for (int j = 1; j <= 3; j++) cin >> a[i][j]; memset(dp, -1, sizeof(dp)); cout << solve(0, 0); }
replace
26
27
26
27
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define f first #define s second #define pb push_back #define all(v) (v).begin(), (v).end() #define debug(x) cout << #x << " " << x << "\n" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll N = 1e5 + 3; ll n, k, a[N][4], res[N][4]; ll _max(ll x, ll y, ll z) { return max(max(x, y), z); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; ++i) { for (ll j = 1; j <= 3; ++j) cin >> a[i][j]; } for (ll i = 1; i <= n; ++i) { for (ll j = 1; j <= n; ++j) { for (ll k = 1; k <= 3; ++k) { if (k == j) continue; res[i][j] = max(res[i][j], res[i - 1][k] + a[i][j]); } } } cout << _max(res[n][1], res[n][2], res[n][3]); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define f first #define s second #define pb push_back #define all(v) (v).begin(), (v).end() #define debug(x) cout << #x << " " << x << "\n" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll N = 1e5 + 3; ll n, k, a[N][4], res[N][4]; ll _max(ll x, ll y, ll z) { return max(max(x, y), z); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; ++i) { for (ll j = 1; j <= 3; ++j) cin >> a[i][j]; } for (ll i = 1; i <= n; ++i) { for (ll j = 1; j <= 3; ++j) { for (ll k = 1; k <= 3; ++k) { if (k == j) continue; res[i][j] = max(res[i][j], res[i - 1][k] + a[i][j]); } } } cout << _max(res[n][1], res[n][2], res[n][3]); return 0; }
replace
34
35
34
35
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vp vector<pii> #define vs vector<string> #define all(v) v.begin(), v.end() #define lb lower_bound #define ub upper_bound #define bs binary_search #define ff first #define ss second #define sz(x) ((int)(x).size()) #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define pi 3.14159265358979323846 // 20 decimals #define MOD 1000000007 int32_t main() { IOS #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vi dp(3, 0); vi new_dp(3, 0); vi happy(3, 0); for (int vac = 0; vac < n; vac++) { for (int i = 0; i < 3; i++) cin >> happy[i]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + happy[j]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vp vector<pii> #define vs vector<string> #define all(v) v.begin(), v.end() #define lb lower_bound #define ub upper_bound #define bs binary_search #define ff first #define ss second #define sz(x) ((int)(x).size()) #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define pi 3.14159265358979323846 // 20 decimals #define MOD 1000000007 int32_t main() { IOS int n; cin >> n; vi dp(3, 0); vi new_dp(3, 0); vi happy(3, 0); for (int vac = 0; vac < n; vac++) { for (int i = 0; i < 3; i++) cin >> happy[i]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + happy[j]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}); return 0; }
replace
34
39
34
36
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int val[N][3]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> val[i][j]; } } long long int dp[N][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -100000; } } for (int i = 0; i < 3; i++) { dp[0][i] = val[0][i]; } for (int i = 1; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = max(dp[i - 1][(j + 1) % 3] + val[i][j], dp[i - 1][(j + 2) % 3] + val[i][j]); } } cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int val[N][3]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> val[i][j]; } } long long int dp[N][3]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -100000; } } for (int i = 0; i < 3; i++) { dp[0][i] = val[0][i]; } for (int i = 1; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = max(dp[i - 1][(j + 1) % 3] + val[i][j], dp[i - 1][(j + 2) % 3] + val[i][j]); } } cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl; return 0; }
replace
12
13
12
13
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define M 1000000007 #define mp make_pair #define pb push_back #define PB pop_back #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define lcase(a) (char)tolower(a) #define ucase(a) (char)toupper(a) #define precise(a) fixed << setprecision(a) << #define F first #define S second #define I insert #define pii pair<int, int> #define trav(a, x) for (auto &a : x) #define fl(i, n) for (int i = 0; i < n; i++) #define rfl(n) for (int i = n - 1; i >= 0; i--) #define time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.I(tmp); \ commands \ } #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl; #define ingrid(data, n, commands) \ for (int i = 0; i < n; i++) { \ cin >> data[i]; \ commands \ } #define section(a, b, w) \ set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define union(a, b, w) \ set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define copy(a, w) copy(a.begin(), a.end(), back_inserter(w)); #define all(data) data.begin(), data.end() #define PI 3.14159265358979323844 #define endl '\n' #define last(a) a[sz(a) - 1] #define mp make_pair #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // Graph DFS const int fx[] = {+1, -1, +0, +0}; const int fy[] = {+0, +0, +1, -1}; // primes for hashing 937,991,1013,1409,1741 // Returns index of first element not less than key and more than key // respectively #define lb(data, key) lower_bound(all(data), key) - data.begin(); #define up(data, key) upper_bound(all(data), key) - data.begin(); #define fnd(data, key) find(all(data), key) - data.begin(); // Long Long Int #define int long long int void solve() { int n; cin >> n; std::vector<std::vector<int>> v(n, std::vector<int>(n, 0)); fl(i, n) { fl(j, 3) { cin >> v[i][j]; } } int dp[n][3]; fl(i, 3) { dp[0][i] = v[0][i]; } for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + v[i][2]; } cout << max(max(dp[n - 1][1], dp[n - 1][0]), dp[n - 1][2]) << endl; } signed main() { FAST int t = 1; // cin>>t; while (t--) solve(); return 0; } /*6 30 10 60 10 60 50*/
#include <bits/stdc++.h> using namespace std; #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define M 1000000007 #define mp make_pair #define pb push_back #define PB pop_back #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define lcase(a) (char)tolower(a) #define ucase(a) (char)toupper(a) #define precise(a) fixed << setprecision(a) << #define F first #define S second #define I insert #define pii pair<int, int> #define trav(a, x) for (auto &a : x) #define fl(i, n) for (int i = 0; i < n; i++) #define rfl(n) for (int i = n - 1; i >= 0; i--) #define time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.I(tmp); \ commands \ } #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl; #define ingrid(data, n, commands) \ for (int i = 0; i < n; i++) { \ cin >> data[i]; \ commands \ } #define section(a, b, w) \ set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define union(a, b, w) \ set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define copy(a, w) copy(a.begin(), a.end(), back_inserter(w)); #define all(data) data.begin(), data.end() #define PI 3.14159265358979323844 #define endl '\n' #define last(a) a[sz(a) - 1] #define mp make_pair #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // Graph DFS const int fx[] = {+1, -1, +0, +0}; const int fy[] = {+0, +0, +1, -1}; // primes for hashing 937,991,1013,1409,1741 // Returns index of first element not less than key and more than key // respectively #define lb(data, key) lower_bound(all(data), key) - data.begin(); #define up(data, key) upper_bound(all(data), key) - data.begin(); #define fnd(data, key) find(all(data), key) - data.begin(); // Long Long Int #define int long long int void solve() { int n; cin >> n; std::vector<std::vector<int>> v(n, std::vector<int>(3, 0)); fl(i, n) { fl(j, 3) { cin >> v[i][j]; } } int dp[n][3]; fl(i, 3) { dp[0][i] = v[0][i]; } for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + v[i][2]; } cout << max(max(dp[n - 1][1], dp[n - 1][0]), dp[n - 1][2]) << endl; } signed main() { FAST int t = 1; // cin>>t; while (t--) solve(); return 0; } /*6 30 10 60 10 60 50*/
replace
86
87
86
87
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int dp[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } for (int i = 0; i < 3; i++) dp[0][i] = a[0][i]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2]; } int ans = 0; for (int i = 0; i < 3; i++) { ans = max(dp[n - 1][i], ans); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int dp[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } for (int i = 0; i < 3; i++) dp[0][i] = a[0][i]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2]; } int ans = 0; for (int i = 0; i < 3; i++) { ans = max(dp[n - 1][i], ans); } cout << ans << endl; }
replace
6
7
6
7
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif ll n, i; cin >> n; ll a[n], b[n], c[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } ll dp[n][3]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]); dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]); dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]); // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl; } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n, i; cin >> n; ll a[n], b[n], c[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } ll dp[n][3]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]); dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]); dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]); // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl; } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; }
replace
5
8
5
6
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[10001][4], f[10001][4] = {0}; int main() { int i, j, k, n; scanf("%d", &n); for (i = 1; i <= n; i++) for (j = 1; j <= 3; j++) scanf("%d", &a[i][j]); for (i = 1; i <= n; i++) { for (j = 1; j <= 3; j++) { for (k = 1; k <= 3; k++) { if (k == j) continue; f[i][j] = max(f[i][j], f[i - 1][k] + a[i][j]); } } } printf("%d", max(f[n][1], max(f[n][2], f[n][3]))); return 0; }
#include <bits/stdc++.h> using namespace std; int a[100001][4], f[100001][4] = {0}; int main() { int i, j, k, n; scanf("%d", &n); for (i = 1; i <= n; i++) for (j = 1; j <= 3; j++) scanf("%d", &a[i][j]); for (i = 1; i <= n; i++) { for (j = 1; j <= 3; j++) { for (k = 1; k <= 3; k++) { if (k == j) continue; f[i][j] = max(f[i][j], f[i - 1][k] + a[i][j]); } } } printf("%d", max(f[n][1], max(f[n][2], f[n][3]))); return 0; }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD ((int)(1e9 + 7)) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long #define float long double int ans = 0; int32_t main() { IOS int n; cin >> n; vector<vector<int>> A(3, vector<int>(n + 1)), dp(3, vector<int>(n + 1)); for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { cin >> A[j][i]; } } for (int i = 0; i < 3; i++) { dp[i][1] = A[i][1]; } for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { dp[j][i + 1] = max(dp[(j + 1) % 3][i] + A[j][i + 1], dp[(j + 2) % 3][i] + A[j][i + 1]); } } cout << max({dp[0][n], dp[1][n], dp[2][n]}) << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD ((int)(1e9 + 7)) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long #define float long double int ans = 0; int32_t main() { IOS int n; cin >> n; vector<vector<int>> A(3, vector<int>(n + 1)), dp(3, vector<int>(n + 1)); for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { cin >> A[j][i]; } } for (int i = 0; i < 3; i++) { dp[i][1] = A[i][1]; } for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { dp[j][i + 1] = max(dp[(j + 1) % 3][i] + A[j][i + 1], dp[(j + 2) % 3][i] + A[j][i + 1]); } } cout << max({dp[0][n], dp[1][n], dp[2][n]}) << endl; }
replace
27
28
27
28
0
p03162
C++
Runtime Error
// C - Vacation #include <iostream> #include <vector> #define ll long long using namespace std; ll n; // vector<ll> dp(3, vector<ll>(1000005, -1)); ll dp[3][1000005]; ll cost(vector<vector<ll>> &matrix, ll selected, ll day) { if (dp[day][selected] != -1) return dp[day][selected]; if (day == matrix.size()) return matrix[day][selected]; dp[day][selected] = max(cost(matrix, (selected + 1) % 3, day + 1) + matrix[day][selected], cost(matrix, (selected + 2) % 3, day + 1) + matrix[day][selected]); return dp[day][selected]; } int main() { cin >> n; vector<vector<ll>> matrix(n, vector<ll>(3, -1)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> matrix[i][j]; } } cout << max(max(cost(matrix, 0, 0), cost(matrix, 1, 0)), cost(matrix, 2, 0)); }
// C - Vacation #include <iostream> #include <vector> #define ll long long using namespace std; ll n; // vector<ll> dp(3, vector<ll>(1000005, -1)); ll dp[1000005][3]; ll cost(vector<vector<ll>> &matrix, ll selected, ll day) { if (dp[day][selected] != -1) return dp[day][selected]; if (day == matrix.size()) return matrix[day][selected]; dp[day][selected] = max(cost(matrix, (selected + 1) % 3, day + 1) + matrix[day][selected], cost(matrix, (selected + 2) % 3, day + 1) + matrix[day][selected]); return dp[day][selected]; } int main() { cin >> n; vector<vector<ll>> matrix(n, vector<ll>(3, -1)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> matrix[i][j]; } } cout << max(max(cost(matrix, 0, 0), cost(matrix, 1, 0)), cost(matrix, 2, 0)); }
replace
10
11
10
11
0
p03162
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; #include <algorithm> #define str(a) to_string(a) #define int long long #define pb push_back int32_t main() { int n; cin >> n; vector<vector<int>> vec(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) cin >> vec[i][j]; } int dp[n][3]; dp[0][0] = vec[0][0]; dp[0][1] = vec[0][1]; dp[0][2] = vec[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = vec[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = vec[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = vec[i][2] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; }
#include <iostream> #include <vector> using namespace std; #include <algorithm> #define str(a) to_string(a) #define int long long #define pb push_back int32_t main() { int n; cin >> n; int vec[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) cin >> vec[i][j]; } int dp[n][3]; dp[0][0] = vec[0][0]; dp[0][1] = vec[0][1]; dp[0][2] = vec[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = vec[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = vec[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = vec[i][2] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl; }
replace
13
14
13
14
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <cstdio> typedef long long int ll; #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR_IN(i, a, b) for (int i = (a); i < (b); i++) #define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b)) using namespace std; /* N 10^5 a,b,c 10^4 N a1 b1 c1 ... aN bN cN */ int N; ll dp[100000][3]; int h[3]; int main() { cin >> N; REP(i, N) { REP(j, 3) cin >> h[j]; REP(j, 3) { REP(k, 3) { if (k == j) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + h[j]); } } } ll ans = 0; REP(j, 3) ans = max(ans, dp[N][j]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <cstdio> typedef long long int ll; #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR_IN(i, a, b) for (int i = (a); i < (b); i++) #define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b)) using namespace std; /* N 10^5 a,b,c 10^4 N a1 b1 c1 ... aN bN cN */ int N; ll dp[100001][3]; int h[3]; int main() { cin >> N; REP(i, N) { REP(j, 3) cin >> h[j]; REP(j, 3) { REP(k, 3) { if (k == j) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + h[j]); } } } ll ans = 0; REP(j, 3) ans = max(ans, dp[N][j]); cout << ans << endl; return 0; }
replace
20
21
20
21
0
p03162
C++
Runtime Error
/*************************************************** * Problem Name : C - Vacation.cpp * Problem Link : * OJ : * Verdict : Trying * Date : 2019-01-26 * Problem Type : * Author Name : Saikat Sharma * University : CSE, MBSTU ***************************************************/ #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define __FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define FileRead freopen("/home/saikat/Desktop/logN/input.txt", "r", stdin); #define FileWrite freopen("/home/saikat/Desktop/logN/output.txt", "w", stdout); #define SET(a, v) memset(a, v, sizeof(a)) #define pii pair<int, int> #define pll pair<ll, ll> #define debug cout << "#########\n"; #define nl cout << "\n"; #define sp cout << " "; #define sl(n) scanf("%lld", &n) #define sf(n) scanf("%lf", &n) #define si(n) scanf("%d", &n) #define ss(n) scanf("%s", n) #define pf(n) scanf("%d", n) #define pfl(n) scanf("%lld", n) #define all(v) v.begin(), v.end() #define Pow2(x) ((x) * (x)) #define Mod(x, m) ((((x) % (m)) + (m)) % (m)) #define Max3(a, b, c) max(a, max(b, c)) #define Min3(a, b, c) min(a, min(b, c)) #define pb push_back #define mk make_pair #define MAX 1005 #define INF 1000000000 using namespace std; typedef long long ll; typedef unsigned long long ull; template <typename T> std::string NumberToString(T Number) { std::ostringstream ss; ss << Number; return ss.str(); } ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } /************************************ Code Start Here * ******************************************************/ int ar[MAX][5]; int dp[MAX][5]; int n; int fun(int i, int t) { //~ debug; if (i == n - 1) { return ar[i][t]; } if (dp[i][t] != -1) return dp[i][t]; int ret1 = 0, ret2 = 0; if (t == 0) { ret1 = ar[i][t] + fun(i + 1, 1); ret2 = ar[i][t] + fun(i + 1, 2); } else if (t == 1) { ret1 = ar[i][t] + fun(i + 1, 0); ret2 = ar[i][t] + fun(i + 1, 2); } else { ret1 = ar[i][t] + fun(i + 1, 0); ret2 = ar[i][t] + fun(i + 1, 1); } return dp[i][t] = max(ret1, ret2); } int main() { //~ __FastIO; //~ int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> ar[i][j]; } } //~ debug; SET(dp, -1); int a = fun(0, 0); //~ debug; int b = fun(0, 1); int c = fun(0, 2); cout << Max3(a, b, c) << "\n"; return 0; }
/*************************************************** * Problem Name : C - Vacation.cpp * Problem Link : * OJ : * Verdict : Trying * Date : 2019-01-26 * Problem Type : * Author Name : Saikat Sharma * University : CSE, MBSTU ***************************************************/ #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define __FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define FileRead freopen("/home/saikat/Desktop/logN/input.txt", "r", stdin); #define FileWrite freopen("/home/saikat/Desktop/logN/output.txt", "w", stdout); #define SET(a, v) memset(a, v, sizeof(a)) #define pii pair<int, int> #define pll pair<ll, ll> #define debug cout << "#########\n"; #define nl cout << "\n"; #define sp cout << " "; #define sl(n) scanf("%lld", &n) #define sf(n) scanf("%lf", &n) #define si(n) scanf("%d", &n) #define ss(n) scanf("%s", n) #define pf(n) scanf("%d", n) #define pfl(n) scanf("%lld", n) #define all(v) v.begin(), v.end() #define Pow2(x) ((x) * (x)) #define Mod(x, m) ((((x) % (m)) + (m)) % (m)) #define Max3(a, b, c) max(a, max(b, c)) #define Min3(a, b, c) min(a, min(b, c)) #define pb push_back #define mk make_pair #define MAX 1000005 #define INF 1000000000 using namespace std; typedef long long ll; typedef unsigned long long ull; template <typename T> std::string NumberToString(T Number) { std::ostringstream ss; ss << Number; return ss.str(); } ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } /************************************ Code Start Here * ******************************************************/ int ar[MAX][5]; int dp[MAX][5]; int n; int fun(int i, int t) { //~ debug; if (i == n - 1) { return ar[i][t]; } if (dp[i][t] != -1) return dp[i][t]; int ret1 = 0, ret2 = 0; if (t == 0) { ret1 = ar[i][t] + fun(i + 1, 1); ret2 = ar[i][t] + fun(i + 1, 2); } else if (t == 1) { ret1 = ar[i][t] + fun(i + 1, 0); ret2 = ar[i][t] + fun(i + 1, 2); } else { ret1 = ar[i][t] + fun(i + 1, 0); ret2 = ar[i][t] + fun(i + 1, 1); } return dp[i][t] = max(ret1, ret2); } int main() { //~ __FastIO; //~ int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> ar[i][j]; } } //~ debug; SET(dp, -1); int a = fun(0, 0); //~ debug; int b = fun(0, 1); int c = fun(0, 2); cout << Max3(a, b, c) << "\n"; return 0; }
replace
50
51
50
51
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define endl "\n" #define mod 1000000007 using namespace std; int main() { ll n; cin >> n; ll dp[10001][3]; ll arr[10001][3]; for (ll i = 0; i < n; i++) { ll x, y, z; cin >> x >> y >> z; arr[i][0] = x; arr[i][1] = y; arr[i][2] = z; } for (ll i = 0; i < n; i++) { if (i == 0) { dp[i][0] = arr[i][0]; dp[i][1] = arr[i][1]; dp[i][2] = arr[i][2]; continue; } dp[i][0] = max(arr[i][0] + dp[i - 1][1], arr[i][0] + dp[i - 1][2]); dp[i][1] = max(arr[i][1] + dp[i - 1][0], arr[i][1] + dp[i - 1][2]); dp[i][2] = max(arr[i][2] + dp[i - 1][0], arr[i][2] + dp[i - 1][1]); } cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define endl "\n" #define mod 1000000007 using namespace std; int main() { ll n; cin >> n; ll dp[100001][3]; ll arr[100001][3]; for (ll i = 0; i < n; i++) { ll x, y, z; cin >> x >> y >> z; arr[i][0] = x; arr[i][1] = y; arr[i][2] = z; } for (ll i = 0; i < n; i++) { if (i == 0) { dp[i][0] = arr[i][0]; dp[i][1] = arr[i][1]; dp[i][2] = arr[i][2]; continue; } dp[i][0] = max(arr[i][0] + dp[i - 1][1], arr[i][0] + dp[i - 1][2]); dp[i][1] = max(arr[i][1] + dp[i - 1][0], arr[i][1] + dp[i - 1][2]); dp[i][2] = max(arr[i][2] + dp[i - 1][0], arr[i][2] + dp[i - 1][1]); } cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl; return 0; }
replace
10
12
10
12
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rep(i, n) FOR(i, 0, n - 1) typedef long long ll; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // 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 N; cin >> N; ll act[N][3]; rep(i, N) { rep(j, 3) { cin >> act[i][j]; } } vector<vector<ll>> dp(N, vector<ll>(3)); rep(i, N) { rep(j, 3) { rep(k, 3) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + act[i][k]); } } } ll res = 0; rep(j, 3) chmax(res, dp[N][j]); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rep(i, n) FOR(i, 0, n - 1) typedef long long ll; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // 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 N; cin >> N; ll act[N][3]; rep(i, N) { rep(j, 3) { cin >> act[i][j]; } } vector<vector<ll>> dp(N + 10, vector<ll>(3)); rep(i, N) { rep(j, 3) { rep(k, 3) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + act[i][k]); } } } ll res = 0; rep(j, 3) chmax(res, dp[N][j]); cout << res << endl; }
replace
33
34
33
34
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define FAST_INPUT \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define ll long long using namespace std; void solve() { int n; cin >> n; vector<vector<int>> nums(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> nums[i][j]; } } vector<vector<int>> dp(n, vector<int>(3, 0)); for (int i = 0; i < 3; i++) { dp[0][i] = nums[0][i]; } for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { int mx = 0; for (int k = 0; k < 3; k++) { if (j != k) { mx = max(mx, dp[i - 1][k]); } } dp[i][j] = mx + nums[i][j]; } } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } int main() { FAST_INPUT; solve(); return 0; }
#include <bits/stdc++.h> #define FAST_INPUT \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define ll long long using namespace std; void solve() { int n; cin >> n; vector<vector<int>> nums(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> nums[i][j]; } } vector<vector<int>> dp(n, vector<int>(3, 0)); for (int i = 0; i < 3; i++) { dp[0][i] = nums[0][i]; } for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { int mx = 0; for (int k = 0; k < 3; k++) { if (j != k) { mx = max(mx, dp[i - 1][k]); } } dp[i][j] = mx + nums[i][j]; } } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } int main() { FAST_INPUT; solve(); return 0; }
replace
25
26
25
26
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int dp[100000 + 1][3]; struct vacation { int a, b, c; }; int solve(vector<vacation> v, int i, int n, int j) { if (i > n) return 0; if (dp[i][j] != -1) return dp[i][j]; int sol = 0; if (j == 0) dp[i][j] = max(v[i].b + solve(v, i + 1, n, 1), v[i].c + solve(v, i + 1, n, 2)); else if (j == 1) dp[i][j] = max(v[i].a + solve(v, i + 1, n, 0), v[i].c + solve(v, i + 1, n, 2)); else dp[i][j] = max(v[i].b + solve(v, i + 1, n, 1), v[i].a + solve(v, i + 1, n, 0)); return dp[i][j]; } int main() { ll n; cin >> n; vector<vacation> v(n + 1); int x, y, z; for (int i = 1; i <= n; i++) { cin >> v[i].a; cin >> v[i].b; cin >> v[i].c; } for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i][j] = -1; dp[1][0] = v[1].a; dp[1][1] = v[1].b; dp[1][2] = v[1].c; int A = v[1].a + solve(v, 2, n, 0); int B = v[1].b + solve(v, 2, n, 1); int C = v[1].c + solve(v, 2, n, 2); cout << max(A, max(B, C)) << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int dp[100000 + 1][3]; struct vacation { int a, b, c; }; int solve(vector<vacation> &v, int i, int n, int j) { if (i > n) return 0; if (dp[i][j] != -1) return dp[i][j]; int sol = 0; if (j == 0) dp[i][j] = max(v[i].b + solve(v, i + 1, n, 1), v[i].c + solve(v, i + 1, n, 2)); else if (j == 1) dp[i][j] = max(v[i].a + solve(v, i + 1, n, 0), v[i].c + solve(v, i + 1, n, 2)); else dp[i][j] = max(v[i].b + solve(v, i + 1, n, 1), v[i].a + solve(v, i + 1, n, 0)); return dp[i][j]; } int main() { ll n; cin >> n; vector<vacation> v(n + 1); int x, y, z; for (int i = 1; i <= n; i++) { cin >> v[i].a; cin >> v[i].b; cin >> v[i].c; } for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i][j] = -1; dp[1][0] = v[1].a; dp[1][1] = v[1].b; dp[1][2] = v[1].c; int A = v[1].a + solve(v, 2, n, 0); int B = v[1].b + solve(v, 2, n, 1); int C = v[1].c + solve(v, 2, n, 2); cout << max(A, max(B, C)) << endl; return 0; }
replace
10
11
10
11
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> abc(n, vector<int>(3)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> abc[i][j]; vector<vector<int>> dp(n + 1, vector<int>(3, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j]); } } } cout << *max_element(dp[n].begin(), dp[n].end()) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> abc(n, vector<int>(3)); for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> abc[i][j]; vector<vector<int>> dp(n + 1, vector<int>(3, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j]); } } } cout << *max_element(dp[n].begin(), dp[n].end()) << endl; return 0; }
replace
8
9
8
9
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long // #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 998244353 #define endl "\n" #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } // #DEBUG void __print(int x) { cout << x; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cout << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif // ################################################################### int pow(int a, int b, int m) { int r = 1, e = a; while (b) { if (b & 1) r = (r * e) % m; e = (e * e) % m; b >>= 1; } return r; } void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // First write recursive with no ristrictions; // Then apply ristrictions; (What can we do? and Can we do it?) // We are adding mod because sometimes ans could be negeative (So always add mod // when substracting 2 mod answers) int n; int a[100005][4]; int dp[100005][4]; int solve(int day, int flag) { if (day == n) { return 0; } if (dp[day][flag] != -1) { return dp[day][flag]; } int maxi = 0; if (flag == 0) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][2] + solve(day + 1, 2)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 1) { maxi = max(maxi, a[day][2] + solve(day + 1, 2)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 2) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 3) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][2] + solve(day + 1, 2)); } return dp[day][flag] = maxi; } int32_t main() { fast(); cin >> n; for (int i = 0; i < n; i++) { for (int j = 1; j <= 3; j++) { cin >> a[i][j]; } } memset(dp, -1, sizeof(dp)); cout << solve(0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long // #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 998244353 #define endl "\n" #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } // #DEBUG void __print(int x) { cout << x; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cout << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif // ################################################################### int pow(int a, int b, int m) { int r = 1, e = a; while (b) { if (b & 1) r = (r * e) % m; e = (e * e) % m; b >>= 1; } return r; } void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } // First write recursive with no ristrictions; // Then apply ristrictions; (What can we do? and Can we do it?) // We are adding mod because sometimes ans could be negeative (So always add mod // when substracting 2 mod answers) int n; int a[100005][4]; int dp[100005][4]; int solve(int day, int flag) { if (day == n) { return 0; } if (dp[day][flag] != -1) { return dp[day][flag]; } int maxi = 0; if (flag == 0) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][2] + solve(day + 1, 2)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 1) { maxi = max(maxi, a[day][2] + solve(day + 1, 2)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 2) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][3] + solve(day + 1, 3)); } if (flag == 3) { maxi = max(maxi, a[day][1] + solve(day + 1, 1)); maxi = max(maxi, a[day][2] + solve(day + 1, 2)); } return dp[day][flag] = maxi; } int32_t main() { fast(); cin >> n; for (int i = 0; i < n; i++) { for (int j = 1; j <= 3; j++) { cin >> a[i][j]; } } memset(dp, -1, sizeof(dp)); cout << solve(0, 0) << endl; }
delete
89
93
89
89
0
p03162
C++
Runtime Error
/* โ•”โ•โ•โ•โ•ฆโ•โ•โ•โ•ฆโ•โ•โ•โ•— โ•‘โ•”โ•โ•—โ•‘โ•”โ•โ•โ•ฉโ•—โ•”โ•—โ•‘ โ•‘โ•‘โ–‘โ•‘โ•‘โ•šโ•โ•โ•—โ•‘โ•‘โ•‘โ•‘ โ•‘โ•‘โ–‘โ•‘โ•‘โ•”โ•โ•โ•โ•‘โ•‘โ•‘โ•‘ โ•‘โ•šโ•โ•โ•‘โ•šโ•โ•โ•ฆโ•โ•šโ•โ•‘ โ•šโ•โ•โ•—โ• โ•โ•โ•โ•ฉโ•โ•โ•โ• โ–‘โ–‘โ–‘โ•šโ•โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ */ /* * * * */ #include <bits/stdc++.h> #define ll long long #define MAX 10000 using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[MAX][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; int dp[MAX][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]); dp[i][1] = max(dp[i - 1][1], max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]); dp[i][2] = max(dp[i - 1][2], max(dp[i - 1][0], dp[i - 1][1]) + a[i][2]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); return 0; }
/* โ•”โ•โ•โ•โ•ฆโ•โ•โ•โ•ฆโ•โ•โ•โ•— โ•‘โ•”โ•โ•—โ•‘โ•”โ•โ•โ•ฉโ•—โ•”โ•—โ•‘ โ•‘โ•‘โ–‘โ•‘โ•‘โ•šโ•โ•โ•—โ•‘โ•‘โ•‘โ•‘ โ•‘โ•‘โ–‘โ•‘โ•‘โ•”โ•โ•โ•โ•‘โ•‘โ•‘โ•‘ โ•‘โ•šโ•โ•โ•‘โ•šโ•โ•โ•ฆโ•โ•šโ•โ•‘ โ•šโ•โ•โ•—โ• โ•โ•โ•โ•ฉโ•โ•โ•โ• โ–‘โ–‘โ–‘โ•šโ•โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ */ /* * * * */ #include <bits/stdc++.h> #define ll long long #define MAX 100000 using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[MAX][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; int dp[MAX][3]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]); dp[i][1] = max(dp[i - 1][1], max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]); dp[i][2] = max(dp[i - 1][2], max(dp[i - 1][0], dp[i - 1][1]) + a[i][2]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); return 0; }
replace
16
17
16
17
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int solve(vector<array<int, 3>> &v_abc, vector<vector<int>> memo, int pre = -1, int cur = 0) { int n = v_abc.size(); if (cur == n) { return 0; } if (memo[cur][pre + 1] == -1) { int ans = 0; for (int i = 0; i < 3; ++i) { if (i != pre) { ans = max(ans, solve(v_abc, memo, i, cur + 1) + v_abc[cur][i]); } } memo[cur][pre + 1] = ans; } return memo[cur][pre + 1]; } int main(int argc, const char *argv[]) { int n; cin >> n; vector<array<int, 3>> v_abc(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> v_abc[i][j]; } } vector<vector<int>> memo(n, vector<int>(4, -1)); cout << solve(v_abc, memo) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int solve(vector<array<int, 3>> &v_abc, vector<vector<int>> &memo, int pre = -1, int cur = 0) { int n = v_abc.size(); if (cur == n) { return 0; } if (memo[cur][pre + 1] == -1) { int ans = 0; for (int i = 0; i < 3; ++i) { if (i != pre) { ans = max(ans, solve(v_abc, memo, i, cur + 1) + v_abc[cur][i]); } } memo[cur][pre + 1] = ans; } return memo[cur][pre + 1]; } int main(int argc, const char *argv[]) { int n; cin >> n; vector<array<int, 3>> v_abc(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> v_abc[i][j]; } } vector<vector<int>> memo(n, vector<int>(4, -1)); cout << solve(v_abc, memo) << '\n'; return 0; }
replace
4
5
4
5
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf("%d", &n); vector<vector<int>> a(n, vector<int>(3, 0)); vector<vector<int>> dp(n, vector<int>(3, 0)); for (i = 0; i < n; i++) { scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]); } dp[n - 1][0] = a[i][0]; dp[n - 1][1] = a[i][1]; dp[n - 1][2] = a[i][2]; for (i = n - 2; i >= 0; i--) { dp[i][0] = a[i][0] + max(dp[i + 1][1], dp[i + 1][2]); dp[i][1] = a[i][1] + max(dp[i + 1][0], dp[i + 1][2]); dp[i][2] = a[i][2] + max(dp[i + 1][0], dp[i + 1][1]); } printf("%d", max({dp[0][0], dp[0][1], dp[0][2]})); }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf("%d", &n); vector<vector<int>> a(n, vector<int>(3, 0)); vector<vector<int>> dp(n, vector<int>(3, 0)); for (i = 0; i < n; i++) { scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]); } dp[n - 1][0] = a[n - 1][0]; dp[n - 1][1] = a[n - 1][1]; dp[n - 1][2] = a[n - 1][2]; for (i = n - 2; i >= 0; i--) { dp[i][0] = a[i][0] + max(dp[i + 1][1], dp[i + 1][2]); dp[i][1] = a[i][1] + max(dp[i + 1][0], dp[i + 1][2]); dp[i][2] = a[i][2] + max(dp[i + 1][0], dp[i + 1][1]); } printf("%d", max({dp[0][0], dp[0][1], dp[0][2]})); }
replace
12
15
12
15
-11
p03162
C++
Runtime Error
/* Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College Date:12/06/2020 */ #include <algorithm> #include <bits/stdc++.h> #include <string> using namespace std; #define ll long long #define int ll #define ld long double #define ff first #define ss string #define se second #define alt(v) v.begin(), v.end() #define pb emplace_back #define mp make_pair #define fab(i, a, b) for (ll i = (a); i < (b); i++) #define fba(i, a, b) for (ll i = (b); i >= (a); i--) // ll mod=1000000007; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int N = 1e5 + 5; int cache[N][3]; int a[N][3]; int n; int dp(int idx, int f) { if (idx == n) return 0; int &ans = cache[idx][f]; if (ans != -1) return ans; ans = 0; for (int i = 0; i < 3; i++) { if (i == f) continue; ans = max(ans, dp(idx + 1, i)); } ans += a[idx][f]; return ans; } bool test = 0; void solve() { cin >> n; memset(cache, -1, sizeof(cache)); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; int ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, dp(0, i)); cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin.exceptions(cin.failbit); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; if (test) cin >> t; while (t--) { solve(); } return 0; }
/* Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College Date:12/06/2020 */ #include <algorithm> #include <bits/stdc++.h> #include <string> using namespace std; #define ll long long #define int ll #define ld long double #define ff first #define ss string #define se second #define alt(v) v.begin(), v.end() #define pb emplace_back #define mp make_pair #define fab(i, a, b) for (ll i = (a); i < (b); i++) #define fba(i, a, b) for (ll i = (b); i >= (a); i--) // ll mod=1000000007; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int N = 1e5 + 5; int cache[N][3]; int a[N][3]; int n; int dp(int idx, int f) { if (idx == n) return 0; int &ans = cache[idx][f]; if (ans != -1) return ans; ans = 0; for (int i = 0; i < 3; i++) { if (i == f) continue; ans = max(ans, dp(idx + 1, i)); } ans += a[idx][f]; return ans; } bool test = 0; void solve() { cin >> n; memset(cache, -1, sizeof(cache)); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; int ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, dp(0, i)); cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin.exceptions(cin.failbit); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; if (test) cin >> t; while (t--) { solve(); } return 0; }
replace
59
63
59
63
-6
terminate called after throwing an instance of 'std::__ios_failure' what(): basic_ios::clear: iostream error
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[10020], b[10020], c[10020]; int da[10020], db[10020], dc[10020]; int resiA(int i, int n); int resiB(int i, int n); int resiC(int i, int n); int resiA(int i, int n) { if (i == n - 1) { return a[i]; } if (da[i] == 0) { da[i] = max(resiB(i + 1, n) + a[i], resiC(i + 1, n) + a[i]); } return da[i]; } int resiB(int i, int n) { if (i == n - 1) { return b[i]; } if (db[i] == 0) { db[i] = max(resiA(i + 1, n) + b[i], resiC(i + 1, n) + b[i]); } return db[i]; } int resiC(int i, int n) { if (i == n - 1) { return c[i]; } if (dc[i] == 0) { dc[i] = max(resiA(i + 1, n) + c[i], resiB(i + 1, n) + c[i]); } return dc[i]; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; da[i] = 0; db[i] = 0; dc[i] = 0; } int rez = max(max(resiB(0, n), resiC(0, n)), resiA(0, n)); cout << rez; return 0; }
#include <bits/stdc++.h> using namespace std; int a[100200], b[100020], c[100020]; int da[100200], db[100020], dc[100020]; int resiA(int i, int n); int resiB(int i, int n); int resiC(int i, int n); int resiA(int i, int n) { if (i == n - 1) { return a[i]; } if (da[i] == 0) { da[i] = max(resiB(i + 1, n) + a[i], resiC(i + 1, n) + a[i]); } return da[i]; } int resiB(int i, int n) { if (i == n - 1) { return b[i]; } if (db[i] == 0) { db[i] = max(resiA(i + 1, n) + b[i], resiC(i + 1, n) + b[i]); } return db[i]; } int resiC(int i, int n) { if (i == n - 1) { return c[i]; } if (dc[i] == 0) { dc[i] = max(resiA(i + 1, n) + c[i], resiB(i + 1, n) + c[i]); } return dc[i]; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; da[i] = 0; db[i] = 0; dc[i] = 0; } int rez = max(max(resiB(0, n), resiC(0, n)), resiA(0, n)); cout << rez; return 0; }
replace
4
6
4
6
0