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; // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef vector<pii> vpii; typedef vector<pil> vpil; typedef vector<pli> vpli; typedef set<int> si; typedef set<ll> sll; typedef map<int, int> mii; typedef map<ll, ll> mll; const double pi = acos(-1.0); const long long INF = 2e18; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define in insert #define endl "\n" #define sqr(a) ((a) * (a)) #define jor(a) !(a & 1) // jor means EVEN number #define bjor(a) (a & 1) // bjor means ODD number #define all(a) a.begin(), a.end() #define mem(arr, b) memset(arr, b, sizeof(arr)) // memset only for -1 and 0 // fill(a, a+n, 5) //fill for any value #define for0(i, b) for (int i = 0; i < (b); i++) #define for1(i, b) for (int i = 1; i <= (b); i++) #define forab(i, a, b) for (int i = (a); i <= (b); i++) #define forba(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define fileRead freopen("input.txt", "r", stdin); #define fileWrite freopen("output.txt", "w", stdout); void print(int a[], int n) { // for testing or debugging for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; } //----------------------------------------------------------------------- int const mx = 10005; int a[mx], b[mx], c[mx], N; int dpA[mx], dpB[mx], dpC[mx]; int fun(char ch, int n) { /// base case if (n == 0) { if (ch == 'a') return max(b[0], c[0]); if (ch == 'b') return max(a[0], c[0]); if (ch == 'c') return max(a[0], b[0]); } /// memoization if (ch == 'a' and dpA[n] != -1) return dpA[n]; if (ch == 'b' and dpB[n] != -1) return dpB[n]; if (ch == 'c' and dpC[n] != -1) return dpC[n]; if (ch == 'a') { dpA[n] = a[n] + max(fun('b', n - 1), fun('c', n - 1)); return dpA[n]; } if (ch == 'b') { dpB[n] = b[n] + max(fun('a', n - 1), fun('c', n - 1)); return dpB[n]; } if (ch == 'c') { dpC[n] = c[n] + max(fun('a', n - 1), fun('b', n - 1)); return dpC[n]; } } int main() { IOS; // fileRead; int tc = 1; // cin>>tc; while (tc--) { mem(dpA, -1), mem(dpB, -1), mem(dpC, -1); cin >> N; for0(i, N) cin >> a[i] >> b[i] >> c[i]; cout << max({fun('a', N - 1), fun('b', N - 1), fun('c', N - 1)}); } }
#include <bits/stdc++.h> using namespace std; // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef vector<pii> vpii; typedef vector<pil> vpil; typedef vector<pli> vpli; typedef set<int> si; typedef set<ll> sll; typedef map<int, int> mii; typedef map<ll, ll> mll; const double pi = acos(-1.0); const long long INF = 2e18; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define in insert #define endl "\n" #define sqr(a) ((a) * (a)) #define jor(a) !(a & 1) // jor means EVEN number #define bjor(a) (a & 1) // bjor means ODD number #define all(a) a.begin(), a.end() #define mem(arr, b) memset(arr, b, sizeof(arr)) // memset only for -1 and 0 // fill(a, a+n, 5) //fill for any value #define for0(i, b) for (int i = 0; i < (b); i++) #define for1(i, b) for (int i = 1; i <= (b); i++) #define forab(i, a, b) for (int i = (a); i <= (b); i++) #define forba(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define fileRead freopen("input.txt", "r", stdin); #define fileWrite freopen("output.txt", "w", stdout); void print(int a[], int n) { // for testing or debugging for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; } //----------------------------------------------------------------------- int const mx = 100005; int a[mx], b[mx], c[mx], N; int dpA[mx], dpB[mx], dpC[mx]; int fun(char ch, int n) { /// base case if (n == 0) { if (ch == 'a') return max(b[0], c[0]); if (ch == 'b') return max(a[0], c[0]); if (ch == 'c') return max(a[0], b[0]); } /// memoization if (ch == 'a' and dpA[n] != -1) return dpA[n]; if (ch == 'b' and dpB[n] != -1) return dpB[n]; if (ch == 'c' and dpC[n] != -1) return dpC[n]; if (ch == 'a') { dpA[n] = a[n] + max(fun('b', n - 1), fun('c', n - 1)); return dpA[n]; } if (ch == 'b') { dpB[n] = b[n] + max(fun('a', n - 1), fun('c', n - 1)); return dpB[n]; } if (ch == 'c') { dpC[n] = c[n] + max(fun('a', n - 1), fun('b', n - 1)); return dpC[n]; } } int main() { IOS; // fileRead; int tc = 1; // cin>>tc; while (tc--) { mem(dpA, -1), mem(dpB, -1), mem(dpC, -1); cin >> N; for0(i, N) cin >> a[i] >> b[i] >> c[i]; cout << max({fun('a', N - 1), fun('b', N - 1), fun('c', N - 1)}); } }
replace
62
63
62
63
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" const int N = 1e5 + 5; int a[5][N]; int dp[5][N]; int n; int solve(int idx, int prev) { if (idx == n + 1) { return 0; } int &ans = dp[prev][idx]; if (ans != -1) { return ans; } ans = 0; for (int i = 1; i <= 3; i++) { if (i == prev) { continue; } ans = max(ans, a[i][idx] + solve(idx + 1, i)); } return ans; } int32_t main() { memset(dp, -1, sizeof(dp)); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 3; j++) { cin >> a[i][j]; } } int ans = solve(1, 0); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" const int N = 1e5 + 5; int a[5][N]; int dp[5][N]; int n; int solve(int idx, int prev) { if (idx == n + 1) { return 0; } int &ans = dp[prev][idx]; if (ans != -1) { return ans; } ans = 0; for (int i = 1; i <= 3; i++) { if (i == prev) { continue; } ans = max(ans, a[i][idx] + solve(idx + 1, i)); } return ans; } int32_t main() { memset(dp, -1, sizeof(dp)); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 3; j++) { cin >> a[j][i]; } } int ans = solve(1, 0); cout << ans << "\n"; return 0; }
replace
41
42
41
42
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int const int maxn = 1e5 + 5; const int inf = 1e10; vector<vector<int>> dp(maxn, vector<int>(3, inf)); vector<int> a(maxn), b(maxn), c(maxn); int n; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif 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]; // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl; 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<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl; } 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; #define int long long int const int maxn = 1e5 + 5; const int inf = 1e10; vector<vector<int>> dp(maxn, vector<int>(3, inf)); vector<int> a(maxn), b(maxn), c(maxn); int n; int32_t main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif 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]; // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl; 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<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; return 0; }
replace
12
16
12
16
-11
p03162
C++
Runtime Error
/** * @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad */ #include <bits/stdc++.h> using namespace std; // General #define ll long long #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define mod9 998244353 #define endl "\n" #define debug(x) cout << x << endl #define REP(i, n) for (i = 0; i < n; ++i) #define FOR(i, x, n) for (i = x; i < n; ++i) // Bounds #define lb(a, x) a.lower_bound(x) #define ub(a, x) a.upper_bound(x) #define all(a) a.begin(), a.end() // Vector #define vi vector<int> #define pb(v, x) v.push_back(x) #define vsi vector<set<int>> // Map #define mii map<int, int> // Set #define si set<int> // Pair #define vpii vector<pair<int, int>> #define pii pair<int, int> #define F first #define S second ll power_Mod(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = ((res % (ll)mod) * (x % (ll)mod)) % (ll)mod; y = y >> 1; x = ((x % (ll)mod) * (x % (ll)mod)) % (ll)mod; } return res; } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } int is_palin(string s) { int i, len = s.length(); for (i = 0; i < len / 2; i++) if (s[i] != s[len - i - 1]) break; if (i == len / 2) return 1; else return 0; } ll ceiling(double d) { ll d_ = (ll)d; if (d == d_) return d_; else return d_ + 1; } ll flooring(double d) { ll d_ = (ll)d; return d_; } void showSet(set<int> s) { si::iterator it; it = s.begin(); while (it != s.end()) { cout << (*it) << " "; it++; } cout << endl; } bool cmp(string a, string b) { ll x = a.length(); ll y = b.length(); // if(x != y) return x < y; return x < y; } /******************* NUMBER THEORY ********************/ void prime_factors(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { cout << i << " "; while (n % i == 0) n /= i; } } if (n > 1) cout << n << " "; } bool is_prime(int n) { int i, flag = 0; for (i = 2; i * i <= n; i++) { if (n % i == 0) { flag = 1; break; } } if (flag == 1) return false; return true; } // bool prime[1000000+1]; // void SieveOfEratosthenes() // { // memset(prime, true, sizeof(prime)); // for (int p=2; p*p<=1000000+1; p++) // { // if (prime[p] == true) // { // for (int i=p*p; i<=1000000+1; i += p) // prime[i] = false; // } // } // } /********************** NUMBER THEORY ENDS ***********************/ /***************************** FOR C(n, r) and P(n, r) *****************************/ /* ll fact[1000000 + 1]; ll invfact[1000000 + 1]; void calcFact() { fact[0] = 1; for(ll i = 1; i <= 1000000; i++) fact[i] = ((fact[i - 1] % mod) * (i % mod) ) % mod; } void calcInvFact() { invfact[0] = 1; for(ll i = 1; i <= 1000000; i++) invfact[i] = (power_moD(fact[i], mod - 2) % mod); } ll nCr(ll n, ll r) { return ((((fact[n] % mod) * (invfact[r] % mod)) % mod) * (invfact[n-r] % mod) ) % mod; } */ /***************************** C(n, r) and P(n, r) ENDS *****************************/ /************************* GRAPH ALGORITHMS **************************/ // bool visited[100000+1] = {false}; /* Depth First Search */ // void dfs(vi graph[], int n) { // visited[n] = true; // ll size = graph[n].size(); // for(int i: graph[n]) { // if(!visited[i]) { // dfs(graph, i); // } // } // } /* Breadth First Search */ // queue<int> Q; // void bfs(vi graph[], int n) { // int v; // Q.push(n); // visited[n] = true; // while(!Q.empty()) { // v = Q.front(); // Q.pop(); // for(int i: graph[v]) { // if(!visited[i]){ // visited[i] = true; // Q.push(i); // } // } // } // } // void add_edge(vi graph[], int a, int b) { // pb(graph[a], b); // pb(graph[b], a); // } /* Disjoint Set Union (DSU) */ // vi size(100000+1, 1); // vi graph(100000+1); // int root(int i) { // // Finding root of any element // while(graph[i] != i) { // graph[i] = graph[graph[i]]; // Path compression // i = graph[i]; // } // return i; // } // bool find_(int p, int q) { // // Check whether two elements are in same subset // int root_p = root(p); // int root_q = root(q); // if(root_p == root_q) return true; // return false; // } // void dsu(int p, int q) { // // Union of two elements // int root_p = root(p); // int root_q = root(q); // if(!find_(p, q)) { // if(size[root_p] > size[root_q]) { // // root of p will be ultimate root // graph[root_q] = root_p; // size[root_p] += size[root_q]; // } // else { // // root of q will be ultimate root // graph[root_p] = root_q; // size[root_q] += size[root_p]; // } // } // } /******************* GRAPH ALGO ENDS *******************/ // int bits[32] = {0}; // mii chk; // void countSetBits(int n) { // int i = 0; // int temp = n; // while(temp) { // if(temp&1){ // bits[i]++; // chk[i] = n; // } // temp>>=1; // ++i; // } // } int main() { #ifndef ONLINE_JUDGE FILE *input, *output; // for getting input from input.txt input = freopen("input.txt", "r", stdin); // for writing output to output.txt // output = freopen("output.txt", "w", stdout); #endif io; ll t, n, i, j; t = 1; // cin >> t; while (t--) { cin >> n; vi a(n), b(n), c(n); REP(i, n) cin >> a[i] >> b[i] >> c[i]; int dp[n][3]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; FOR(i, 1, n) { 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]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } return 0; }
/** * @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad */ #include <bits/stdc++.h> using namespace std; // General #define ll long long #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define mod9 998244353 #define endl "\n" #define debug(x) cout << x << endl #define REP(i, n) for (i = 0; i < n; ++i) #define FOR(i, x, n) for (i = x; i < n; ++i) // Bounds #define lb(a, x) a.lower_bound(x) #define ub(a, x) a.upper_bound(x) #define all(a) a.begin(), a.end() // Vector #define vi vector<int> #define pb(v, x) v.push_back(x) #define vsi vector<set<int>> // Map #define mii map<int, int> // Set #define si set<int> // Pair #define vpii vector<pair<int, int>> #define pii pair<int, int> #define F first #define S second ll power_Mod(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = ((res % (ll)mod) * (x % (ll)mod)) % (ll)mod; y = y >> 1; x = ((x % (ll)mod) * (x % (ll)mod)) % (ll)mod; } return res; } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } int is_palin(string s) { int i, len = s.length(); for (i = 0; i < len / 2; i++) if (s[i] != s[len - i - 1]) break; if (i == len / 2) return 1; else return 0; } ll ceiling(double d) { ll d_ = (ll)d; if (d == d_) return d_; else return d_ + 1; } ll flooring(double d) { ll d_ = (ll)d; return d_; } void showSet(set<int> s) { si::iterator it; it = s.begin(); while (it != s.end()) { cout << (*it) << " "; it++; } cout << endl; } bool cmp(string a, string b) { ll x = a.length(); ll y = b.length(); // if(x != y) return x < y; return x < y; } /******************* NUMBER THEORY ********************/ void prime_factors(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { cout << i << " "; while (n % i == 0) n /= i; } } if (n > 1) cout << n << " "; } bool is_prime(int n) { int i, flag = 0; for (i = 2; i * i <= n; i++) { if (n % i == 0) { flag = 1; break; } } if (flag == 1) return false; return true; } // bool prime[1000000+1]; // void SieveOfEratosthenes() // { // memset(prime, true, sizeof(prime)); // for (int p=2; p*p<=1000000+1; p++) // { // if (prime[p] == true) // { // for (int i=p*p; i<=1000000+1; i += p) // prime[i] = false; // } // } // } /********************** NUMBER THEORY ENDS ***********************/ /***************************** FOR C(n, r) and P(n, r) *****************************/ /* ll fact[1000000 + 1]; ll invfact[1000000 + 1]; void calcFact() { fact[0] = 1; for(ll i = 1; i <= 1000000; i++) fact[i] = ((fact[i - 1] % mod) * (i % mod) ) % mod; } void calcInvFact() { invfact[0] = 1; for(ll i = 1; i <= 1000000; i++) invfact[i] = (power_moD(fact[i], mod - 2) % mod); } ll nCr(ll n, ll r) { return ((((fact[n] % mod) * (invfact[r] % mod)) % mod) * (invfact[n-r] % mod) ) % mod; } */ /***************************** C(n, r) and P(n, r) ENDS *****************************/ /************************* GRAPH ALGORITHMS **************************/ // bool visited[100000+1] = {false}; /* Depth First Search */ // void dfs(vi graph[], int n) { // visited[n] = true; // ll size = graph[n].size(); // for(int i: graph[n]) { // if(!visited[i]) { // dfs(graph, i); // } // } // } /* Breadth First Search */ // queue<int> Q; // void bfs(vi graph[], int n) { // int v; // Q.push(n); // visited[n] = true; // while(!Q.empty()) { // v = Q.front(); // Q.pop(); // for(int i: graph[v]) { // if(!visited[i]){ // visited[i] = true; // Q.push(i); // } // } // } // } // void add_edge(vi graph[], int a, int b) { // pb(graph[a], b); // pb(graph[b], a); // } /* Disjoint Set Union (DSU) */ // vi size(100000+1, 1); // vi graph(100000+1); // int root(int i) { // // Finding root of any element // while(graph[i] != i) { // graph[i] = graph[graph[i]]; // Path compression // i = graph[i]; // } // return i; // } // bool find_(int p, int q) { // // Check whether two elements are in same subset // int root_p = root(p); // int root_q = root(q); // if(root_p == root_q) return true; // return false; // } // void dsu(int p, int q) { // // Union of two elements // int root_p = root(p); // int root_q = root(q); // if(!find_(p, q)) { // if(size[root_p] > size[root_q]) { // // root of p will be ultimate root // graph[root_q] = root_p; // size[root_p] += size[root_q]; // } // else { // // root of q will be ultimate root // graph[root_p] = root_q; // size[root_q] += size[root_p]; // } // } // } /******************* GRAPH ALGO ENDS *******************/ // int bits[32] = {0}; // mii chk; // void countSetBits(int n) { // int i = 0; // int temp = n; // while(temp) { // if(temp&1){ // bits[i]++; // chk[i] = n; // } // temp>>=1; // ++i; // } // } int main() { io; ll t, n, i, j; t = 1; // cin >> t; while (t--) { cin >> n; vi a(n), b(n), c(n); REP(i, n) cin >> a[i] >> b[i] >> c[i]; int dp[n][3]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; FOR(i, 1, n) { 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]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } return 0; }
delete
272
279
272
272
-11
p03162
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iosfwd> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define lli long long int #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long INF = 1LL << 57; const int M = 1e6 + 500; lli dp[N][3]; void solve() { lli n; cin >> n; lli a[n][3]; for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][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][0], dp[i - 1][1]) + a[i][2]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl; return; } /* 10 6 10 3 2 5 7 8 */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); lli t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iosfwd> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define lli long long int #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long INF = 1LL << 57; const int M = 1e6 + 500; lli dp[N][3]; void solve() { lli n; cin >> n; lli a[n + 1][3]; for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][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][0], dp[i - 1][1]) + a[i][2]; } cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl; return; } /* 10 6 10 3 2 5 7 8 */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); lli t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
44
45
44
45
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int h[10005][3]; int dp[10005][3]; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i][0] >> h[i][1] >> h[i][2]; } memset(dp, INT_MIN, sizeof(dp)); dp[0][0] = h[0][0]; dp[0][1] = h[0][1]; dp[0][2] = h[0][2]; for (int day = 1; day < n; day++) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { dp[day][j] = max(dp[day - 1][i] + h[day][j], dp[day][j]); } } } } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); }
#include <bits/stdc++.h> using namespace std; int main() { int n; int h[100100][3]; int dp[100100][3]; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i][0] >> h[i][1] >> h[i][2]; } memset(dp, INT_MIN, sizeof(dp)); dp[0][0] = h[0][0]; dp[0][1] = h[0][1]; dp[0][2] = h[0][2]; for (int day = 1; day < n; day++) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { dp[day][j] = max(dp[day - 1][i] + h[day][j], dp[day][j]); } } } } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); }
replace
6
8
6
8
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int N = 1e5 + 5; int a[N][3], n; int cache[N][3]; int dp(int idx, int prev) { if (idx >= n) return 0; if (cache[idx][prev] != -1) return cache[idx][prev]; int ans = 0; forn(i, 0, 3) { if (i != prev) ans = max(ans, a[idx][i] + dp(idx + 1, i)); } cache[idx][prev] = ans; return ans; } int32_t main() { IOS INPUT(); cin >> n; memset(cache, -1, sizeof(cache)); forn(i, 0, n) { forn(j, 0, 3) cin >> a[i][j]; } int ans = 0; forn(i, 0, 3) { ans = max(ans, a[0][i] + dp(1, i)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int N = 1e5 + 5; int a[N][3], n; int cache[N][3]; int dp(int idx, int prev) { if (idx >= n) return 0; if (cache[idx][prev] != -1) return cache[idx][prev]; int ans = 0; forn(i, 0, 3) { if (i != prev) ans = max(ans, a[idx][i] + dp(idx + 1, i)); } cache[idx][prev] = ans; return ans; } int32_t main() { IOS // INPUT(); cin >> n; memset(cache, -1, sizeof(cache)); forn(i, 0, n) { forn(j, 0, 3) cin >> a[i][j]; } int ans = 0; forn(i, 0, 3) { ans = max(ans, a[0][i] + dp(1, i)); } cout << ans << endl; return 0; }
replace
45
47
45
48
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int int n, a[100001], b[100001], c[100001]; ll dp[3][100001]; ll call(int i, int key) { if (dp[key][i]) return dp[key][i]; if (i == n - 1) { if (key == 0) return dp[key][i] = max(b[i], c[i]); else if (key == 1) return dp[key][i] = max(a[i], c[i]); else return dp[key][i] = max(b[i], a[i]); } if (key == 0) return dp[key][i] = max(b[i] + call(i + 1, 1), c[i] + call(i + 1, 2)); else if (key == 1) return dp[key][i] = max(a[i] + call(i + 1, 0), c[i] + call(i + 1, 2)); else return dp[key][i] = max(a[i] + call(i + 1, 0), b[i] + call(i + 1, 1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; cout << max(a[0] + call(1, 0), max(b[0] + call(1, 1), c[0] + call(1, 2))) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int n, a[100001], b[100001], c[100001]; ll dp[3][100001]; ll call(int i, int key) { if (dp[key][i]) return dp[key][i]; if (i > n - 1) return 0; if (i == n - 1) { if (key == 0) return dp[key][i] = max(b[i], c[i]); else if (key == 1) return dp[key][i] = max(a[i], c[i]); else return dp[key][i] = max(b[i], a[i]); } if (key == 0) return dp[key][i] = max(b[i] + call(i + 1, 1), c[i] + call(i + 1, 2)); else if (key == 1) return dp[key][i] = max(a[i] + call(i + 1, 0), c[i] + call(i + 1, 2)); else return dp[key][i] = max(a[i] + call(i + 1, 0), b[i] + call(i + 1, 1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; cout << max(a[0] + call(1, 0), max(b[0] + call(1, 1), c[0] + call(1, 2))) << endl; return 0; }
insert
11
11
11
13
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long add(long long a, long long b) { long long res = a + b; if (res >= mod) res -= mod; return res; } long long sub(long long a, long long b) { long long res = a - b + mod; if (res >= mod) res -= mod; return res; } long long mul(long long a, long long b) { return (((a % mod) * (b % mod)) % mod); } long long gcd(long long x, long long y) { if (y == 0) { return x; } if (x > y) { return gcd(y, x % y); } else { return gcd(x, y % x); } } void dfs(vector<vector<int>> &v, vector<int> &visited, int node, int &ans) { if (visited[node]) { return; } visited[node] = 1; ans++; for (auto i : v[node]) { dfs(v, visited, i, ans); } } /*bool good(vector<int> &v, int d, int mid){ vector<int> p(v.size()); p[0] = v[0] - mid; for(int i = 1;i < v.size();i++){ p[i] = p[i - 1] + (v[i] - mid); } vector<int> m(v.size()); m[0] = p[0]; int mi = m[0]; for(int i = 1;i < v.size();i++){ mi = min(mi, p[i]); m[i] = mi; } for(int r = 0;r < v.size();r++){ if(r - d > 0){ if(m[r - d - 1] <= p[r]){ L = r - d; R = r; return true; } } } return false; }*/ bool comp(pair<int, int> x, pair<int, int> y) { if (x.first < y.first) return true; else if (x.first == y.first) { if (x.second < y.second) return true; else return false; } else { return false; } } long long a[10001], b[10001], c[10001], dp[10001][3]; int main() { 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][1], dp[i - 1][0]) + c[i]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; } /* 5 2 -1 -2 -3 4 5 2 3 4 -3 -2 -1 4 5 2 3 5 + (-3) = 2 4 + -2 = 2 ans = 4 -3 -2 -1 4 5 3 2 5 + -3 = 2 4 + -1 = 3 ans = 5 */
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long add(long long a, long long b) { long long res = a + b; if (res >= mod) res -= mod; return res; } long long sub(long long a, long long b) { long long res = a - b + mod; if (res >= mod) res -= mod; return res; } long long mul(long long a, long long b) { return (((a % mod) * (b % mod)) % mod); } long long gcd(long long x, long long y) { if (y == 0) { return x; } if (x > y) { return gcd(y, x % y); } else { return gcd(x, y % x); } } void dfs(vector<vector<int>> &v, vector<int> &visited, int node, int &ans) { if (visited[node]) { return; } visited[node] = 1; ans++; for (auto i : v[node]) { dfs(v, visited, i, ans); } } /*bool good(vector<int> &v, int d, int mid){ vector<int> p(v.size()); p[0] = v[0] - mid; for(int i = 1;i < v.size();i++){ p[i] = p[i - 1] + (v[i] - mid); } vector<int> m(v.size()); m[0] = p[0]; int mi = m[0]; for(int i = 1;i < v.size();i++){ mi = min(mi, p[i]); m[i] = mi; } for(int r = 0;r < v.size();r++){ if(r - d > 0){ if(m[r - d - 1] <= p[r]){ L = r - d; R = r; return true; } } } return false; }*/ bool comp(pair<int, int> x, pair<int, int> y) { if (x.first < y.first) return true; else if (x.first == y.first) { if (x.second < y.second) return true; else return false; } else { return false; } } long long a[100001], b[100001], c[100001], dp[100001][3]; int main() { 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][1], dp[i - 1][0]) + c[i]; } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; } /* 5 2 -1 -2 -3 4 5 2 3 4 -3 -2 -1 4 5 2 3 5 + (-3) = 2 4 + -2 = 2 ans = 4 -3 -2 -1 4 5 3 2 5 + -3 = 2 4 + -1 = 3 ans = 5 */
replace
84
85
84
85
0
p03162
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; long long dp[10010][3]; long long a[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; } dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]); } } } long long Ans = 0; for (int i = 0; i < 3; i++) { Ans = max(Ans, dp[N][i]); } cout << Ans << endl; }
#include <algorithm> #include <iostream> using namespace std; long long dp[100100][3]; long long a[100100][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; } dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]); } } } long long Ans = 0; for (int i = 0; i < 3; i++) { Ans = max(Ans, dp[N][i]); } cout << Ans << endl; }
replace
6
8
6
8
0
p03162
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; const int MAXN = 1e5; const int INF = 1e9 - 7; typedef long long ll; ll dp[MAXN][4]; int n; vector<ll> a, b, c; ll happy(ll N, ll K) { if (N == 0) return 0; if (dp[N][K] != -1) return dp[N][K]; if (K == 3) return dp[N][K] = max(happy(N - 1, 2) + b[N], happy(N - 1, 1) + a[N]); if (K == 2) return dp[N][K] = max(happy(N - 1, 1) + a[N], happy(N - 1, 3) + c[N]); if (K == 1) return dp[N][K] = max(happy(N - 1, 2) + b[N], happy(N - 1, 3) + c[N]); if (K == 0) return dp[N][K] = max(happy(N - 1, 1) + a[N], max(happy(N - 1, 2) + b[N], happy(N - 1, 3) + c[N])); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a = vector<ll>(n + 1); b = vector<ll>(n + 1); c = vector<ll>(n + 1); for (int i = 0; i <= n; i++) for (int j = 0; j <= 3; j++) dp[i][j] = -1; a[0] = INF; b[0] = INF; c[0] = INF; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << happy(n, 0) << "\n"; return 0; }
#include <iostream> #include <vector> using namespace std; const int MAXN = 1e5; const int INF = 1e9 - 7; typedef long long ll; ll dp[MAXN + 2][4]; int n; vector<ll> a, b, c; ll happy(ll N, ll K) { if (N == 0) return 0; if (dp[N][K] != -1) return dp[N][K]; if (K == 3) return dp[N][K] = max(happy(N - 1, 2) + b[N], happy(N - 1, 1) + a[N]); if (K == 2) return dp[N][K] = max(happy(N - 1, 1) + a[N], happy(N - 1, 3) + c[N]); if (K == 1) return dp[N][K] = max(happy(N - 1, 2) + b[N], happy(N - 1, 3) + c[N]); if (K == 0) return dp[N][K] = max(happy(N - 1, 1) + a[N], max(happy(N - 1, 2) + b[N], happy(N - 1, 3) + c[N])); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a = vector<ll>(n + 1); b = vector<ll>(n + 1); c = vector<ll>(n + 1); for (int i = 0; i <= n; i++) for (int j = 0; j <= 3; j++) dp[i][j] = -1; a[0] = INF; b[0] = INF; c[0] = INF; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << happy(n, 0) << "\n"; return 0; }
replace
7
8
7
8
0
p03162
C++
Time Limit Exceeded
// #include <bits/stdc++.h> #include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; typedef vector<VI> VVI; // 例: VVI dp(10, vector<int>(10, INF); typedef priority_queue<int, vector<int>, less<int>> QUE_int; const int INF = 2 * pow(10, 9) + 1; //+1しないとREになるかも(out of rangeになるんかな?? ) vector<int> dx = {-1, 0, 1, 0, -1, -1, 1, 1}; vector<int> dy = {0, -1, 0, 1, -1, 1, -1, 1}; int main(void) { int N; cin >> N; vector<int> a(N), b(N), c(N); for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } VVI act(N, vector<int>(3)); for (int i = 0; i < N; i++) { act[i][0] = a[i]; act[i][1] = b[i]; act[i][2] = c[i]; } VVI dp(N + 1, vector<int>(3 + 1, -1)); // dp[i][j]:i日目にjをした時の最大幸福値 dp[0][0] = act[0][0]; dp[0][1] = act[0][1]; dp[0][2] = act[0][2]; for (int i = 1; i < N; i++) { for (int j = 0; j < N; j++) { int act0 = j % 3; int act1 = (j + 1) % 3; // int act2 = (j + 2) % 3; dp[i][act0] = max(dp[i - 1][act1], dp[i - 1][act2]) + act[i][act0]; } } int ans = max(dp[N - 1][0], dp[N - 1][1]); ans = max(ans, dp[N - 1][2]); cout << ans << endl; }
// #include <bits/stdc++.h> #include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; typedef vector<VI> VVI; // 例: VVI dp(10, vector<int>(10, INF); typedef priority_queue<int, vector<int>, less<int>> QUE_int; const int INF = 2 * pow(10, 9) + 1; //+1しないとREになるかも(out of rangeになるんかな?? ) vector<int> dx = {-1, 0, 1, 0, -1, -1, 1, 1}; vector<int> dy = {0, -1, 0, 1, -1, 1, -1, 1}; int main(void) { int N; cin >> N; vector<int> a(N), b(N), c(N); for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } VVI act(N, vector<int>(3)); for (int i = 0; i < N; i++) { act[i][0] = a[i]; act[i][1] = b[i]; act[i][2] = c[i]; } VVI dp(N + 1, vector<int>(3 + 1, -1)); // dp[i][j]:i日目にjをした時の最大幸福値 dp[0][0] = act[0][0]; dp[0][1] = act[0][1]; dp[0][2] = act[0][2]; for (int i = 1; i < N; i++) { for (int j = 0; j < 3; j++) { int act0 = j % 3; int act1 = (j + 1) % 3; // int act2 = (j + 2) % 3; dp[i][act0] = max(dp[i - 1][act1], dp[i - 1][act2]) + act[i][act0]; } } int ans = max(dp[N - 1][0], dp[N - 1][1]); ans = max(ans, dp[N - 1][2]); cout << ans << endl; }
replace
35
36
35
36
TLE
p03162
C++
Runtime Error
// // main.cpp // C - Vacation // // Created by Hashizo on 2019/06/12. // #include <algorithm> #include <iostream> #include <regex> #include <string> #include <vector> using namespace std; #undef INT_MAX #undef INT_MIN #define INT_MAX 2147483647 #define INT_MIN (-INT_MAX - 1) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define REPLACE(s, f, t) regex_replace(s, regex(f), t) int main(int argc, const char *argv[]) { int n; cin >> n; int activity[4][3]; int dp[4 + 1][3]; REP(i, n) { REP(j, 3) { cin >> activity[i][j]; } } REP(j, 3) { dp[0][j] = 0; } REP(i, n) { dp[i + 1][0] = activity[i][0] + max(dp[i][1], dp[i][2]); dp[i + 1][1] = activity[i][1] + max(dp[i][0], dp[i][2]); dp[i + 1][2] = activity[i][2] + max(dp[i][0], dp[i][1]); // dp[i+1][0] = dp[i][0] + max(activity[i][1], activity[i][2]); // dp[i+1][1] = dp[i][1] + max(activity[i][0], activity[i][2]); // dp[i+1][2] = dp[i][2] + max(activity[i][0], activity[i][1]); } int res = 0; REP(j, 3) { res = max(dp[n][j], res); } cout << res << endl; return 0; }
// // main.cpp // C - Vacation // // Created by Hashizo on 2019/06/12. // #include <algorithm> #include <iostream> #include <regex> #include <string> #include <vector> using namespace std; #undef INT_MAX #undef INT_MIN #define INT_MAX 2147483647 #define INT_MIN (-INT_MAX - 1) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define REPLACE(s, f, t) regex_replace(s, regex(f), t) int main(int argc, const char *argv[]) { int n; cin >> n; int activity[n][3]; int dp[n + 1][3]; REP(i, n) { REP(j, 3) { cin >> activity[i][j]; } } REP(j, 3) { dp[0][j] = 0; } REP(i, n) { dp[i + 1][0] = activity[i][0] + max(dp[i][1], dp[i][2]); dp[i + 1][1] = activity[i][1] + max(dp[i][0], dp[i][2]); dp[i + 1][2] = activity[i][2] + max(dp[i][0], dp[i][1]); // dp[i+1][0] = dp[i][0] + max(activity[i][1], activity[i][2]); // dp[i+1][1] = dp[i][1] + max(activity[i][0], activity[i][2]); // dp[i+1][2] = dp[i][2] + max(activity[i][0], activity[i][1]); } int res = 0; REP(j, 3) { res = max(dp[n][j], res); } cout << res << endl; return 0; }
replace
30
32
30
32
0
p03162
C++
Time Limit Exceeded
#define nl "\n" #define ll long long #define ull unsigned long long #define pb push_back #define SIZE(a) (int)a.size() #define SORT(v) sort(v.begin(), v.end()) #define RSORT(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ff first #define ss second #define sq(a) ((a) * (a)) #define For(i, a, b) for (i = a; i <= b; i++) #define Rof(i, a, b) for (i = a; i >= b; i--) #define Rep(i, b) for (i = 0; i < b; i++) #define MOD 1000000007 #define PI acos(-1.0) #define eps 1e-9 #define Linf 2e18 #define inf 1 << 30 #define MX5 100005 #define MX6 1000006 #define MX3 1005 #define GCD(a, b) __gcd(a, b) #define Abs(a) abs(a) #define input(a, b) scanf("%lld%lld", &a, &b) #define in1(a) scanf("%I64d", &a) #define output(a) printf("%lld\n", a); #define mem(a) memset(a, -1, sizeof(a)) // complexity O(n) #define clr(a) memset(a, 0, sizeof(a)) #define mk make_pair #define pLL pair<ll, ll> #define invcos(a) (acos(a) * (180 / 3.14159265)) #define rtan(a) (tan(a * 3.14159265 / 180.0)) #define pip printf("pip") #define Case(x) printf("Case %lld: ", x) #define timelimit 1.0 * clock() / CLOCKS_PER_SEC #define pc_one __builtin_popcount #define pcl_one __builtin_popcountl #define pcll_one __builtin_popcountll #define parity __builtin_parity #define parityl __builtin_parityl #define parityll __builtin_parityll #define infile freopen("input.txt", "r", stdin) #define outfile freopen("output.txt", "w", stdout) #define debug(x) cerr << #x << " is " << x << endl #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); // const ll Linf=2e18; /// 4direction -> int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1}; /// 8direction -> int /// del_x[]={-1,0,1,0,1,-1,-1,1},del_y[]={0,1,0,-1,-1,-1,1,1}; #include <bits/stdc++.h> #include <iomanip> using namespace std; ll bigmod(ll n, ll p) { if (p == 0) return 1; if (p == 1) return (n + MOD) % MOD; if (p % 2) return (bigmod(n, p - 1) * n + MOD) % MOD; else { ll x = bigmod(n, p / 2); return (x * x + MOD) % MOD; } } ll modinverse(ll n) { return bigmod(n, MOD - 2) % MOD; } bool check_2s_power(ll a) { return (pcll_one(a) == 1 ? true : false); } /*----------------------Graph Moves----------------*/ // const int fx[]={+1,-1,+0,+0}; // const int fy[]={+0,+0,+1,-1}; // const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move // const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move // const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move // const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ ll dp[MX5][3]; int main() { ll n, i, j, k, a; in1(n); For(i, 1, n) { Rep(j, 3) { in1(dp[i][j]); } } ll ans = 0; For(i, 1, n) { Rep(j, 3) { ll maxi = 0; For(k, 1, 2) { a = (j + k) % 3; maxi = max(maxi, dp[i - 1][a]); } dp[i][j] += maxi; ans = max(ans, dp[i][j]); } } output(ans); }
#define nl "\n" #define ll long long #define ull unsigned long long #define pb push_back #define SIZE(a) (int)a.size() #define SORT(v) sort(v.begin(), v.end()) #define RSORT(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ff first #define ss second #define sq(a) ((a) * (a)) #define For(i, a, b) for (i = a; i <= b; i++) #define Rof(i, a, b) for (i = a; i >= b; i--) #define Rep(i, b) for (i = 0; i < b; i++) #define MOD 1000000007 #define PI acos(-1.0) #define eps 1e-9 #define Linf 2e18 #define inf 1 << 30 #define MX5 100005 #define MX6 1000006 #define MX3 1005 #define GCD(a, b) __gcd(a, b) #define Abs(a) abs(a) #define input(a, b) scanf("%lld%lld", &a, &b) #define in1(a) scanf("%lld", &a) #define output(a) printf("%lld\n", a); #define mem(a) memset(a, -1, sizeof(a)) // complexity O(n) #define clr(a) memset(a, 0, sizeof(a)) #define mk make_pair #define pLL pair<ll, ll> #define invcos(a) (acos(a) * (180 / 3.14159265)) #define rtan(a) (tan(a * 3.14159265 / 180.0)) #define pip printf("pip") #define Case(x) printf("Case %lld: ", x) #define timelimit 1.0 * clock() / CLOCKS_PER_SEC #define pc_one __builtin_popcount #define pcl_one __builtin_popcountl #define pcll_one __builtin_popcountll #define parity __builtin_parity #define parityl __builtin_parityl #define parityll __builtin_parityll #define infile freopen("input.txt", "r", stdin) #define outfile freopen("output.txt", "w", stdout) #define debug(x) cerr << #x << " is " << x << endl #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); // const ll Linf=2e18; /// 4direction -> int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1}; /// 8direction -> int /// del_x[]={-1,0,1,0,1,-1,-1,1},del_y[]={0,1,0,-1,-1,-1,1,1}; #include <bits/stdc++.h> #include <iomanip> using namespace std; ll bigmod(ll n, ll p) { if (p == 0) return 1; if (p == 1) return (n + MOD) % MOD; if (p % 2) return (bigmod(n, p - 1) * n + MOD) % MOD; else { ll x = bigmod(n, p / 2); return (x * x + MOD) % MOD; } } ll modinverse(ll n) { return bigmod(n, MOD - 2) % MOD; } bool check_2s_power(ll a) { return (pcll_one(a) == 1 ? true : false); } /*----------------------Graph Moves----------------*/ // const int fx[]={+1,-1,+0,+0}; // const int fy[]={+0,+0,+1,-1}; // const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move // const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move // const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move // const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*------------------------------------------------*/ ll dp[MX5][3]; int main() { ll n, i, j, k, a; in1(n); For(i, 1, n) { Rep(j, 3) { in1(dp[i][j]); } } ll ans = 0; For(i, 1, n) { Rep(j, 3) { ll maxi = 0; For(k, 1, 2) { a = (j + k) % 3; maxi = max(maxi, dp[i - 1][a]); } dp[i][j] += maxi; ans = max(ans, dp[i][j]); } } output(ans); }
replace
25
26
25
26
TLE
p03162
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<int>> dp(n, vector<int>(3)); for (int &i : dp.at(0)) { cin >> i; } for (int i = 1; i < n; ++i) { for (int &i : dp.at(i)) { cin >> i; } dp.at(i).at(0) += max(dp.at(i - 1).at(1), dp.at(i - 1).at(2)); dp.at(i).at(1) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(2)); dp.at(i).at(2) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(1)); } cout << *max_element(dp.back().begin(), dp.back().end()); return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<int>> dp(n, vector<int>(3)); for (int &i : dp.at(0)) { cin >> i; } for (int i = 1; i < n; ++i) { for (int &j : dp.at(i)) { cin >> j; } dp.at(i).at(0) += max(dp.at(i - 1).at(1), dp.at(i - 1).at(2)); dp.at(i).at(1) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(2)); dp.at(i).at(2) += max(dp.at(i - 1).at(0), dp.at(i - 1).at(1)); } cout << *max_element(dp.back().begin(), dp.back().end()); return 0; }
replace
15
17
15
17
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const double EPS = 1e-8; const double PI = acos(-1.0); #define inf INT_MAX ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } struct hap { int a; int b; int c; }; int a[100005][3]; // dont ; int n; int dp[100005][4]; int sol(int ind, int l) { if (ind >= n) return 0; int &res = dp[ind][l]; for (int i = 0; i < 3; i++) { if (l != i) { res = max(res, sol(ind + 1, i) + a[ind][i]); } } return res; } int main() { cin >> n; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; a[i][0] = x; a[i][1] = y; a[i][2] = z; } memset(dp, -1, sizeof(dp)); int ans = sol(0, 3); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const double EPS = 1e-8; const double PI = acos(-1.0); #define inf INT_MAX ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } struct hap { int a; int b; int c; }; int a[100005][3]; // dont ; int n; int dp[100005][4]; int sol(int ind, int l) { if (ind >= n) return 0; int &res = dp[ind][l]; if (res != -1) return res; for (int i = 0; i < 3; i++) { if (l != i) { res = max(res, sol(ind + 1, i) + a[ind][i]); } } return res; } int main() { cin >> n; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; a[i][0] = x; a[i][1] = y; a[i][2] = z; } memset(dp, -1, sizeof(dp)); int ans = sol(0, 3); cout << ans << endl; return 0; }
insert
29
29
29
31
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ll long long #define pb push_back #define F first #define S second #define ld long double #define vi vector<ll> const int INF = 1e9; const int N = 100005; vi dp(3); void solve() { ll n; cin >> n; for (ll day = 0; day < n; day++) { vi dp1(3); vi a(3); for (ll i = 0; i < 3; i++) cin >> a[i]; for (ll i = 0; i < 3; i++) { for (ll j = 0; j < 3; j++) { if (i != j) { dp1[j] = max(dp1[j], dp[i] + a[j]); } } } dp = dp1; } cout << max({dp[0], dp[1], dp[2]}); } int main() { FASTIO; #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ll long long #define pb push_back #define F first #define S second #define ld long double #define vi vector<ll> const int INF = 1e9; const int N = 100005; vi dp(3); void solve() { ll n; cin >> n; for (ll day = 0; day < n; day++) { vi dp1(3); vi a(3); for (ll i = 0; i < 3; i++) cin >> a[i]; for (ll i = 0; i < 3; i++) { for (ll j = 0; j < 3; j++) { if (i != j) { dp1[j] = max(dp1[j], dp[i] + a[j]); } } } dp = dp1; } cout << max({dp[0], dp[1], dp[2]}); } int main() { FASTIO; /* #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif */ int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
37
45
37
45
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pi; typedef long long ll; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i <= b; i++) vector<vector<ll>> dp; int main() { ll n, a, b, c; cin >> n; dp.assign(n + 5, vector<ll>(3, 0)); for (ll i = 0; i < n; i++) { dp[0][i] = 0; dp[1][i] = 0; dp[2][i] = 0; } cin >> a >> b >> c; dp[0][0] = a; dp[1][0] = b; dp[2][0] = c; n--; for (ll i = 1; i <= n; i++) { cin >> a >> b >> c; dp[0][i] = max(dp[0][i], max(dp[1][i - 1], dp[2][i - 1]) + a); dp[1][i] = max(dp[1][i], max(dp[0][i - 1], dp[2][i - 1]) + b); dp[2][i] = max(dp[2][i], max(dp[0][i - 1], dp[1][i - 1]) + c); } ll maxi = 0; maxi = max(maxi, dp[0][n]); maxi = max(maxi, dp[1][n]); maxi = max(maxi, dp[2][n]); cout << maxi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pi; typedef long long ll; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i <= b; i++) vector<vector<ll>> dp; int main() { ll n, a, b, c; cin >> n; dp.assign(3, vector<ll>(n + 1, 0)); cin >> a >> b >> c; dp[0][0] = a; dp[1][0] = b; dp[2][0] = c; n--; for (ll i = 1; i <= n; i++) { cin >> a >> b >> c; dp[0][i] = max(dp[0][i], max(dp[1][i - 1], dp[2][i - 1]) + a); dp[1][i] = max(dp[1][i], max(dp[0][i - 1], dp[2][i - 1]) + b); dp[2][i] = max(dp[2][i], max(dp[0][i - 1], dp[1][i - 1]) + c); } ll maxi = 0; maxi = max(maxi, dp[0][n]); maxi = max(maxi, dp[1][n]); maxi = max(maxi, dp[2][n]); cout << maxi << endl; return 0; }
replace
20
27
20
21
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define loop(i, a, b) for (ll i = a; i < b; i++) #define loope(i, a, b) for (ll i = a; i <= b; i++) #define test() \ ull t; \ cin >> t; \ while (t--) #define puu pair<ull, ull> #define f first #define s second #define pb push_back #define mkp make_pair #define ins insert #define Vint vector<int> #define Vll vector<ll> #define Vull vector<ull> #define nl cout << endl #define sp cout << " " #define MOD 1000000007 #define all(x) x.begin(), x.end() int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); ll n; cin >> n; ll v[n][3]; loop(i, 0, n) { loop(j, 0, 3) cin >> v[i][j]; } vector<vector<ll>> dp(n, vector<ll>(3, 0)); dp[0][0] = v[0][0]; dp[0][1] = v[0][1]; dp[0][2] = v[0][2]; loop(i, 1, n) { loop(j, 0, 3) dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + v[i][j]; } ll ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define loop(i, a, b) for (ll i = a; i < b; i++) #define loope(i, a, b) for (ll i = a; i <= b; i++) #define test() \ ull t; \ cin >> t; \ while (t--) #define puu pair<ull, ull> #define f first #define s second #define pb push_back #define mkp make_pair #define ins insert #define Vint vector<int> #define Vll vector<ll> #define Vull vector<ull> #define nl cout << endl #define sp cout << " " #define MOD 1000000007 #define all(x) x.begin(), x.end() int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif // fastio(); ll n; cin >> n; ll v[n][3]; loop(i, 0, n) { loop(j, 0, 3) cin >> v[i][j]; } vector<vector<ll>> dp(n, vector<ll>(3, 0)); dp[0][0] = v[0][0]; dp[0][1] = v[0][1]; dp[0][2] = v[0][2]; loop(i, 1, n) { loop(j, 0, 3) dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + v[i][j]; } ll ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); cout << ans; }
replace
29
34
29
34
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int dp[1000][3]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { vector<int> v(3); for (int j = 0; j < 3; j++) cin >> v[j]; dp[i][0] = v[0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = v[1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = v[2] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max({dp[n][0], dp[n][1], dp[n][2]}); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int dp[100007][3]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { vector<int> v(3); for (int j = 0; j < 3; j++) cin >> v[j]; dp[i][0] = v[0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = v[1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = v[2] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max({dp[n][0], dp[n][1], dp[n][2]}); }
replace
4
5
4
5
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define all(x) (x).begin(), (x).end() #define F first #define S second #define pb push_back #define pp pair<int, int> #define rep(i, l, r) for (int i = l; i < r; i++) int main() { #ifndef ONLINE_JUDGE freopen("input.txt.txt", "r", stdin); freopen("output.txt.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n), b(n), c(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i]; int dp[n][3]; rep(i, 0, n) { if (i == 0) { dp[i][0] = a[i], dp[i][1] = b[i], dp[i][2] = c[i]; } else { 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 << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define all(x) (x).begin(), (x).end() #define F first #define S second #define pb push_back #define pp pair<int, int> #define rep(i, l, r) for (int i = l; i < r; i++) int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt.txt","r",stdin); // freopen("output.txt.txt","w",stdout); // #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n), b(n), c(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i]; int dp[n][3]; rep(i, 0, n) { if (i == 0) { dp[i][0] = a[i], dp[i][1] = b[i], dp[i][2] = c[i]; } else { 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 << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); }
replace
10
14
10
14
0
p03162
C++
Runtime Error
// // main.cpp // test130 // // Created by on 2019/06/16. // Copyright © 2 All rights reserved. // // // main.cpp // new // // Created on 2019/06/09. // Copyright All rights reserved. // // C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2013 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif #define f(i, n) for (int i = 0; i < (n); i++) #define int long long using namespace std; int n, h[11004][4], dp[11004][3], k; signed main() { cin >> n; for (int i = 0; i < n; i++) { cin >> h[i][0]; cin >> h[i][1]; cin >> h[i][2]; } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j != k) { dp[i + 1][j] = max(dp[i][k] + h[i][k], dp[i + 1][j]); } } } } int ans = max(dp[n][0], max(dp[n][1], dp[n][2])); cout << ans << endl; }
// // main.cpp // test130 // // Created by on 2019/06/16. // Copyright © 2 All rights reserved. // // // main.cpp // new // // Created on 2019/06/09. // Copyright All rights reserved. // // C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2013 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif #define f(i, n) for (int i = 0; i < (n); i++) #define int long long using namespace std; int n, h[110040][4], dp[110040][3], k; signed main() { cin >> n; for (int i = 0; i < n; i++) { cin >> h[i][0]; cin >> h[i][1]; cin >> h[i][2]; } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j != k) { dp[i + 1][j] = max(dp[i][k] + h[i][k], dp[i + 1][j]); } } } } int ans = max(dp[n][0], max(dp[n][1], dp[n][2])); cout << ans << endl; }
replace
137
138
137
138
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<vector<int>> vvi; #define ff first #define ss second #define pb push_back #define mp make_pair #define rep(i, a, b) for (int i = a; i <= b; i++) const int INF = INT_MAX; int fact[9]; int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; int **dp = new int *[3]; rep(i, 0, 2) dp[i] = new int[n + 1]; dp[0][0] = 0; dp[1][0] = 0; dp[2][0] = 0; rep(day, 1, n) { rep(i, 0, 2) { int x; cin >> x; if (i == 0) dp[0][day] = x + max(dp[1][day - 1], dp[2][day - 1]); else if (i == 1) dp[1][day] = x + max(dp[0][day - 1], dp[2][day - 1]); else dp[2][day] = x + max(dp[0][day - 1], dp[1][day - 1]); } } int ans = dp[0][n]; rep(i, 1, 2) ans = max(ans, dp[i][n]); cout << ans; rep(i, 0, 2) delete[] dp[i]; delete[] dp; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<vector<int>> vvi; #define ff first #define ss second #define pb push_back #define mp make_pair #define rep(i, a, b) for (int i = a; i <= b; i++) const int INF = INT_MAX; int fact[9]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int **dp = new int *[3]; rep(i, 0, 2) dp[i] = new int[n + 1]; dp[0][0] = 0; dp[1][0] = 0; dp[2][0] = 0; rep(day, 1, n) { rep(i, 0, 2) { int x; cin >> x; if (i == 0) dp[0][day] = x + max(dp[1][day - 1], dp[2][day - 1]); else if (i == 1) dp[1][day] = x + max(dp[0][day - 1], dp[2][day - 1]); else dp[2][day] = x + max(dp[0][day - 1], dp[1][day - 1]); } } int ans = dp[0][n]; rep(i, 1, 2) ans = max(ans, dp[i][n]); cout << ans; rep(i, 0, 2) delete[] dp[i]; delete[] dp; return 0; }
delete
20
25
20
20
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 REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) typedef long long LL; typedef pair<int, int> pii; const int INTINF = 1e9; const LL LLINF = 1e18; const int dg5 = 1e5; // dp[j][i] : i 日目に j を選ぶとしたときの最大幸福度 LL dp[2][dg5 + 1]; LL abc[2][dg5 + 1]; void solve() { int N; cin >> N; REP0(i, N) { cin >> abc[0][i] >> abc[1][i] >> abc[2][i]; } REP0(i, 3) { dp[i][0] = abc[i][0]; } REP1(i, N - 1) { REP0(j, 3) { dp[j][i] = max(dp[(j + 1) % 3][i - 1] + abc[j][i], dp[(j + 2) % 3][i - 1] + abc[j][i]); } } LL ans = 0; REP0(i, 3) { ans = max(ans, dp[i][N - 1]); } cout << ans << endl; } int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); solve(); return 0; }
#include "bits/stdc++.h" using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) typedef long long LL; typedef pair<int, int> pii; const int INTINF = 1e9; const LL LLINF = 1e18; const int dg5 = 1e5; // dp[j][i] : i 日目に j を選ぶとしたときの最大幸福度 LL dp[3][dg5 + 1]; LL abc[3][dg5 + 1]; void solve() { int N; cin >> N; REP0(i, N) { cin >> abc[0][i] >> abc[1][i] >> abc[2][i]; } REP0(i, 3) { dp[i][0] = abc[i][0]; } REP1(i, N - 1) { REP0(j, 3) { dp[j][i] = max(dp[(j + 1) % 3][i - 1] + abc[j][i], dp[(j + 2) % 3][i - 1] + abc[j][i]); } } LL ans = 0; REP0(i, 3) { ans = max(ans, dp[i][N - 1]); } cout << ans << endl; } int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); solve(); return 0; }
replace
15
17
15
17
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define MAX 1005 #define xx first #define yy second #define pb push_back #define mp make_pair #define ull long long #define FOR(i, a, b) for (int i = a; i <= b; i++) #define nl '\n' #define zai << ' ' << #define all(a) a.begin(), a.end() typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; int a[MAX], b[MAX], c[MAX], n; int dp[MAX][5]; bool vis[MAX][5]; // 0-A // 1-B // 2-C int solve(int i, int last) { if (i == n) return 0; if (vis[i][last]) return dp[i][last]; vis[i][last] = 1; int ans = 0; for (int j = 0; j < 3; j++) { if (j != last) { if (j == 0) { ans = max(ans, a[i] + solve(i + 1, j)); } if (j == 1) { ans = max(ans, b[i] + solve(i + 1, j)); } if (j == 2) { ans = max(ans, c[i] + solve(i + 1, j)); } } } return dp[i][last] = ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << solve(0, -1); }
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define MAX 100005 #define xx first #define yy second #define pb push_back #define mp make_pair #define ull long long #define FOR(i, a, b) for (int i = a; i <= b; i++) #define nl '\n' #define zai << ' ' << #define all(a) a.begin(), a.end() typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; int a[MAX], b[MAX], c[MAX], n; int dp[MAX][5]; bool vis[MAX][5]; // 0-A // 1-B // 2-C int solve(int i, int last) { if (i == n) return 0; if (vis[i][last]) return dp[i][last]; vis[i][last] = 1; int ans = 0; for (int j = 0; j < 3; j++) { if (j != last) { if (j == 0) { ans = max(ans, a[i] + solve(i + 1, j)); } if (j == 1) { ans = max(ans, b[i] + solve(i + 1, j)); } if (j == 2) { ans = max(ans, c[i] + solve(i + 1, j)); } } } return dp[i][last] = ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << solve(0, -1); }
replace
4
5
4
5
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 inf = 1001001001; int main() { int n; cin >> n; vector<vector<int>> h(n, vector<int>(3)); rep(i, n) { rep(j, 3) { cin >> h.at(i).at(j); } } vector<vector<int>> dp(n, vector<int>(3, 0)); rep(i, n) { if (i == 0) { rep(l, n) { dp.at(0).at(l) = h.at(0).at(l); } continue; } rep(j, 3) { rep(k, 3) { if (k != j) { dp.at(i).at(j) = max(dp.at(i).at(j), dp.at(i - 1).at(k) + h.at(i).at(j)); } } } } int ans = 0; rep(i, 3) { ans = max(ans, dp.at(n - 1).at(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 inf = 1001001001; int main() { int n; cin >> n; vector<vector<int>> h(n, vector<int>(3)); rep(i, n) { rep(j, 3) { cin >> h.at(i).at(j); } } vector<vector<int>> dp(n, vector<int>(3, 0)); rep(i, n) { if (i == 0) { rep(l, 3) { dp.at(0).at(l) = h.at(0).at(l); } continue; } rep(j, 3) { rep(k, 3) { if (k != j) { dp.at(i).at(j) = max(dp.at(i).at(j), dp.at(i - 1).at(k) + h.at(i).at(j)); } } } } int ans = 0; rep(i, 3) { ans = max(ans, dp.at(n - 1).at(i)); } cout << ans << endl; }
replace
19
20
19
20
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define For(i, m, n) for (int i = m; i < n; i++) #define FOR(i, n) for (int i = 0; i < n; i++) #define ll long long #define ull unsigned long long #define lli long long int #define pb push_back ll mob = 1000000007; using namespace std; ll dp[11000][3]; int main() { int n; std::cin >> n; int a[n][3]; FOR(i, n) { FOR(j, 3) { cin >> a[i][j]; } } FOR(i, n) { FOR(j, 3) { if (i == 0) { dp[i][j] = a[i][j]; } else { FOR(k, 3) { if (j == k) continue; dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]); } } } } ll u = 0; if (u < dp[n - 1][0]) u = dp[n - 1][0]; if (u < dp[n - 1][1]) u = dp[n - 1][1]; if (u < dp[n - 1][2]) u = dp[n - 1][2]; cout << u; return 0; }
#include <bits/stdc++.h> using namespace std; #define For(i, m, n) for (int i = m; i < n; i++) #define FOR(i, n) for (int i = 0; i < n; i++) #define ll long long #define ull unsigned long long #define lli long long int #define pb push_back ll mob = 1000000007; using namespace std; ll dp[1000000][3]; int main() { int n; std::cin >> n; int a[n][3]; FOR(i, n) { FOR(j, 3) { cin >> a[i][j]; } } FOR(i, n) { FOR(j, 3) { if (i == 0) { dp[i][j] = a[i][j]; } else { FOR(k, 3) { if (j == k) continue; dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]); } } } } ll u = 0; if (u < dp[n - 1][0]) u = dp[n - 1][0]; if (u < dp[n - 1][1]) u = dp[n - 1][1]; if (u < dp[n - 1][2]) u = dp[n - 1][2]; cout << u; return 0; }
replace
10
11
10
11
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Pair = pair<int, int>; using Graph = vector<vector<int>>; #define MOD 1000000007 #define INF 1000000007 #define SEP " " int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } vector<vector<int>> dp(n, vector<int>(n)); 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] + 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 << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Pair = pair<int, int>; using Graph = vector<vector<int>>; #define MOD 1000000007 #define INF 1000000007 #define SEP " " int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } vector<vector<int>> dp(n, vector<int>(3)); 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] + 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 << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; }
replace
17
18
17
18
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair ll mod = 1e9 + 7; ll a[200005]; ll b[200005]; ll idx[100005][2]; // ll cnt[200005]; ll pre[200005]; // ll end[200005]; map<ll, ll> m; bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.fi - a.se) > (b.fi - b.se); } bool revcomp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.fi) > (b.fi); } ll ceil1(ll a, ll b) { if (a % b != 0) return a / b + 1; else return a / b; } ll power(ll a, ll b, ll n) { ll ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % n; a = (a * a) % n; b /= 2; } return ans; } ll count1 = 0; ll gcd(ll a, ll b) { // if(a<b)swap(a,b); if (b == 0) return a; return gcd(b, a % b); } ll primepos(ll fact, ll p) { ll res = 0; while (fact > 0) { res += fact / p; fact /= p; } return res; } // void dfs(ll n, ll p){ // if(vis[n]!=0){ // return; // } // else{ // vis[n]=1; // b[n]=p; // for(int i=0;i<v[n].size();i++){ // dfs(v[n][i],p); // } // } // } int main() { ios::sync_with_stdio(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; cin >> n; int a[n + 1]; int b[n + 1]; int c[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; cin >> c[i]; } int dp[n + 1][3]; memset(dp, 0, sizeof dp); for (int i = 0; i < n; i++) { if (i == 0) { dp[i][0] = a[0]; dp[i][1] = b[0]; dp[i][2] = c[0]; continue; } 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])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair ll mod = 1e9 + 7; ll a[200005]; ll b[200005]; ll idx[100005][2]; // ll cnt[200005]; ll pre[200005]; // ll end[200005]; map<ll, ll> m; bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.fi - a.se) > (b.fi - b.se); } bool revcomp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.fi) > (b.fi); } ll ceil1(ll a, ll b) { if (a % b != 0) return a / b + 1; else return a / b; } ll power(ll a, ll b, ll n) { ll ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % n; a = (a * a) % n; b /= 2; } return ans; } ll count1 = 0; ll gcd(ll a, ll b) { // if(a<b)swap(a,b); if (b == 0) return a; return gcd(b, a % b); } ll primepos(ll fact, ll p) { ll res = 0; while (fact > 0) { res += fact / p; fact /= p; } return res; } // void dfs(ll n, ll p){ // if(vis[n]!=0){ // return; // } // else{ // vis[n]=1; // b[n]=p; // for(int i=0;i<v[n].size();i++){ // dfs(v[n][i],p); // } // } // } int main() { ios::sync_with_stdio(0); int n; cin >> n; int a[n + 1]; int b[n + 1]; int c[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; cin >> c[i]; } int dp[n + 1][3]; memset(dp, 0, sizeof dp); for (int i = 0; i < n; i++) { if (i == 0) { dp[i][0] = a[0]; dp[i][1] = b[0]; dp[i][2] = c[0]; continue; } 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])) << endl; return 0; }
delete
80
83
80
80
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; vector<int> a(10000), b(100000), c(100000); vector<vector<int>> dp(3, vector<int>(100000, 0)); cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0]; for (int day = 1; day < n; day++) { dp[0][day] = max(dp[1][day - 1], dp[2][day - 1]) + a[day]; dp[1][day] = max(dp[0][day - 1], dp[2][day - 1]) + b[day]; dp[2][day] = max(dp[0][day - 1], dp[1][day - 1]) + c[day]; } cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; vector<int> a(100000), b(100000), c(100000); vector<vector<int>> dp(3, vector<int>(100000, 0)); cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0]; for (int day = 1; day < n; day++) { dp[0][day] = max(dp[1][day - 1], dp[2][day - 1]) + a[day]; dp[1][day] = max(dp[0][day - 1], dp[2][day - 1]) + b[day]; dp[2][day] = max(dp[0][day - 1], dp[1][day - 1]) + c[day]; } cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl; return 0; }
replace
11
12
11
12
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } const long INF = -(1L << 60); int a[10010][3]; long dp[100010][3]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { scanf("%d", &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 res = 0; for (int i = 0; i < 3; i++) { chmax(res, dp[n][i]); } printf("%ld", res); }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } const long INF = -(1L << 60); int a[100010][3]; long dp[100010][3]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { scanf("%d", &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 res = 0; for (int i = 0; i < 3; i++) { chmax(res, dp[n][i]); } printf("%ld", res); }
replace
13
14
13
14
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<long long>> v(n + 1, vector<long long>(n + 1)), dp(n + 1, vector<long long>(n + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> v[i][j]; } } long long ans = INT_MIN; for (int i = 0; i < 3; i++) { dp[0][i] = v[0][i]; if (dp[0][i] > ans) ans = dp[0][i]; } for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { if (!j) dp[i][j] = max(dp[i - 1][j + 1], dp[i - 1][j + 2]) + v[i][j]; else if (j == 1) dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j + 1]) + v[i][j]; else dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + v[i][j]; if (dp[i][j] > ans) ans = dp[i][j]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<long long>> v(n + 1, vector<long long>(4)), dp(n + 1, vector<long long>(4)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> v[i][j]; } } long long ans = INT_MIN; for (int i = 0; i < 3; i++) { dp[0][i] = v[0][i]; if (dp[0][i] > ans) ans = dp[0][i]; } for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { if (!j) dp[i][j] = max(dp[i - 1][j + 1], dp[i - 1][j + 2]) + v[i][j]; else if (j == 1) dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j + 1]) + v[i][j]; else dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + v[i][j]; if (dp[i][j] > ans) ans = dp[i][j]; } } cout << ans << endl; return 0; }
replace
8
10
8
10
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(x) x.begin(), x.end() using ll = long long; using pii = pair<int, int>; using vi = vector<int>; const int mod = 1e9 + 7; const ll INF = 1e9; const int MAX = 1e5; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; struct edge { int to, cost; }; // 辺 // vector<edge> graph[MAX]; // 隣接リスト // bool visit[MAX]; // 訪問の有無 int n; // 変数 int act[MAX][3]; // i日目の活動がxのとき得る幸福度 int dp[MAX][3]; // i日目に活動xをしたときの幸福度の総和の最大値 int rec(int i, int to) { if (dp[i][to] != 0) return dp[i][to]; if (i == 0) return dp[i][to] = act[i][to]; int r = 0; rep(ye, 3) { if (ye == to) continue; r = max(r, rec(i - 1, ye) + act[i][to]); } return r; } int main() { // input cin >> n; rep(i, n) { rep(j, 3) { cin >> act[i][j]; } } // solve int ans = 0; rep(to, 3) { ans = max(ans, rec(n - 1, to)); } // output cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(x) x.begin(), x.end() using ll = long long; using pii = pair<int, int>; using vi = vector<int>; const int mod = 1e9 + 7; const ll INF = 1e9; const int MAX = 1e5; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; struct edge { int to, cost; }; // 辺 // vector<edge> graph[MAX]; // 隣接リスト // bool visit[MAX]; // 訪問の有無 int n; // 変数 int act[MAX][3]; // i日目の活動がxのとき得る幸福度 int dp[MAX][3]; // i日目に活動xをしたときの幸福度の総和の最大値 int rec(int i, int to) { if (dp[i][to] != 0) return dp[i][to]; if (i == 0) return dp[i][to] = act[i][to]; int r = 0; rep(ye, 3) { if (ye == to) continue; r = max(r, rec(i - 1, ye) + act[i][to]); } return dp[i][to] = r; } int main() { // input cin >> n; rep(i, n) { rep(j, 3) { cin >> act[i][j]; } } // solve int ans = 0; rep(to, 3) { ans = max(ans, rec(n - 1, to)); } // output cout << ans << "\n"; }
replace
38
39
38
39
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define endl '\n' using namespace std; int a[100001][3], dp[100001][3]; int n; int ans = 0; int solve(int i, int j) { if (i == n) return 0; if (j == 0) { return dp[i][j] = max(solve(i + 1, 1) + a[i][1], solve(i + 1, 2) + a[i][2]); } else if (j == 1) { return dp[i][j] = max(solve(i + 1, 0) + a[i][0], solve(i + 1, 2) + a[i][2]); } else if (j == 2) { return dp[i][j] = max(solve(i + 1, 0) + a[i][0], solve(i + 1, 1) + a[i][1]); } return dp[i][j]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; dp[i][j] = -1; } } int ans = max(solve(0, 0), solve(0, 1)); ans = max(ans, solve(0, 2)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; int a[100001][3], dp[100001][3]; int n; int ans = 0; int solve(int i, int j) { if (i == n) return 0; if (dp[i][j] != -1) return dp[i][j]; if (j == 0) { return dp[i][j] = max(solve(i + 1, 1) + a[i][1], solve(i + 1, 2) + a[i][2]); } else if (j == 1) { return dp[i][j] = max(solve(i + 1, 0) + a[i][0], solve(i + 1, 2) + a[i][2]); } else if (j == 2) { return dp[i][j] = max(solve(i + 1, 0) + a[i][0], solve(i + 1, 1) + a[i][1]); } return dp[i][j]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; dp[i][j] = -1; } } int ans = max(solve(0, 0), solve(0, 1)); ans = max(ans, solve(0, 2)); cout << ans << endl; return 0; }
insert
10
10
10
12
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[2][100000]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { cin >> dp[j][i]; } } for (int i = 2; i <= n; i++) { for (int j = 0; j < 3; j++) { dp[j][i] += max(dp[(j + 1) % 3][i - 1], dp[(j + 2) % 3][i - 1]); } } cout << max(dp[0][n], max(dp[1][n], dp[2][n])); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int dp[3][N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { cin >> dp[j][i]; } } for (int i = 2; i <= n; i++) { for (int j = 0; j < 3; j++) { dp[j][i] += max(dp[(j + 1) % 3][i - 1], dp[(j + 2) % 3][i - 1]); } } cout << max(dp[0][n], max(dp[1][n], dp[2][n])); return 0; }
replace
3
4
3
6
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int N; int a[100000], b[10000], c[100000]; int dp[10000][3]; signed main() { 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]); } printf("%d\n", max(max(dp[N - 1][0], dp[N - 1][1]), dp[N - 1][2])); }
#include <bits/stdc++.h> using namespace std; int N; int a[100000], b[100000], c[1000000]; int dp[100000][3]; signed main() { 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]); } printf("%d\n", max(max(dp[N - 1][0], dp[N - 1][1]), dp[N - 1][2])); }
replace
4
6
4
6
0
p03162
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <ccomplex> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <numeric> #include <set> #include <sstream> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; #define rep(i, s, e) for (ll i = s; i < e; i++) #define reft0(i, j) setfill('0') << setw(i) << j template <class T> inline bool chMax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chMin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll N; vector<ll> a; vector<ll> b; vector<ll> c; cin >> N; rep(i, 0, N) { ll tempA, tempB, tempC; cin >> tempA >> tempB >> tempC; a.push_back(tempA); b.push_back(tempB); c.push_back(tempC); } ll ansA[100003]; ll ansB[100003]; ll ansC[100003]; rep(i, 0, 100010) { ansA[i] = 0; ansB[i] = 0; ansC[i] = 0; } ansA[0] = a[0]; ansB[0] = b[0]; ansC[0] = c[0]; rep(idx, 1, N) { chMax(ansA[idx], max(ansB[idx - 1], ansC[idx - 1]) + a[idx]); chMax(ansB[idx], max(ansA[idx - 1], ansC[idx - 1]) + b[idx]); chMax(ansC[idx], max(ansA[idx - 1], ansB[idx - 1]) + c[idx]); } cout << max(ansA[N - 1], max(ansB[N - 1], ansC[N - 1])) << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <ccomplex> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <numeric> #include <set> #include <sstream> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; #define rep(i, s, e) for (ll i = s; i < e; i++) #define reft0(i, j) setfill('0') << setw(i) << j template <class T> inline bool chMax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chMin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll N; vector<ll> a; vector<ll> b; vector<ll> c; cin >> N; rep(i, 0, N) { ll tempA, tempB, tempC; cin >> tempA >> tempB >> tempC; a.push_back(tempA); b.push_back(tempB); c.push_back(tempC); } ll ansA[100003]; ll ansB[100003]; ll ansC[100003]; rep(i, 0, 100003) { ansA[i] = 0; ansB[i] = 0; ansC[i] = 0; } ansA[0] = a[0]; ansB[0] = b[0]; ansC[0] = c[0]; rep(idx, 1, N) { chMax(ansA[idx], max(ansB[idx - 1], ansC[idx - 1]) + a[idx]); chMax(ansB[idx], max(ansA[idx - 1], ansC[idx - 1]) + b[idx]); chMax(ansC[idx], max(ansA[idx - 1], ansB[idx - 1]) + c[idx]); } cout << max(ansA[N - 1], max(ansB[N - 1], ansC[N - 1])) << endl; return 0; }
replace
57
58
57
58
-6
*** stack smashing detected ***: terminated
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n][3]; int x = n; while (n--) cin >> arr[n - x - 1][0] >> arr[n - x - 1][1] >> arr[n - x - 1][2]; int dp[n][3]; dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2]; for (int i = 1; i < n; i++) { int a, b, c; a = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]); b = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]); c = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]); dp[i][0] = a; dp[i][1] = b; dp[i][2] = c; } cout << max(dp[n - 1][2], max(dp[n - 1][0], dp[n - 1][1])); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n][3]; int x = n; while (x--) cin >> arr[n - x - 1][0] >> arr[n - x - 1][1] >> arr[n - x - 1][2]; int dp[n][3]; dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2]; for (int i = 1; i < n; i++) { int a, b, c; a = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]); b = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]); c = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]); dp[i][0] = a; dp[i][1] = b; dp[i][2] = c; } cout << max(dp[n - 1][2], max(dp[n - 1][0], dp[n - 1][1])); }
replace
8
9
8
9
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll INF = 1LL << 60; #define rep1(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, k, n) for (ll i = k; i < (n); i++) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 入力 int N; ll a[10010][3]; // DP テーブル ll dp[100010][3]; int main() { int N; cin >> N; rep1(i, N) rep1(j, 3) cin >> a[i][j]; // ループ rep1(i, N) { rep1(j, 3) { rep1(k, 3) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; rep1(i, 3) chmax(ans, dp[N][i]); // 答え cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll INF = 1LL << 60; #define rep1(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, k, n) for (ll i = k; i < (n); i++) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 入力 int N; ll a[100010][3]; // DP テーブル ll dp[100010][3]; int main() { int N; cin >> N; rep1(i, N) rep1(j, 3) cin >> a[i][j]; // ループ rep1(i, N) { rep1(j, 3) { rep1(k, 3) { if (j == k) continue; chmax(dp[i + 1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; rep1(i, 3) chmax(ans, dp[N][i]); // 答え cout << ans << endl; }
replace
25
26
25
26
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; vector<vector<int>> dp(100001, vector<int>(4, -1)); int dfs(vector<int> swim, vector<int> bugs, vector<int> homework, int index, int prev) { if (index == swim.size()) { return 0; } if (dp[index][prev] != -1) return dp[index][prev]; int happiness = 0; if (prev != 1) { happiness = max(happiness, dfs(swim, bugs, homework, index + 1, 1) + swim[index]); } if (prev != 2) { happiness = max(happiness, dfs(swim, bugs, homework, index + 1, 2) + bugs[index]); } if (prev != 3) { happiness = max(happiness, homework[index] + dfs(swim, bugs, homework, index + 1, 3)); } dp[index][prev] = happiness; return happiness; } int main() { int n; cin >> n; vector<int> swim(n), bugs(n), homework(n); for (int i = 0; i < n; i++) { cin >> swim[i] >> bugs[i] >> homework[i]; } cout << dfs(swim, bugs, homework, 0, 0); }
#include <bits/stdc++.h> using namespace std; vector<vector<int>> dp(100001, vector<int>(4, -1)); int dfs(vector<int> &swim, vector<int> &bugs, vector<int> &homework, int index, int prev) { if (index == swim.size()) { return 0; } if (dp[index][prev] != -1) return dp[index][prev]; int happiness = 0; if (prev != 1) { happiness = max(happiness, dfs(swim, bugs, homework, index + 1, 1) + swim[index]); } if (prev != 2) { happiness = max(happiness, dfs(swim, bugs, homework, index + 1, 2) + bugs[index]); } if (prev != 3) { happiness = max(happiness, homework[index] + dfs(swim, bugs, homework, index + 1, 3)); } dp[index][prev] = happiness; return happiness; } int main() { int n; cin >> n; vector<int> swim(n), bugs(n), homework(n); for (int i = 0; i < n; i++) { cin >> swim[i] >> bugs[i] >> homework[i]; } cout << dfs(swim, bugs, homework, 0, 0); }
replace
3
4
3
4
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i < n + 1; i++) #define sort(A) sort(A.begin(), A.end()) #define reverse(A) reverse(A.begin(), A.end()); typedef long long ll; const ll MOD = 1000000007; int main() { int n; cin >> n; vector<int> a(n + 1), b(n + 1), c(n + 1); rep1(i, n) cin >> a[i] >> b[i] >> c[i]; int dp[3][100010] = {}; dp[1][1] = a[1]; dp[2][1] = b[1]; dp[3][1] = c[1]; for (int i = 2; i <= n; i++) { int way1; int way2; way1 = dp[2][i - 1] + a[i]; way2 = dp[3][i - 1] + a[i]; dp[1][i] = max(way1, way2); way1 = dp[1][i - 1] + b[i]; way2 = dp[3][i - 1] + b[i]; dp[2][i] = max(way1, way2); way1 = dp[1][i - 1] + c[i]; way2 = dp[2][i - 1] + c[i]; dp[3][i] = max(way1, way2); } int ans = 0; rep1(i, 3) ans = max(ans, dp[i][n]); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i < n + 1; i++) #define sort(A) sort(A.begin(), A.end()) #define reverse(A) reverse(A.begin(), A.end()); typedef long long ll; const ll MOD = 1000000007; int main() { int n; cin >> n; vector<int> a(n + 1), b(n + 1), c(n + 1); rep1(i, n) cin >> a[i] >> b[i] >> c[i]; vector<vector<int>> dp(4, vector<int>(n + 1)); dp[1][1] = a[1]; dp[2][1] = b[1]; dp[3][1] = c[1]; for (int i = 2; i <= n; i++) { int way1; int way2; way1 = dp[2][i - 1] + a[i]; way2 = dp[3][i - 1] + a[i]; dp[1][i] = max(way1, way2); way1 = dp[1][i - 1] + b[i]; way2 = dp[3][i - 1] + b[i]; dp[2][i] = max(way1, way2); way1 = dp[1][i - 1] + c[i]; way2 = dp[2][i - 1] + c[i]; dp[3][i] = max(way1, way2); } int ans = 0; rep1(i, 3) ans = max(ans, dp[i][n]); cout << ans << endl; }
replace
15
16
15
16
-6
*** stack smashing detected ***: terminated
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" const int MOD = 1e9 + 7; #ifndef HOME #define cerr \ if (0) \ cerr #endif const int MaxN = 1e5 + 5; int dp[MaxN][3]; int a[MaxN][3]; int n; int solve(int i, int type) { if (i == n) { return 0; } int &ans = dp[i][type]; if (ans != -1) { return ans; } int res = 0; if (i == 0) { res = max(res, a[i][0] + solve(i + 1, 1)); res = max(res, a[i][0] + solve(i + 1, 2)); res = max(res, a[i][1] + solve(i + 1, 2)); res = max(res, a[i][1] + solve(i + 1, 0)); res = max(res, a[i][2] + solve(i + 1, 1)); res = max(res, a[i][2] + solve(i + 1, 0)); } else { for (int j = 0; j < n; j++) { if (type != j) { res = max(res, a[i][type] + solve(i + 1, j)); } } } return ans = res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } memset(dp, -1, sizeof(dp)); cout << solve(0, 0); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" const int MOD = 1e9 + 7; #ifndef HOME #define cerr \ if (0) \ cerr #endif const int MaxN = 1e5 + 5; int dp[MaxN][3]; int a[MaxN][3]; int n; int solve(int i, int type) { if (i == n) { return 0; } int &ans = dp[i][type]; if (ans != -1) { return ans; } int res = 0; if (i == 0) { res = max(res, a[i][0] + solve(i + 1, 1)); res = max(res, a[i][0] + solve(i + 1, 2)); res = max(res, a[i][1] + solve(i + 1, 2)); res = max(res, a[i][1] + solve(i + 1, 0)); res = max(res, a[i][2] + solve(i + 1, 1)); res = max(res, a[i][2] + solve(i + 1, 0)); } else { for (int j = 0; j < 3; j++) { if (type != j) { res = max(res, a[i][type] + solve(i + 1, j)); } } } return ans = res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } memset(dp, -1, sizeof(dp)); cout << solve(0, 0); return 0; }
replace
31
32
31
32
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; const int maxn = 1e4; int a[maxn][maxn]; int dp[maxn][maxn]; int main() { int n; cin >> n; 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++) { cin >> a[i - 1][j]; } dp[i][0] = a[i - 1][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = a[i - 1][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = a[i - 1][2] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; const int maxn = 1e5; int a[maxn][3]; int dp[maxn][3]; int main() { int n; cin >> n; 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++) { cin >> a[i - 1][j]; } dp[i][0] = a[i - 1][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = a[i - 1][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = a[i - 1][2] + max(dp[i - 1][0], dp[i - 1][1]); } cout << max(dp[n][0], max(dp[n][1], dp[n][2])); return 0; }
replace
3
6
3
6
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb(s) push_back(s) #define mp(a, b) make_pair(a, b) #define f first #define se second #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 typedef long long ll; void solve() { int N; cin >> N; vector<int> dp(3); for (int i = 1; i <= N; ++i) { vector<int> c(3); vector<int> dp2(3, 0); for (int i = 0; i < N; ++i) cin >> c[i]; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i != j) { dp2[j] = max(dp2[j], dp[i] + c[j]); } } } dp = dp2; } cout << max(dp[0], max(dp[1], dp[2])) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // int t; // cin>>t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb(s) push_back(s) #define mp(a, b) make_pair(a, b) #define f first #define se second #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 typedef long long ll; void solve() { int N; cin >> N; vector<int> dp(3); for (int i = 1; i <= N; ++i) { vector<int> c(3); vector<int> dp2(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) { dp2[j] = max(dp2[j], dp[i] + c[j]); } } } dp = dp2; } cout << max(dp[0], max(dp[1], dp[2])) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // int t; // cin>>t; // while(t--) solve(); return 0; }
replace
27
28
27
28
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long t, n; long long dp[100000][3]; long long c[4]; const int INF = 1e9 + 5; int main() { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 3; j++) { long long x; cin >> x; for (int u = 1; u <= 3; u++) { if (u != j) { dp[i][j] = max(dp[i][j], dp[i - 1][u] + x); } } } } cout << max(dp[n][1], max(dp[n][2], dp[n][3])); /*for (int i=0; i<n; i++) { for (int j=1; j<=3; j++) { cout << dp[i][j] << " "; } cout << '\n'; }*/ }
#include <bits/stdc++.h> using namespace std; long long t, n; long long dp[200000][3]; long long c[4]; const int INF = 1e9 + 5; int main() { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 3; j++) { long long x; cin >> x; for (int u = 1; u <= 3; u++) { if (u != j) { dp[i][j] = max(dp[i][j], dp[i - 1][u] + x); } } } } cout << max(dp[n][1], max(dp[n][2], dp[n][3])); /*for (int i=0; i<n; i++) { for (int j=1; j<=3; j++) { cout << dp[i][j] << " "; } cout << '\n'; }*/ }
replace
4
5
4
5
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector<vector<long long>> dp(n, vector<long long>(3, 0)); for (int i = 0; i < n; i++) cin >> dp[i][0] >> dp[i][1] >> dp[i][2]; long long mx = INT_MIN; for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { mx = INT_MIN; for (int k = 0; k < 3; k++) { if (k != j) mx = max(mx, dp[i - 1][k]); } dp[i][j] += mx; } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<long long>> dp(n, vector<long long>(3, 0)); for (int i = 0; i < n; i++) cin >> dp[i][0] >> dp[i][1] >> dp[i][2]; long long mx = INT_MIN; for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) { mx = INT_MIN; for (int k = 0; k < 3; k++) { if (k != j) mx = max(mx, dp[i - 1][k]); } dp[i][j] += mx; } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]); return 0; }
delete
4
8
4
4
0
p03162
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) long long mmax(long long x, long long y) { if (x > y) return x; else return y; } int main() { int n; cin >> n; Graph abc(n); rep(i, n) { int a, b, c; cin >> a >> b >> c; abc[i].push_back(a); abc[i].push_back(b); abc[i].push_back(c); } long long dp[1000][3]; rep(i, 1000) rep(j, 3) dp[i][j] = 0; dp[0][0] = abc[0][0]; dp[0][1] = abc[0][1]; dp[0][2] = abc[0][2]; rep(i, n - 1) { rep(j, 3) { long long x = dp[i][(j + 1) % 3]; long long y = dp[i][(j + 2) % 3]; dp[i + 1][j] = mmax(x, y) + abc[i + 1][j]; } } // rep(i, n) rep(j, 3) // cout << i << j << ":" << dp[i][j] << endl; long long ans = 0; rep(i, 3) ans = mmax(ans, dp[n - 1][i]); cout << ans << endl; }
#include <iostream> #include <vector> using namespace std; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) long long mmax(long long x, long long y) { if (x > y) return x; else return y; } int main() { int n; cin >> n; Graph abc(n); rep(i, n) { int a, b, c; cin >> a >> b >> c; abc[i].push_back(a); abc[i].push_back(b); abc[i].push_back(c); } long long dp[100009][3]; rep(i, 100009) rep(j, 3) dp[i][j] = 0; dp[0][0] = abc[0][0]; dp[0][1] = abc[0][1]; dp[0][2] = abc[0][2]; rep(i, n - 1) { rep(j, 3) { long long x = dp[i][(j + 1) % 3]; long long y = dp[i][(j + 2) % 3]; dp[i + 1][j] = mmax(x, y) + abc[i + 1][j]; } } // rep(i, n) rep(j, 3) // cout << i << j << ":" << dp[i][j] << endl; long long ans = 0; rep(i, 3) ans = mmax(ans, dp[n - 1][i]); cout << ans << endl; }
replace
25
27
25
27
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1e9 + 7; ll dp[10010][3]; int main() { int N; cin >> N; ll 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 < 3; i++) dp[0][i] = a[0][i]; for (int 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]); } 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; using ll = long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1e9 + 7; ll dp[100010][3]; int main() { int N; cin >> N; ll 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 < 3; i++) dp[0][i] = a[0][i]; for (int 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]); } cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl; return 0; }
replace
9
10
9
10
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define P pair<int, int> #define F first #define S second const ll mod = 1000000007LL; ll n, a[100005], b[100005], c[100005], dp[100005][3]; void solve() { 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], dp[n - 1][1], dp[n - 1][2]}); } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("practice/input.txt", "r", stdin); freopen("practice/output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define P pair<int, int> #define F first #define S second const ll mod = 1000000007LL; ll n, a[100005], b[100005], c[100005], dp[100005][3]; void solve() { 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], dp[n - 1][1], dp[n - 1][2]}); } int main(int argc, char const *argv[]) { /*#ifndef ONLINE_JUDGE freopen("practice/input.txt", "r", stdin); freopen("practice/output.txt", "w", stdout); #endif*/ ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; while (T--) { solve(); } return 0; }
replace
29
33
29
33
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS int n; cin >> n; vector<int> dp(3); for (int d = 0; d < n; d++) { vector<int> ndp(3, 0); vector<int> c(3); 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) ndp[j] = max(ndp[j], c[j] + dp[i]); } } dp = ndp; } cout << max({dp[0], dp[1], dp[2]}); return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { IOS int n; cin >> n; vector<int> dp(3); for (int d = 0; d < n; d++) { vector<int> ndp(3, 0); vector<int> c(3); 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) ndp[j] = max(ndp[j], c[j] + dp[i]); } } dp = ndp; } cout << max({dp[0], dp[1], dp[2]}); return 0; }
replace
12
16
12
13
0
p03162
C++
Runtime Error
// define debug for debugging #define DEBUG #include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define mp make_pair #define MOD 1000000007 #define MAX 100000 + 100 #define max3(a, b, c) max(a, max(b, c)) typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int n, cevap = -1; int arr[MAX][3], dp[MAX][3][3]; void dfs(int a, int b, int c) { if (a == -1) { dfs(0, 0, 1); dfs(0, 1, 2); dfs(0, 2, 0); cevap = max3(dp[0][0][1], dp[0][1][2], dp[0][2][0]); } else if (dp[a][b][c] == 0) { int mn = 0; if (a + 1 < n) { if (c != 0) { dfs(a + 1, c, 0); mn = dp[a + 1][c][0]; } if (c != 1) { dfs(a + 1, c, 1); mn = max(mn, dp[a + 1][c][1]); } if (c != 2) { dfs(a + 1, c, 2); mn = max(mn, dp[a + 1][c][2]); } } else mn = 0; dp[a][b][c] = mn + arr[a][c]; // cout << a << ' ' << b << ' ' << c << ' ' << dp[a][b][c] << ' ' << mn << // ' ' << arr[a][c] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef DEBUG freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } dfs(-1, -1, -1); cout << cevap; return 0; }
// define debug for debugging // #define DEBUG #include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define mp make_pair #define MOD 1000000007 #define MAX 100000 + 100 #define max3(a, b, c) max(a, max(b, c)) typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int n, cevap = -1; int arr[MAX][3], dp[MAX][3][3]; void dfs(int a, int b, int c) { if (a == -1) { dfs(0, 0, 1); dfs(0, 1, 2); dfs(0, 2, 0); cevap = max3(dp[0][0][1], dp[0][1][2], dp[0][2][0]); } else if (dp[a][b][c] == 0) { int mn = 0; if (a + 1 < n) { if (c != 0) { dfs(a + 1, c, 0); mn = dp[a + 1][c][0]; } if (c != 1) { dfs(a + 1, c, 1); mn = max(mn, dp[a + 1][c][1]); } if (c != 2) { dfs(a + 1, c, 2); mn = max(mn, dp[a + 1][c][2]); } } else mn = 0; dp[a][b][c] = mn + arr[a][c]; // cout << a << ' ' << b << ' ' << c << ' ' << dp[a][b][c] << ' ' << mn << // ' ' << arr[a][c] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef DEBUG freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } dfs(-1, -1, -1); cout << cevap; return 0; }
replace
1
2
1
2
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, dp[300005][5], arr[300005][5]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) scanf("%d", arr[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) { dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + arr[i][k]); } } } } int res = max(dp[n][0], dp[n][1]); res = max(res, dp[n][2]); printf("%d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; int n, dp[300005][5], arr[300005][5]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) scanf("%d", &arr[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) { dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + arr[i][k]); } } } } int res = max(dp[n][0], dp[n][1]); res = max(res, dp[n][2]); printf("%d\n", res); return 0; }
replace
9
10
9
10
-11
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long int; vector<vector<ll>> v; ll n; ll DP[100000][3]; ll backtrack(ll pos, char choice) { if (pos == n) return 0LL; vector<ll> b; for (ll i = 0; i < 3; i++) { char ch = (char)(i + 'a'); if (choice != ch && DP[pos][i] != -1) { b.push_back(DP[pos][i]); } } if (b.size() == 2) return max(b[0], b[1]); ll answer = 0; for (ll i = 0; i < 3; i++) { char ch = (char)(i + 'a'); if (choice != ch) { answer = max(answer, v[pos][ch - 'a'] + backtrack(pos + 1, ch)); } } return answer; } int main() { cin >> n; for (ll i = 0; i < n; i++) { ll a, b, c; cin >> a >> b >> c; v.push_back({a, b, c}); } memset(DP, -1, sizeof(DP)); cout << backtrack(0, '.'); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; vector<vector<ll>> v; ll n; ll DP[100000][3]; ll backtrack(ll pos, char choice) { if (pos == n) return 0LL; vector<ll> b; for (ll i = 0; i < 3; i++) { char ch = (char)(i + 'a'); if (choice != ch && DP[pos][i] != -1) { b.push_back(DP[pos][i]); } } if (b.size() == 2) return max(b[0], b[1]); ll answer = 0; for (ll i = 0; i < 3; i++) { char ch = (char)(i + 'a'); if (choice != ch) { DP[pos][i] = v[pos][ch - 'a'] + backtrack(pos + 1, ch); answer = max(answer, DP[pos][i]); } } return answer; } int main() { cin >> n; for (ll i = 0; i < n; i++) { ll a, b, c; cin >> a >> b >> c; v.push_back({a, b, c}); } memset(DP, -1, sizeof(DP)); cout << backtrack(0, '.'); return 0; }
replace
34
35
34
36
TLE
p03162
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb push_back #define csl \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define reps(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) for (int i = 0; i < int(b); i++) #define first ff #define second ss #define size sz typedef long long ll; typedef vector<long long> vll; typedef vector<pair<int, int>> vii; typedef vector<int> vi; typedef pair<ll, ll> pll; const int INF = 1e9 + 5; int main() { csl; int n; cin >> n; vector<int> dp(3, 0); for (int d = 0; d < n; d++) { vector<int> q(3); vector<int> inp(3); rep(j, 3) { cin >> inp[j]; } rep(i, n) { rep(j, n) { if (i != j) { q[j] = max(q[j], dp[i] + inp[j]); } } } dp = q; } cout << max({dp[0], dp[1], dp[2]}) << endl; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb push_back #define csl \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define reps(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) for (int i = 0; i < int(b); i++) #define first ff #define second ss #define size sz typedef long long ll; typedef vector<long long> vll; typedef vector<pair<int, int>> vii; typedef vector<int> vi; typedef pair<ll, ll> pll; const int INF = 1e9 + 5; int main() { csl; int n; cin >> n; vector<int> dp(3, 0); for (int d = 0; d < n; d++) { vector<int> q(3); vector<int> inp(3); rep(j, 3) { cin >> inp[j]; } rep(i, 3) { rep(j, 3) { if (i != j) { q[j] = max(q[j], dp[i] + inp[j]); } } } dp = q; } cout << max({dp[0], dp[1], dp[2]}) << endl; }
replace
29
31
29
31
0
p03162
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string> using namespace std; long long dp[100001][3]; int main() { int N; long long a[10001][3]; cin >> N; for (int i = 1; i < N + 1; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } for (int i = 0; i < N + 1; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } for (int i = 1; i < N + 1; i++) { for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { if (j != k) { dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]); } if (j == k) { dp[i][k] = dp[i][k]; } } } } long long answer = 0; for (int j = 0; j < 3; j++) { answer = max(answer, dp[N][j]); } cout << answer << endl; } /*int dp[100001]; int main(){ int N,K; cin>>N>>K; int h[100000]; for(int i=1;i<N+1;i++){ cin>>h[i]; } dp[0]=0; dp[1]=0; for(int i=2;i<N+1;i++){ dp[i]=99999999; if(i<=K){ for(int j=1;j<i;j++){ dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j])); } } if(i>K){ for(int j=i-K;j<i;j++){ dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j])); } } } cout<<dp[N]<<endl;*/ /*int dp[200000]; int main(){ int N,C; cin>>N>>C; int h[200000]; for(int i=1;i<N+1;i++){ cin>>h[i]; } dp[1]=0; dp[2]=(h[2]-h[1])*(h[2]-h[1])+C; for(int i=3;i<N+1;i++){ dp[i]=99999999; for(int j=1;j<i;j++){ dp[i]=min(dp[i],dp[j]+(h[i]-h[j])*(h[i]-h[j])+C); } } cout<<dp[N]<<endl;*/
#include <algorithm> #include <iostream> #include <math.h> #include <string> using namespace std; long long dp[100001][3]; int main() { int N; long long a[100001][3]; cin >> N; for (int i = 1; i < N + 1; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } for (int i = 0; i < N + 1; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = 0; } } for (int i = 1; i < N + 1; i++) { for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { if (j != k) { dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]); } if (j == k) { dp[i][k] = dp[i][k]; } } } } long long answer = 0; for (int j = 0; j < 3; j++) { answer = max(answer, dp[N][j]); } cout << answer << endl; } /*int dp[100001]; int main(){ int N,K; cin>>N>>K; int h[100000]; for(int i=1;i<N+1;i++){ cin>>h[i]; } dp[0]=0; dp[1]=0; for(int i=2;i<N+1;i++){ dp[i]=99999999; if(i<=K){ for(int j=1;j<i;j++){ dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j])); } } if(i>K){ for(int j=i-K;j<i;j++){ dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j])); } } } cout<<dp[N]<<endl;*/ /*int dp[200000]; int main(){ int N,C; cin>>N>>C; int h[200000]; for(int i=1;i<N+1;i++){ cin>>h[i]; } dp[1]=0; dp[2]=(h[2]-h[1])*(h[2]-h[1])+C; for(int i=3;i<N+1;i++){ dp[i]=99999999; for(int j=1;j<i;j++){ dp[i]=min(dp[i],dp[j]+(h[i]-h[j])*(h[i]-h[j])+C); } } cout<<dp[N]<<endl;*/
replace
9
10
9
10
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 5, M = 1e9 + 7, OO = 0x3f3f3f3f; int n; int arr[3][N]; int mem[N][4]; int solve(int i, int last) { if (i == n) return 0; if (mem[i][last] = !-1) return mem[i][last]; int op1 = (last != 1) ? solve(i + 1, 1) + arr[0][i] : 0; int op2 = (last != 2) ? solve(i + 1, 2) + arr[1][i] : 0; int op3 = (last != 3) ? solve(i + 1, 3) + arr[2][i] : 0; return mem[i][last] = max(op1, max(op2, op3)); } int main() { // freopen("input.txt","rt",stdin); // freopen("output.txt","wt",stdout); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d %d", arr[0] + i, arr[1] + i, arr[2] + i); memset(mem, -1, sizeof mem); printf("%d\n", solve(0, 0)); return 0; }
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 5, M = 1e9 + 7, OO = 0x3f3f3f3f; int n; int arr[3][N]; int mem[N][4]; int solve(int i, int last) { if (i == n) return 0; if (mem[i][last] != -1) return mem[i][last]; int op1 = (last != 1) ? solve(i + 1, 1) + arr[0][i] : 0; int op2 = (last != 2) ? solve(i + 1, 2) + arr[1][i] : 0; int op3 = (last != 3) ? solve(i + 1, 3) + arr[2][i] : 0; return mem[i][last] = max(op1, max(op2, op3)); } int main() { // freopen("input.txt","rt",stdin); // freopen("output.txt","wt",stdout); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d %d", arr[0] + i, arr[1] + i, arr[2] + i); memset(mem, -1, sizeof mem); printf("%d\n", solve(0, 0)); return 0; }
replace
12
13
12
13
TLE
p03162
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int main() { int n; cin >> n; vector<int> dp(3); // dp[0] = max({dp[0],dp[1],dp[2]}); for (int day = 0; day < n; day++) { vector<int> new_dp(3); vector<int> c(3); for (int i = 0; i < 3; ++i) { scanf("%d", &c[i]); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j != i) { new_dp[j] = max(new_dp[j], dp[i] + c[j]); } } } dp = new_dp; } cout << dp[n - 1]; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int n; cin >> n; vector<int> dp(3); // dp[0] = max({dp[0],dp[1],dp[2]}); for (int day = 0; day < n; day++) { vector<int> new_dp(3); vector<int> c(3); for (int i = 0; i < 3; ++i) { scanf("%d", &c[i]); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j != i) { new_dp[j] = max(new_dp[j], dp[i] + c[j]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}); return 0; }
replace
24
25
24
25
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #define scan(n) scanf("%I64d", &n); #define scan2(a, b) scanf("%I64d%I64d", &a, &b); #define scan3(a, b, c) scanf("%I64d%I64d%I64d", &a, &b, &c); #define sc(n) scanf("%c", &n); #define sf(n) scanf("%lf", &n); #define ss(n) scanf("%s", n); #define forall(i, a, b) for (long long int i = a; i < b; i++) #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define minimum(a) *min_element(a.begin(), a.end()) #define maximum(a) *max_element(a.begin(), a.end()) #define display(a) \ for (auto i : a) \ cout << i << " "; typedef long long int ll; typedef long double ld; const int MOD = 1e9 + 7; using namespace std; ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power(ll a, ll n, ll mod) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } vector<ll> scanVector(ll n, vector<ll> &v) { ll temp; for (ll i = 0; i < n; i++) { cin >> temp; v.pb(temp); } return v; } int main() { FAST_IO ll t; // cin>>t; t = 1; while (t--) { ll n; cin >> n; ll a1, b1, c1; vector<ll> a; vector<ll> b; vector<ll> c; for (ll i = 1; i <= n; i++) { cin >> a1 >> b1 >> c1; a.pb(a1); b.pb(b1); c.pb(c1); } ll dp[n][n]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (ll 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]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } return 0; }
#include <bits/stdc++.h> #include <iostream> #define scan(n) scanf("%I64d", &n); #define scan2(a, b) scanf("%I64d%I64d", &a, &b); #define scan3(a, b, c) scanf("%I64d%I64d%I64d", &a, &b, &c); #define sc(n) scanf("%c", &n); #define sf(n) scanf("%lf", &n); #define ss(n) scanf("%s", n); #define forall(i, a, b) for (long long int i = a; i < b; i++) #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define minimum(a) *min_element(a.begin(), a.end()) #define maximum(a) *max_element(a.begin(), a.end()) #define display(a) \ for (auto i : a) \ cout << i << " "; typedef long long int ll; typedef long double ld; const int MOD = 1e9 + 7; using namespace std; ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power(ll a, ll n, ll mod) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } vector<ll> scanVector(ll n, vector<ll> &v) { ll temp; for (ll i = 0; i < n; i++) { cin >> temp; v.pb(temp); } return v; } int main() { FAST_IO ll t; // cin>>t; t = 1; while (t--) { ll n; cin >> n; ll a1, b1, c1; vector<ll> a; vector<ll> b; vector<ll> c; for (ll i = 1; i <= n; i++) { cin >> a1 >> b1 >> c1; a.pb(a1); b.pb(b1); c.pb(c1); } ll dp[n][3]; dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; for (ll 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]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; } return 0; }
replace
75
76
75
76
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); vector<int> b(N); vector<int> c(N); for (int i = 0; i < N; i++) { int A, B, C; cin >> A >> B >> C; a.at(i) = A; b.at(i) = B; c.at(i) = C; } vector<vector<int>> dp(N + 1, vector<int>(3, 0)); for (int i = 0; i <= N; i++) { dp[i][0] = a.at(i - 1) + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = b.at(i - 1) + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = c.at(i - 1) + max(dp[i - 1][0], dp[i - 1][1]); } int ans = max(dp[N][0], max(dp[N][1], dp[N][2])); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); vector<int> b(N); vector<int> c(N); for (int i = 0; i < N; i++) { int A, B, C; cin >> A >> B >> C; a.at(i) = A; b.at(i) = B; c.at(i) = C; } vector<vector<int>> dp(N + 1, vector<int>(3, 0)); for (int i = 1; i <= N; i++) { dp[i][0] = a.at(i - 1) + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = b.at(i - 1) + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = c.at(i - 1) + max(dp[i - 1][0], dp[i - 1][1]); } int ans = max(dp[N][0], max(dp[N][1], dp[N][2])); cout << ans << endl; return 0; }
replace
16
17
16
17
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 3)
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define ll long long #define mp make_pair #define MAXN 1e6 const int mod = 1e9 + 7; void solve() { int n, x; cin >> n; vector<int> dp(3); for (int i = 0; i < n; i++) { vector<int> new_dp(3, 0); vector<int> c(3); for (int j = 0; j < 3; j++) cin >> c[i]; 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] + c[k]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}); } int main() { fastio solve(); }
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define ll long long #define mp make_pair #define MAXN 1e6 const int mod = 1e9 + 7; void solve() { int n, x; cin >> n; vector<int> dp(3); for (int i = 0; i < n; i++) { vector<int> new_dp(3, 0); vector<int> c(3); for (int j = 0; j < 3; j++) cin >> c[j]; 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] + c[k]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}); } int main() { fastio solve(); }
replace
20
21
20
21
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define sanyes \ ios_base::sync_with_stdio(0), cout.tie(0); \ cin.tie(0); #define llong long long #define pb push_back #define bpc __builtin_popcount const llong mxn = 1e5 + 7; const llong mod = 998244353; const llong inf = 1e18 + 9; using namespace std; llong n, l, dp[1001][3], a[mxn], b[mxn], c[mxn], mx = -inf; 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++) { dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i]; dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c[i]; } mx = max(dp[n][1], max(dp[n][2], dp[n][3])); cout << mx; return 0; }
#include <bits/stdc++.h> #define sanyes \ ios_base::sync_with_stdio(0), cout.tie(0); \ cin.tie(0); #define llong long long #define pb push_back #define bpc __builtin_popcount const llong mxn = 1e5 + 7; const llong mod = 998244353; const llong inf = 1e18 + 9; using namespace std; llong n, l, dp[mxn][3], a[mxn], b[mxn], c[mxn], mx = -inf; 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++) { dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i]; dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i]; dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c[i]; } mx = max(dp[n][1], max(dp[n][2], dp[n][3])); cout << mx; return 0; }
replace
14
15
14
15
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int dp[10010][3]; 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] = a + max({dp[i - 1][1], dp[i - 1][2]}); dp[i][1] = b + max({dp[i - 1][0], dp[i - 1][2]}); dp[i][2] = c + max({dp[i - 1][0], dp[i - 1][1]}); } } cout << max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}); }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int dp[100010][3]; 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] = a + max({dp[i - 1][1], dp[i - 1][2]}); dp[i][1] = b + max({dp[i - 1][0], dp[i - 1][2]}); dp[i][2] = c + max({dp[i - 1][0], dp[i - 1][1]}); } } cout << max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}); }
replace
7
8
7
8
0
p03162
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string.h> #include <vector> using namespace std; #define mod (long)(998244353) #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl(long(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) #define long long long template <class T> inline void YES(T condition) { if (condition) cout << "YES" << endl; else cout << "NO" << endl; } template <class T> inline void Yes(T condition) { if (condition) cout << "Yes" << endl; else cout << "No" << endl; } template <class T> inline void POSS(T condition) { if (condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; } template <class T> inline void Poss(T condition) { if (condition) cout << "Possible" << endl; else cout << "Impossible" << endl; } template <class T> inline void First(T condition) { if (condition) cout << "First" << endl; else cout << "Second" << endl; } template <class T = string, class U = char> int character_count(T text, U character) { int ans = 0; for (U i : text) { ans += (i == character); } return ans; } long power(long base, long exponent, long module) { if (exponent % 2) { return power(base, exponent - 1, module) * base % module; } else if (exponent) { long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; } else { return 1; } } struct position { int y, x; }; position move_pattern[4] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return // sqrt((second.x - first.x) * (second.x - first.x) + (second.y - // first.y) * (second.y - first.y)); } template <class T, class U> string to_string(pair<T, U> x) { return to_string(x.first) + "," + to_string(x.second); } template <class itr> void array_output(itr start, itr goal) { string ans; for (auto i = start; i != goal; i++) { ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; } template <class itr> void cins(itr start, itr goal) { for (auto i = start; i != goal; i++) { cin >> (*i); } } template <class T> T gcd(T a, T b) { if (a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); } else { return a; } } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } struct combination { vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1) { fact[0] = 1; for (int i = 1; i <= sz; i++) { fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for (int i = sz - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const { if (q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; int N; vector<vector<int>> can_do; int dp[100020][4]; int doing(int now, int yesterday_I_did_swimming_or_catching_or_doing_homework) { if (now == N) { return 0; } int ans = 0; for (int i = 0; i < 3; i++) { if (i != yesterday_I_did_swimming_or_catching_or_doing_homework) { ans = max(ans, can_do[now][i] + doing(now + 1, i)); } } return dp[now][yesterday_I_did_swimming_or_catching_or_doing_homework] = ans; } int main() { cin >> N; can_do.resize(N, vector<int>(3)); for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> can_do[i][j]; } } memset(dp, -1, sizeof(dp)); cout << doing(0, 3) << endl; }
#include <algorithm> #include <iostream> #include <string.h> #include <vector> using namespace std; #define mod (long)(998244353) #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl(long(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) #define long long long template <class T> inline void YES(T condition) { if (condition) cout << "YES" << endl; else cout << "NO" << endl; } template <class T> inline void Yes(T condition) { if (condition) cout << "Yes" << endl; else cout << "No" << endl; } template <class T> inline void POSS(T condition) { if (condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; } template <class T> inline void Poss(T condition) { if (condition) cout << "Possible" << endl; else cout << "Impossible" << endl; } template <class T> inline void First(T condition) { if (condition) cout << "First" << endl; else cout << "Second" << endl; } template <class T = string, class U = char> int character_count(T text, U character) { int ans = 0; for (U i : text) { ans += (i == character); } return ans; } long power(long base, long exponent, long module) { if (exponent % 2) { return power(base, exponent - 1, module) * base % module; } else if (exponent) { long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; } else { return 1; } } struct position { int y, x; }; position move_pattern[4] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return // sqrt((second.x - first.x) * (second.x - first.x) + (second.y - // first.y) * (second.y - first.y)); } template <class T, class U> string to_string(pair<T, U> x) { return to_string(x.first) + "," + to_string(x.second); } template <class itr> void array_output(itr start, itr goal) { string ans; for (auto i = start; i != goal; i++) { ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; } template <class itr> void cins(itr start, itr goal) { for (auto i = start; i != goal; i++) { cin >> (*i); } } template <class T> T gcd(T a, T b) { if (a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); } else { return a; } } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } struct combination { vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1) { fact[0] = 1; for (int i = 1; i <= sz; i++) { fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for (int i = sz - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const { if (q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; int N; vector<vector<int>> can_do; int dp[100020][4]; int doing(int now, int yesterday_I_did_swimming_or_catching_or_doing_homework) { if (now == N) { return 0; } else if (dp[now][yesterday_I_did_swimming_or_catching_or_doing_homework] != -1) { return dp[now][yesterday_I_did_swimming_or_catching_or_doing_homework]; } int ans = 0; for (int i = 0; i < 3; i++) { if (i != yesterday_I_did_swimming_or_catching_or_doing_homework) { ans = max(ans, can_do[now][i] + doing(now + 1, i)); } } return dp[now][yesterday_I_did_swimming_or_catching_or_doing_homework] = ans; } int main() { cin >> N; can_do.resize(N, vector<int>(3)); for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> can_do[i][j]; } } memset(dp, -1, sizeof(dp)); cout << doing(0, 3) << endl; }
insert
120
120
120
123
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[10005][3] = {0}; int ans(int *a, int *b, int *c, int n) { dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1]; for (int i = 2; 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]); } return max(dp[n][0], max(dp[n][1], dp[n][2])); } int main() { int n; cin >> n; int a[n + 1], b[n + 1], c[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << ans(a, b, c, n) << "\n"; }
#include <bits/stdc++.h> using namespace std; int dp[100005][3] = {0}; int ans(int *a, int *b, int *c, int n) { dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1]; for (int i = 2; 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]); } return max(dp[n][0], max(dp[n][1], dp[n][2])); } int main() { int n; cin >> n; int a[n + 1], b[n + 1], c[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; } cout << ans(a, b, c, n) << "\n"; }
replace
3
4
3
4
0
p03162
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) #define NIL = -1; ll gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { a / gcd(a, b) * b; } const ll mod = 1e9 + 7; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; const ll INF = 1e9; ///////////////////////////////////////////////////////////////////////////////////////// int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0)); dp[0][0] = 0; 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]); } ll ans = 0; for (int i = 0; i < 3; i++) ans = max(dp[n][i], ans); cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) #define NIL = -1; ll gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { a / gcd(a, b) * b; } const ll mod = 1e9 + 7; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; const ll INF = 1e9; ///////////////////////////////////////////////////////////////////////////////////////// int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(3, 0)); dp[0][0] = 0; 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]); } ll ans = 0; for (int i = 0; i < 3; i++) ans = max(dp[n][i], ans); cout << ans << endl; }
replace
34
35
34
35
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pb push_back #define mp make_pair #define f first #define s second #define ii pair<ll, ll> #define all(x) std::begin(x), std::end(x) ll const MAX = 100005; ll const INF = 1e9; ll const mod = 1000000007; ll dp[MAX][3]; ll a[MAX][3]; ll n; int k; ll cost(int ndx, int ac) { if (ndx >= n) return 0; ll &ret = dp[ndx][ac]; if (ret != -1) return ret; return max(a[ndx][(ac + 1) % 3] + cost(ndx + 1, (ac + 1) % 3), a[ndx][(ac + 2) % 3] + cost(ndx + 1, (ac + 2) % 3)); } int main() { // freopen ( "portals.in" , "r" , stdin ) ; FASTIO; cin >> n; memset(dp, -1, sizeof dp); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; ll ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, cost(0, i)); cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pb push_back #define mp make_pair #define f first #define s second #define ii pair<ll, ll> #define all(x) std::begin(x), std::end(x) ll const MAX = 100005; ll const INF = 1e9; ll const mod = 1000000007; ll dp[MAX][3]; ll a[MAX][3]; ll n; int k; ll cost(int ndx, int ac) { if (ndx >= n) return 0; ll &ret = dp[ndx][ac]; if (ret != -1) return ret; return ret = max(a[ndx][(ac + 1) % 3] + cost(ndx + 1, (ac + 1) % 3), a[ndx][(ac + 2) % 3] + cost(ndx + 1, (ac + 2) % 3)); } int main() { // freopen ( "portals.in" , "r" , stdin ) ; FASTIO; cin >> n; memset(dp, -1, sizeof dp); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; ll ans = 0; for (int i = 0; i < 3; i++) ans = max(ans, cost(0, i)); cout << ans; }
replace
29
31
29
31
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 100005; const long long mod = 1.0e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ll n, k, i, j; cin >> n; ll a[n + 1], b[n + 1], c[n]; vector<pair<ll, ll>> v[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } ll dp[n + 1][3]; memset(dp, 0, sizeof(dp)); dp[1][0] = a[0]; dp[1][1] = b[0]; dp[1][2] = c[0]; for (i = 2; i <= n; i++) { dp[i][0] = a[i - 1] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = b[i - 1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = c[i - 1] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(dp[n][2], max(dp[n][1], dp[n][0])) << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 100005; const long long mod = 1.0e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k, i, j; cin >> n; ll a[n + 1], b[n + 1], c[n]; vector<pair<ll, ll>> v[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } ll dp[n + 1][3]; memset(dp, 0, sizeof(dp)); dp[1][0] = a[0]; dp[1][1] = b[0]; dp[1][2] = c[0]; for (i = 2; i <= n; i++) { dp[i][0] = a[i - 1] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = b[i - 1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = c[i - 1] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(dp[n][2], max(dp[n][1], dp[n][0])) << endl; return 0; }
replace
14
18
14
15
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; vector<vector<ll>> a(n + 1); for (int i = 1; i <= n; ++i) REP(j, 3) { int A; cin >> A; a[i].push_back(A); } ll dp[n + 10][n + 10]; REP(i, n + 10) REP(j, n) dp[i][j] = 0; dp[0][0] = dp[0][1] = dp[0][2] = 0; for (int i = 1; i <= n; ++i) REP(j, 3) REP(k, 3) { if (k == j) continue; dp[i][j] = max(a[i][j] + dp[i - 1][k], dp[i][j]); } ll ans = 0; REP(i, 3) ans = max(ans, dp[n][i]); cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; vector<vector<ll>> a(n + 1); for (int i = 1; i <= n; ++i) REP(j, 3) { int A; cin >> A; a[i].push_back(A); } ll dp[n + 10][3]; REP(i, n + 10) REP(j, 3) dp[i][j] = 0; dp[0][0] = dp[0][1] = dp[0][2] = 0; for (int i = 1; i <= n; ++i) REP(j, 3) REP(k, 3) { if (k == j) continue; dp[i][j] = max(a[i][j] + dp[i - 1][k], dp[i][j]); } ll ans = 0; REP(i, 3) ans = max(ans, dp[n][i]); cout << ans << std::endl; return 0; }
replace
21
23
21
23
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int mat[3][10001]; int main() { #ifdef EVAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int N; cin >> N; int a[N]; int b[N]; int c[N]; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } mat[0][0] = a[0]; mat[1][0] = b[0]; mat[2][0] = c[0]; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 3; j++) { if (j == 0) { mat[1][i + 1] = max(mat[1][i + 1], mat[j][i] + b[i + 1]); mat[2][i + 1] = max(mat[2][i + 1], mat[j][i] + c[i + 1]); } if (j == 1) { mat[0][i + 1] = max(mat[0][i + 1], mat[j][i] + a[i + 1]); mat[2][i + 1] = max(mat[2][i + 1], mat[j][i] + c[i + 1]); } if (j == 2) { mat[0][i + 1] = max(mat[0][i + 1], mat[j][i] + a[i + 1]); mat[1][i + 1] = max(mat[1][i + 1], mat[j][i] + b[i + 1]); } } } cout << max(mat[2][N - 1], max(mat[1][N - 1], mat[0][N - 1])); }
#include <bits/stdc++.h> using namespace std; int mat[3][100001]; int main() { #ifdef EVAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int N; cin >> N; int a[N]; int b[N]; int c[N]; for (int i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; } mat[0][0] = a[0]; mat[1][0] = b[0]; mat[2][0] = c[0]; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 3; j++) { if (j == 0) { mat[1][i + 1] = max(mat[1][i + 1], mat[j][i] + b[i + 1]); mat[2][i + 1] = max(mat[2][i + 1], mat[j][i] + c[i + 1]); } if (j == 1) { mat[0][i + 1] = max(mat[0][i + 1], mat[j][i] + a[i + 1]); mat[2][i + 1] = max(mat[2][i + 1], mat[j][i] + c[i + 1]); } if (j == 2) { mat[0][i + 1] = max(mat[0][i + 1], mat[j][i] + a[i + 1]); mat[1][i + 1] = max(mat[1][i + 1], mat[j][i] + b[i + 1]); } } } cout << max(mat[2][N - 1], max(mat[1][N - 1], mat[0][N - 1])); }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE const bool DEBUG = true; #else const bool DEBUG = false; #endif using ll = long long; using ull = unsigned long long; #define F first #define S second #define all(x) begin(x), end(x) template <class T> void read_vector(vector<T> &arr) { const int size = arr.size(); for (int i = 0; i < size; ++i) cin >> arr[i]; } // template <class T> // vector<T> create_vector(int n) { // vector<T> v(n); // for (int i = 0; i < size; ++i) cin >> v[i]; // return v; // } void exec() { int n; cin >> n; vector<vector<int>> arr(n, vector<int>(3)); for (int i = 0; i < n; ++i) { cin >> arr[i][0]; cin >> arr[i][1]; cin >> arr[i][2]; } vector<vector<int>> dp(3, vector<int>(n, 0)); dp[0][0] = arr[0][0]; dp[1][0] = arr[0][1]; dp[2][0] = arr[0][2]; for (int i = 1; i < n; ++i) { dp[0][i] = max(dp[0][i], arr[i][0] + max(dp[1][i - 1], dp[2][i - 1])); dp[1][i] = max(dp[1][i], arr[i][1] + max(dp[0][i - 1], dp[2][i - 1])); dp[2][i] = max(dp[2][i], arr[i][2] + max(dp[0][i - 1], dp[1][i - 1])); } sort(all(dp[n - 1])); cout << dp[n - 1].back() << endl; } int main() { exec(); return 0; }
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE const bool DEBUG = true; #else const bool DEBUG = false; #endif using ll = long long; using ull = unsigned long long; #define F first #define S second #define all(x) begin(x), end(x) template <class T> void read_vector(vector<T> &arr) { const int size = arr.size(); for (int i = 0; i < size; ++i) cin >> arr[i]; } // template <class T> // vector<T> create_vector(int n) { // vector<T> v(n); // for (int i = 0; i < size; ++i) cin >> v[i]; // return v; // } void exec() { int n; cin >> n; vector<vector<int>> arr(n, vector<int>(3)); for (int i = 0; i < n; ++i) { cin >> arr[i][0]; cin >> arr[i][1]; cin >> arr[i][2]; } vector<vector<int>> dp(3, vector<int>(n, 0)); dp[0][0] = arr[0][0]; dp[1][0] = arr[0][1]; dp[2][0] = arr[0][2]; for (int i = 1; i < n; ++i) { dp[0][i] = max(dp[0][i], arr[i][0] + max(dp[1][i - 1], dp[2][i - 1])); dp[1][i] = max(dp[1][i], arr[i][1] + max(dp[0][i - 1], dp[2][i - 1])); dp[2][i] = max(dp[2][i], arr[i][2] + max(dp[0][i - 1], dp[1][i - 1])); } cout << max(dp[0].back(), max(dp[1].back(), dp[2].back())) << endl; } int main() { exec(); return 0; }
replace
50
52
50
51
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[11000][3]; int main() { int n; cin >> n; int a[n], b[n], c[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 < 3; j++) { if (i == 0) { if (j == 0) dp[i][j] = a[i]; else if (j == 1) dp[i][j] = b[i]; else if (j == 2) dp[i][j] = c[i]; } else { for (int k = 0; k < 3; k++) { if (j == k) continue; if (j == 0) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i]); else if (j == 1) dp[i][j] = max(dp[i][j], dp[i - 1][k] + b[i]); else if (j == 2) dp[i][j] = max(dp[i][j], dp[i - 1][k] + c[i]); } } } } int ret = 0; ret = max(dp[n - 1][0], dp[n - 1][1]); ret = max(ret, dp[n - 1][2]); cout << ret; }
#include <bits/stdc++.h> using namespace std; int dp[110000][3]; int main() { int n; cin >> n; int a[n], b[n], c[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 < 3; j++) { if (i == 0) { if (j == 0) dp[i][j] = a[i]; else if (j == 1) dp[i][j] = b[i]; else if (j == 2) dp[i][j] = c[i]; } else { for (int k = 0; k < 3; k++) { if (j == k) continue; if (j == 0) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i]); else if (j == 1) dp[i][j] = max(dp[i][j], dp[i - 1][k] + b[i]); else if (j == 2) dp[i][j] = max(dp[i][j], dp[i - 1][k] + c[i]); } } } } int ret = 0; ret = max(dp[n - 1][0], dp[n - 1][1]); ret = max(ret, dp[n - 1][2]); cout << ret; }
replace
2
3
2
3
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[2][3]; int main() { int n; cin >> n; int a[n], b[n], c[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 < 3; j++) { if (i == 0) { if (j == 0) dp[i % 2][j] = a[i]; else if (j == 1) dp[i % 2][j] = b[i]; else if (j == 2) dp[i % 2][j] = c[i]; } else { for (int k = 0; k < 3; k++) { if (j == k) continue; if (j == 0) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + a[i]); else if (j == 1) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + b[i]); else if (j == 2) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + c[i]); } } } } int ret = 0; ret = max(dp[(n - 1) % 2][0], dp[n - 1][1]); ret = max(ret, dp[(n - 1) % 2][2]); cout << ret; }
#include <bits/stdc++.h> using namespace std; int dp[2][3]; int main() { int n; cin >> n; int a[n], b[n], c[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 < 3; j++) { if (i == 0) { if (j == 0) dp[i % 2][j] = a[i]; else if (j == 1) dp[i % 2][j] = b[i]; else if (j == 2) dp[i % 2][j] = c[i]; } else { for (int k = 0; k < 3; k++) { if (j == k) continue; if (j == 0) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + a[i]); else if (j == 1) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + b[i]); else if (j == 2) dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][k] + c[i]); } } } } int ret = 0; ret = max(dp[(n - 1) % 2][0], dp[(n - 1) % 2][1]); ret = max(ret, dp[(n - 1) % 2][2]); cout << ret; }
replace
35
36
35
36
0
p03162
C++
Runtime Error
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int dp[3][10001]; int act[3][10001]; int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> act[0][i] >> act[1][i] >> act[2][i]; } dp[0][1] = act[0][1]; dp[1][1] = act[1][1]; dp[2][1] = act[2][1]; for (int i = 2; i <= N; i++) { dp[0][i] = max(dp[1][i - 1] + act[0][i], dp[2][i - 1] + act[0][i]); dp[1][i] = max(dp[0][i - 1] + act[1][i], dp[2][i - 1] + act[1][i]); dp[2][i] = max(dp[0][i - 1] + act[2][i], dp[1][i - 1] + act[2][i]); } int ret = 0; for (int i = 0; i < 3; i++) { ret = ret > dp[i][N] ? ret : dp[i][N]; } cout << ret << "\n"; return 0; }
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int dp[3][100001]; int act[3][100001]; int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> act[0][i] >> act[1][i] >> act[2][i]; } dp[0][1] = act[0][1]; dp[1][1] = act[1][1]; dp[2][1] = act[2][1]; for (int i = 2; i <= N; i++) { dp[0][i] = max(dp[1][i - 1] + act[0][i], dp[2][i - 1] + act[0][i]); dp[1][i] = max(dp[0][i - 1] + act[1][i], dp[2][i - 1] + act[1][i]); dp[2][i] = max(dp[0][i - 1] + act[2][i], dp[1][i - 1] + act[2][i]); } int ret = 0; for (int i = 0; i < 3; i++) { ret = ret > dp[i][N] ? ret : dp[i][N]; } cout << ret << "\n"; return 0; }
replace
8
10
8
10
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define rep(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define Max(x, y, z) max(x, max(y, z)) #define f first #define s second #define lbd lower_bound #define sz(x) (ll) x.size() #define pi 3.1415926536 #define mod 1000000007 using namespace std; /*void bfs(ll s, vector<vector<ll>> &adj) { dis[s]=0;B vis[s]=1; queue<ll> q; q.push(s); while(!q.empty()) { ll x=q.front(); q.pop(); for(auto to:adj[x]) { if(!vis[to]) {dis[to]=dis[x]+1;q.push(to); vis[to]=1;} } } }*/ void solve() { ll n, m, k, res = 0, l = 0, r = 0, sum = 0, z, sum1 = 0, cnt1 = 0, h, res1, c, x, y; cin >> n; ll ar[n][3]; rep(i, 0, n) rep(j, 0, 3) cin >> ar[i][j]; ll dp[n][3]; dp[0][0] = ar[0][0]; dp[0][1] = ar[0][1]; dp[0][2] = ar[0][2]; if (n > 1) { rep(i, 1, n) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0]; dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + ar[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2]; } } cout << Max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed_up ll t; // cin>>t; t = 1; while (t--) solve(); }
#include <bits/stdc++.h> #define ll long long #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define rep(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define Max(x, y, z) max(x, max(y, z)) #define f first #define s second #define lbd lower_bound #define sz(x) (ll) x.size() #define pi 3.1415926536 #define mod 1000000007 using namespace std; /*void bfs(ll s, vector<vector<ll>> &adj) { dis[s]=0;B vis[s]=1; queue<ll> q; q.push(s); while(!q.empty()) { ll x=q.front(); q.pop(); for(auto to:adj[x]) { if(!vis[to]) {dis[to]=dis[x]+1;q.push(to); vis[to]=1;} } } }*/ void solve() { ll n, m, k, res = 0, l = 0, r = 0, sum = 0, z, sum1 = 0, cnt1 = 0, h, res1, c, x, y; cin >> n; ll ar[n][3]; rep(i, 0, n) rep(j, 0, 3) cin >> ar[i][j]; ll dp[n][3]; dp[0][0] = ar[0][0]; dp[0][1] = ar[0][1]; dp[0][2] = ar[0][2]; if (n > 1) { rep(i, 1, n) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + ar[i][0]; dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + ar[i][1]; dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + ar[i][2]; } } cout << Max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]); } int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ speed_up ll t; // cin>>t; t = 1; while (t--) solve(); }
replace
53
57
53
57
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; #define F first #define S second #define MP make_pair #define PB push_back #define rad(X) cout << (X) << endl #define ASH(X) cout << (X) << " " #define debug(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define FOR(I, A, B) for (int I = (A); I <= (B); I++) #define cir(I, B, A) for (int I = (A); I >= (B); I--) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define SORT(c) (sort(c.begin(), c.end())) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define CASES \ int ___T; \ cin >> ___T; \ for (int cs = 1; cs <= ___T; cs++) #define FAST() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); template <typename T> T gcd(T x, T y) { if (y == 0) return x; else return gcd(y, x % y); } ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1}; ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1}; vector<ll> a, b, c; map<ll, ll> m1, m2, m3; /************************************************/ void Execute() { int n; cin >> n; std::vector<int> dp(3); FOR(day, 1, n) { std::vector<int> v(3); std::vector<int> new_dp(3, 0); FOR(i, 0, 2) { cin >> v[i]; } FOR(i, 0, 2) { FOR(j, 0, 2) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + v[j]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}) << endl; } int32_t main() { #ifndef ONLINE_JUDGE freopen("atomm.txt", "r", stdin); #endif FAST(); // CASES Execute(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; #define F first #define S second #define MP make_pair #define PB push_back #define rad(X) cout << (X) << endl #define ASH(X) cout << (X) << " " #define debug(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define FOR(I, A, B) for (int I = (A); I <= (B); I++) #define cir(I, B, A) for (int I = (A); I >= (B); I--) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define SORT(c) (sort(c.begin(), c.end())) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define CASES \ int ___T; \ cin >> ___T; \ for (int cs = 1; cs <= ___T; cs++) #define FAST() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); template <typename T> T gcd(T x, T y) { if (y == 0) return x; else return gcd(y, x % y); } ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1}; ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1}; vector<ll> a, b, c; map<ll, ll> m1, m2, m3; /************************************************/ void Execute() { int n; cin >> n; std::vector<int> dp(3); FOR(day, 1, n) { std::vector<int> v(3); std::vector<int> new_dp(3, 0); FOR(i, 0, 2) { cin >> v[i]; } FOR(i, 0, 2) { FOR(j, 0, 2) { if (i != j) { new_dp[j] = max(new_dp[j], dp[i] + v[j]); } } } dp = new_dp; } cout << max({dp[0], dp[1], dp[2]}) << endl; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("atomm.txt", "r", stdin); // #endif FAST(); // CASES Execute(); }
replace
65
68
65
68
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; const int oo = 1e9; // const int mod = 1e9+9; /*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); } *ll lcm(ll x, ll y){return x*(y/gcd(x,y));} *void exEuclid(int a, int b){ if(b==0){x = 1; y=0; d=a; return ;} exEuclid(b, a%b); int x1=y; int y1=x-(a/b)*y; x=x1; 100000 y=y1; } * */ //===========================================================// int n; const int nx = 1e5 + 5; int ac[nx][3]; int dp[3][nx]; int go(int a, int i) { if (i == n) return 0; int &ans = dp[a][i]; if (a == 0) { ans = max(ans, go(1, i + 1) + ac[i][0]); ans = max(ans, go(2, i + 1) + ac[i][0]); } if (a == 1) { ans = max(ans, go(0, i + 1) + ac[i][1]); ans = max(ans, go(2, i + 1) + ac[i][1]); } if (a == 2) { ans = max(ans, go(0, i + 1) + ac[i][2]); ans = max(ans, go(1, i + 1) + ac[i][2]); } return ans; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> ac[i][0] >> ac[i][1] >> ac[i][2]; memset(dp, -1, sizeof dp); cout << max(go(0, 0), max(go(1, 0), go(2, 0))) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; const int oo = 1e9; // const int mod = 1e9+9; /*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); } *ll lcm(ll x, ll y){return x*(y/gcd(x,y));} *void exEuclid(int a, int b){ if(b==0){x = 1; y=0; d=a; return ;} exEuclid(b, a%b); int x1=y; int y1=x-(a/b)*y; x=x1; 100000 y=y1; } * */ //===========================================================// int n; const int nx = 1e5 + 5; int ac[nx][3]; int dp[3][nx]; int go(int a, int i) { if (i == n) return 0; if (dp[a][i] != -1) return dp[a][i]; int &ans = dp[a][i]; if (a == 0) { ans = max(ans, go(1, i + 1) + ac[i][0]); ans = max(ans, go(2, i + 1) + ac[i][0]); } if (a == 1) { ans = max(ans, go(0, i + 1) + ac[i][1]); ans = max(ans, go(2, i + 1) + ac[i][1]); } if (a == 2) { ans = max(ans, go(0, i + 1) + ac[i][2]); ans = max(ans, go(1, i + 1) + ac[i][2]); } return ans; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> ac[i][0] >> ac[i][1] >> ac[i][2]; memset(dp, -1, sizeof dp); cout << max(go(0, 0), max(go(1, 0), go(2, 0))) << "\n"; return 0; }
insert
26
26
26
28
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define MAX 1e9 using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main(void) { int n; cin >> n; ll happy_arr[10][3]; ll dp_arr[10][3]; for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> happy_arr[i][j]; } } for (int i = 0; i < 3; ++i) { dp_arr[0][i] = 0; } for (int i = 1; i <= n; ++i) { dp_arr[i][0] = happy_arr[i - 1][0] + max(dp_arr[i - 1][1], dp_arr[i - 1][2]); dp_arr[i][1] = happy_arr[i - 1][1] + max(dp_arr[i - 1][0], dp_arr[i - 1][2]); dp_arr[i][2] = happy_arr[i - 1][2] + max(dp_arr[i - 1][0], dp_arr[i - 1][1]); } ll max = 0; for (int i = 0; i < 3; ++i) { chmax(max, dp_arr[n][i]); } cout << max << endl; return 0; }
#include <bits/stdc++.h> #define MAX 1e9 using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main(void) { int n; cin >> n; ll happy_arr[100010][3]; ll dp_arr[100010][3]; for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> happy_arr[i][j]; } } for (int i = 0; i < 3; ++i) { dp_arr[0][i] = 0; } for (int i = 1; i <= n; ++i) { dp_arr[i][0] = happy_arr[i - 1][0] + max(dp_arr[i - 1][1], dp_arr[i - 1][2]); dp_arr[i][1] = happy_arr[i - 1][1] + max(dp_arr[i - 1][0], dp_arr[i - 1][2]); dp_arr[i][2] = happy_arr[i - 1][2] + max(dp_arr[i - 1][0], dp_arr[i - 1][1]); } ll max = 0; for (int i = 0; i < 3; ++i) { chmax(max, dp_arr[n][i]); } cout << max << endl; return 0; }
replace
17
19
17
19
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; int main() { int a[10][3]; int dp[10][3]; int N; cin >> N; rep(i, N) rep(j, 3) cin >> a[i][j]; rep(i, N + 1) rep(j, 3) dp[i][j] = 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] + a[i][k]); } } } int res = 0; rep(i, 3) res = max(res, dp[N][i]); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; int main() { int a[100010][3]; int dp[100010][3]; int N; cin >> N; rep(i, N) rep(j, 3) cin >> a[i][j]; rep(i, N + 1) rep(j, 3) dp[i][j] = 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] + a[i][k]); } } } int res = 0; rep(i, 3) res = max(res, dp[N][i]); cout << res << endl; return 0; }
replace
7
9
7
9
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < (b); i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf = 1 << 20; const int mod = 1e9 + 7; 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 dp[10005][5]; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0]; rep(i, 0, n - 1) { chmax(dp[i + 1][0], dp[i][1] + a[i + 1]); chmax(dp[i + 1][0], dp[i][2] + a[i + 1]); chmax(dp[i + 1][1], dp[i][0] + b[i + 1]); chmax(dp[i + 1][1], dp[i][2] + b[i + 1]); chmax(dp[i + 1][2], dp[i][0] + c[i + 1]); chmax(dp[i + 1][2], dp[i][1] + c[i + 1]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < (b); i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf = 1 << 20; const int mod = 1e9 + 7; 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 dp[100005][5]; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i]; dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0]; rep(i, 0, n - 1) { chmax(dp[i + 1][0], dp[i][1] + a[i + 1]); chmax(dp[i + 1][0], dp[i][2] + a[i + 1]); chmax(dp[i + 1][1], dp[i][0] + b[i + 1]); chmax(dp[i + 1][1], dp[i][2] + b[i + 1]); chmax(dp[i + 1][2], dp[i][0] + c[i + 1]); chmax(dp[i + 1][2], dp[i][1] + c[i + 1]); } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl; return 0; }
replace
25
26
25
26
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define show(x) cout << (#x) << " : " << x << endl; #define ll long long #define int long long #define ld long double #define fill(a, val) memset(a, val, sizeof(a)) #define mp make_pair #define ff first #define ss second #define pii pair<ll, ll> #define sq(x) ((x) * (x)) #define all(v) v.begin(), v.end() #define fone for (i = 0; i < n; i++) #define endl "\n" const ll MOD = 1000 * 1000 * 1000 + 7; const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const ll MOD2 = 998244353; const ll N = 5000 * 100 + 1; const ll N2 = 1000 * 1000 + 5; const ld PI = 3.14159265; const ll R = 250; ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } signed main() { fastio(); int n, k; cin >> n; int a[n], b[n], c[n]; int dp[1000][1000]; ; fill(dp, 0); 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] + 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][1] + c[i], dp[i - 1][0] + c[i]); } 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; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define show(x) cout << (#x) << " : " << x << endl; #define ll long long #define int long long #define ld long double #define fill(a, val) memset(a, val, sizeof(a)) #define mp make_pair #define ff first #define ss second #define pii pair<ll, ll> #define sq(x) ((x) * (x)) #define all(v) v.begin(), v.end() #define fone for (i = 0; i < n; i++) #define endl "\n" const ll MOD = 1000 * 1000 * 1000 + 7; const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const ll MOD2 = 998244353; const ll N = 5000 * 100 + 1; const ll N2 = 1000 * 1000 + 5; const ld PI = 3.14159265; const ll R = 250; ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } signed main() { fastio(); int n, k; cin >> n; int a[n], b[n], c[n]; int dp[100000][3]; ; fill(dp, 0); 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] + 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][1] + c[i], dp[i - 1][0] + c[i]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl; return 0; }
replace
53
54
53
54
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #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 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--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void dk() { 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() { dk(); int n; cin >> n; int a[3]; int dp[3]; int t[3]; memset(dp, 0, sizeof dp); memset(t, 0, sizeof t); for (int i = 0; i < n; i++) { cin >> a[0] >> a[1] >> a[2]; for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { if (k != j) { t[j] = max(t[j], dp[k] + a[j]); } } } dp[0] = t[0]; dp[1] = t[1]; dp[2] = t[2]; } cout << max(dp[0], max(dp[1], dp[2])); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #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 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--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void dk() { 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() { // dk(); int n; cin >> n; int a[3]; int dp[3]; int t[3]; memset(dp, 0, sizeof dp); memset(t, 0, sizeof t); for (int i = 0; i < n; i++) { cin >> a[0] >> a[1] >> a[2]; for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { if (k != j) { t[j] = max(t[j], dp[k] + a[j]); } } } dp[0] = t[0]; dp[1] = t[1]; dp[2] = t[2]; } cout << max(dp[0], max(dp[1], dp[2])); return 0; }
replace
42
43
42
43
TLE
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if (!(p)) #define until(p) while (!(p)) using ll = long long; using P = std::tuple<int, int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int N; int A[100100][3]; int dp[100100][3]; int rec(int d, int p) { if (d == N) { return 0; } int res = 0; for (int n = 0; n < 3; ++n) { if (d > 0 && n == p) { continue; } res = std::max(res, A[d][n] + rec(d + 1, n)); } return dp[d][p] = res; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for (int i = 0; i < N; ++i) { std::cin >> A[i][0] >> A[i][1] >> A[i][2]; } memset(dp, -1, sizeof(dp)); int res = rec(0, 0); std::cout << res << std::endl; }
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if (!(p)) #define until(p) while (!(p)) using ll = long long; using P = std::tuple<int, int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int N; int A[100100][3]; int dp[100100][3]; int rec(int d, int p) { if (d == N) { return 0; } if (dp[d][p] != -1) { return dp[d][p]; } int res = 0; for (int n = 0; n < 3; ++n) { if (d > 0 && n == p) { continue; } res = std::max(res, A[d][n] + rec(d + 1, n)); } return dp[d][p] = res; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for (int i = 0; i < N; ++i) { std::cin >> A[i][0] >> A[i][1] >> A[i][2]; } memset(dp, -1, sizeof(dp)); int res = rec(0, 0); std::cout << res << std::endl; }
insert
23
23
23
27
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, f, n) for (ll i = (f); (i) < (n); i++) #define repe(i, f, n) for (ll i = (f); (i) <= (n); i++) using namespace std; using ll = long long; ll INF = 1e+18; int iINF = 1e9; int MAXI = 1e8 + 1; using vec = vector<int>; int main() { int N; cin >> N; vector<vector<int>> arr(N); rep(i, 0, N) { int a, b, c; cin >> a >> b >> c; arr[i].push_back(a); arr[i].push_back(b); arr[i].push_back(c); } vector<vector<int>> dp(N, vec(3, 0)); dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2]; rep(i, 0, N - 1) { rep(j, 0, 3) { rep(k, 0, 3) { if (j == k) continue; if (dp[j + 1][k] < dp[i][j] + arr[i + 1][k]) dp[i + 1][k] = dp[i][j] + arr[i + 1][k]; } } } int ans = 0; rep(i, 0, 3) { if (dp[N - 1][i] > ans) ans = dp[N - 1][i]; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, f, n) for (ll i = (f); (i) < (n); i++) #define repe(i, f, n) for (ll i = (f); (i) <= (n); i++) using namespace std; using ll = long long; ll INF = 1e+18; int iINF = 1e9; int MAXI = 1e8 + 1; using vec = vector<int>; int main() { int N; cin >> N; vector<vector<int>> arr(N); rep(i, 0, N) { int a, b, c; cin >> a >> b >> c; arr[i].push_back(a); arr[i].push_back(b); arr[i].push_back(c); } vector<vector<int>> dp(N, vec(3, 0)); dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2]; rep(i, 0, N - 1) { rep(j, 0, 3) { rep(k, 0, 3) { if (j == k) continue; if (dp[i + 1][k] < dp[i][j] + arr[i + 1][k]) dp[i + 1][k] = dp[i][j] + arr[i + 1][k]; } } } int ans = 0; rep(i, 0, 3) { if (dp[N - 1][i] > ans) ans = dp[N - 1][i]; } cout << ans << endl; }
replace
32
33
32
33
-11
p03162
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; bool **v; int **dp; int *a, *b, *c; int solve(int n, const int &max, char last) { if (n == max) return 0; if (v[n][last]) return dp[n][last]; int score_a = last == 'a' ? 0 : solve(n + 1, max, 'a') + a[n]; int score_b = last == 'b' ? 0 : solve(n + 1, max, 'b') + b[n]; int score_c = last == 'c' ? 0 : solve(n + 1, max, 'c') + c[n]; dp[n][last] = std::max({score_a, score_b, score_c}); v[n][last] = 1; return dp[n][last]; } int main() { int N; cin >> N; v = new bool *[N]; a = new int[N]; b = new int[N]; c = new int[N]; dp = new int *[N]; for (int i = 0; i < N; i++) { v[i] = new bool[3]; dp[i] = new int[3]; cin >> a[i]; cin >> b[i]; cin >> c[i]; } fill(&dp[0][0], &dp[0][0] + sizeof(dp), 0); fill(&v[0][0], &v[0][0] + sizeof(v), 0); cout << solve(0, N, 0) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; bool **v; int **dp; int *a, *b, *c; int solve(int n, const int &max, char last) { if (n == max) return 0; if (v[n][last]) return dp[n][last]; int score_a = last == 'a' ? 0 : solve(n + 1, max, 'a') + a[n]; int score_b = last == 'b' ? 0 : solve(n + 1, max, 'b') + b[n]; int score_c = last == 'c' ? 0 : solve(n + 1, max, 'c') + c[n]; dp[n][last] = std::max({score_a, score_b, score_c}); v[n][last] = 1; return dp[n][last]; } int main() { int N; cin >> N; v = new bool *[N]; a = new int[N]; b = new int[N]; c = new int[N]; dp = new int *[N]; for (int i = 0; i < N; i++) { v[i] = new bool[3]; dp[i] = new int[3]; cin >> a[i]; cin >> b[i]; cin >> c[i]; } // fill(&dp[0][0], &dp[0][0] + sizeof(dp), 0); // fill(&v[0][0], &v[0][0] + sizeof(v), 0); cout << solve(0, N, 0) << endl; return 0; }
replace
41
43
41
43
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll n; ll func(ll a[][4]) { ll h[n + 1][4]; h[1][1] = a[1][1]; h[1][2] = a[1][2]; h[1][3] = a[1][3]; for (ll i = 2; i <= n; i++) { h[i][1] = a[i][1] + max(h[i - 1][2], h[i - 1][3]); h[i][2] = a[i][2] + max(h[i - 1][3], h[i - 1][1]); h[i][3] = a[i][3] + max(h[i - 1][1], h[i - 1][2]); } cout << max(h[n][1], max(h[n][2], h[n][3])); } int32_t main() { IOS; cin >> n; ll a[n + 1][4]; for (ll i = 1; i <= n; i++) { cin >> a[i][1] >> a[i][2] >> a[i][3]; } func(a); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll n; void func(ll a[][4]) { ll h[n + 1][4]; h[1][1] = a[1][1]; h[1][2] = a[1][2]; h[1][3] = a[1][3]; for (ll i = 2; i <= n; i++) { h[i][1] = a[i][1] + max(h[i - 1][2], h[i - 1][3]); h[i][2] = a[i][2] + max(h[i - 1][3], h[i - 1][1]); h[i][3] = a[i][3] + max(h[i - 1][1], h[i - 1][2]); } cout << max(h[n][1], max(h[n][2], h[n][3])); } int32_t main() { IOS; cin >> n; ll a[n + 1][4]; for (ll i = 1; i <= n; i++) { cin >> a[i][1] >> a[i][2] >> a[i][3]; } func(a); }
replace
9
10
9
10
0
p03162
C++
Runtime Error
#include <iostream> using namespace std; long n, a[10000][10000], f[10000][10000]; int main() { cin >> n; for (long i = 1; i <= n; i++) { for (long j = 1; j <= 3; j++) cin >> a[i][j]; } f[0][1] = 0; f[0][2] = 0; f[0][3] = 0; for (long i = 1; i <= n; i++) { for (long j = 1; j <= 3; j++) { if (j == 1) { f[i][j] = max(a[i][j] + f[i - 1][j + 1], a[i][j] + f[i - 1][j + 2]); } if (j == 2) { f[i][j] = max(a[i][j] + f[i - 1][j - 1], a[i][j] + f[i - 1][j + 1]); } if (j == 3) { f[i][j] = max(a[i][j] + f[i - 1][j - 1], a[i][j] + f[i - 1][j - 2]); } } } cout << max(f[n][1], max(f[n][2], f[n][3])); return 0; }
#include <iostream> using namespace std; long n, a[100005][4], f[100005][4]; int main() { cin >> n; for (long i = 1; i <= n; i++) { for (long j = 1; j <= 3; j++) cin >> a[i][j]; } f[0][1] = 0; f[0][2] = 0; f[0][3] = 0; for (long i = 1; i <= n; i++) { for (long j = 1; j <= 3; j++) { if (j == 1) { f[i][j] = max(a[i][j] + f[i - 1][j + 1], a[i][j] + f[i - 1][j + 2]); } if (j == 2) { f[i][j] = max(a[i][j] + f[i - 1][j - 1], a[i][j] + f[i - 1][j + 1]); } if (j == 3) { f[i][j] = max(a[i][j] + f[i - 1][j - 1], a[i][j] + f[i - 1][j - 2]); } } } cout << max(f[n][1], max(f[n][2], f[n][3])); return 0; }
replace
3
4
3
4
-11
p03162
C++
Runtime Error
#include <cmath> #include <iostream> using namespace std; int other[3][2] = {{1, 2}, {0, 2}, {1, 0}}; int getDp(int data[][3], int i, int choice, int dp[][3]) { if (dp[i][choice] != -1) { return dp[i][choice]; } for (int j = 0; j < 2; j++) { dp[i][choice] = max(data[i][choice] + getDp(data, i - 1, other[choice][j], dp), dp[i][choice]); } return dp[i][choice]; } int main() { int N; cin >> N; int data[N][3]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> data[i][j]; } } int dp[N][3]; for (int i = 0; i < 3; i++) { dp[0][i] = data[0][i]; } for (int i = 1; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -1; } } for (int i = 0; i < 3; i++) { getDp(data, N - 1, i, dp); } cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])); return 2; }
#include <cmath> #include <iostream> using namespace std; int other[3][2] = {{1, 2}, {0, 2}, {1, 0}}; int getDp(int data[][3], int i, int choice, int dp[][3]) { if (dp[i][choice] != -1) { return dp[i][choice]; } for (int j = 0; j < 2; j++) { dp[i][choice] = max(data[i][choice] + getDp(data, i - 1, other[choice][j], dp), dp[i][choice]); } return dp[i][choice]; } int main() { int N; cin >> N; int data[N][3]; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { cin >> data[i][j]; } } int dp[N][3]; for (int i = 0; i < 3; i++) { dp[0][i] = data[0][i]; } for (int i = 1; i < N; i++) { for (int j = 0; j < 3; j++) { dp[i][j] = -1; } } for (int i = 0; i < 3; i++) { getDp(data, N - 1, i, dp); } cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])); return 0; }
replace
43
44
43
44
2
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long typedef long double ld; #define pb push_back #define f(i, a, b) for (int i = a; i < b; i++) #define fd(i, a, b) for (int i = a - 1; i >= b; i--) #define pf push_front #define fi first #define se second #define INF 1e12 const int mod = 1e9 + 7; int cnt = 0; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("INPUT.txt", "r", stdin); // for writing output to output.txt freopen("OUTPUT.txt", "w", stdout); #endif // -------------------------------------Code starts // here--------------------------------------------------------------------- int t = 1; // cin>>t; while (t--) { int n; cin >> n; int a[n][3]; f(i, 0, n) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } int dp[n][3]; f(i, 0, n) f(j, 0, 3) dp[i][j] = 0; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; f(i, 1, n) { 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> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long typedef long double ld; #define pb push_back #define f(i, a, b) for (int i = a; i < b; i++) #define fd(i, a, b) for (int i = a - 1; i >= b; i--) #define pf push_front #define fi first #define se second #define INF 1e12 const int mod = 1e9 + 7; int cnt = 0; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /* #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("INPUT.txt", "r", stdin); // for writing output to output.txt freopen("OUTPUT.txt", "w", stdout); #endif*/ // -------------------------------------Code starts // here--------------------------------------------------------------------- int t = 1; // cin>>t; while (t--) { int n; cin >> n; int a[n][3]; f(i, 0, n) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } int dp[n][3]; f(i, 0, n) f(j, 0, 3) dp[i][j] = 0; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2]; f(i, 1, n) { 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
23
29
23
29
-11
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; // using P = pair<int, int>; ll dp[10005][3]; int main() { int n; cin >> n; vector<ll> a(n), b(n), c(n); rep(i, n) cin >> a[i] >> b[i] >> c[i]; for (int i = 1; i <= n; ++i) { dp[i][0] = max(dp[i - 1][1] + a[i - 1], dp[i - 1][2] + a[i - 1]); dp[i][1] = max(dp[i - 1][0] + b[i - 1], dp[i - 1][2] + b[i - 1]); dp[i][2] = max(dp[i - 1][0] + c[i - 1], dp[i - 1][1] + c[i - 1]); } ll ans = max(dp[n][0], dp[n][1]); ans = max(ans, dp[n][2]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; // using P = pair<int, int>; ll dp[100005][3]; int main() { int n; cin >> n; vector<ll> a(n), b(n), c(n); rep(i, n) cin >> a[i] >> b[i] >> c[i]; for (int i = 1; i <= n; ++i) { dp[i][0] = max(dp[i - 1][1] + a[i - 1], dp[i - 1][2] + a[i - 1]); dp[i][1] = max(dp[i - 1][0] + b[i - 1], dp[i - 1][2] + b[i - 1]); dp[i][2] = max(dp[i - 1][0] + c[i - 1], dp[i - 1][1] + c[i - 1]); } ll ans = max(dp[n][0], dp[n][1]); ans = max(ans, dp[n][2]); cout << ans << endl; return 0; }
replace
6
7
6
7
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define setbits(x) __builtin_popcountll(x) #define endl "\n" #define ll long long int decimalsum(int x) { int sum = 0; while (x) { sum += x % 10; x = x / 10; } return sum; } int rec(vector<vector<int>> dp, int n, vector<vector<int>> a, int x, int p) { if (x == n) return 0; if (dp[x][p] != -1) return dp[x][p]; return dp[x][p] = max(rec(dp, n, a, x + 1, (p + 1) % 3) + a[x][(p + 1) % 3], rec(dp, n, a, x + 1, (p + 2) % 3) + a[x][(p + 2) % 3]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // int php[4000] , cdc[8000], cdm[8000]; // for(int j=0;j<5;j++){ // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // // int t; // cin>>t; // while(t--) { // solve(); int n; cin >> n; vector<vector<int>> dp(n, vector<int>(3, -1)); vector<vector<int>> a(n, vector<int>(3, -1)); for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } int ans = 0; ans = max(rec(dp, n, a, 1, 0) + a[0][0], rec(dp, n, a, 1, 1) + a[0][1]); ans = max(ans, rec(dp, n, a, 1, 2) + a[0][2]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define setbits(x) __builtin_popcountll(x) #define endl "\n" #define ll long long int decimalsum(int x) { int sum = 0; while (x) { sum += x % 10; x = x / 10; } return sum; } int rec(vector<vector<int>> dp, int n, vector<vector<int>> a, int x, int p) { if (x == n) return 0; if (dp[x][p] != -1) return dp[x][p]; return dp[x][p] = max(rec(dp, n, a, x + 1, (p + 1) % 3) + a[x][(p + 1) % 3], rec(dp, n, a, x + 1, (p + 2) % 3) + a[x][(p + 2) % 3]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // int php[4000] , cdc[8000], cdm[8000]; // for(int j=0;j<5;j++){ // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // for(int i=0;i<2000;i++)php[i/10]=1; // // int t; // cin>>t; // while(t--) { // solve(); int n; cin >> n; vector<vector<int>> dp(n, vector<int>(3, -1)); vector<vector<int>> a(n, vector<int>(3, -1)); for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } int ans = 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] = 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][1], dp[i - 1][0]); } ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); cout << ans << endl; } return 0; }
replace
53
55
53
62
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define mo 1000000007 using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int add(int a, int b) { a %= mo; b %= mo; return (a + b) % mo; } int mul(int a, int b) { a %= mo; b %= mo; return (a * b) % mo; } int32_t 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); // let's begin long long n; cin >> n; vector<long long> dp(3); for (int days = 0; days < n; days++) { vector<long long> curr_dp(3, 0); vector<long long> cost(3); for (int i = 0; i < 3; i++) { cin >> cost[i]; } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i != j) { curr_dp[j] = max(curr_dp[j], dp[i] + cost[j]); } } } dp = curr_dp; } cout << max(dp[0], max(dp[1], dp[2])) << "\n"; return 0; }
#include <bits/stdc++.h> #define mo 1000000007 using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int add(int a, int b) { a %= mo; b %= mo; return (a + b) % mo; } int mul(int a, int b) { a %= mo; b %= mo; return (a * b) % mo; } int32_t 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); // let's begin long long n; cin >> n; vector<long long> dp(3); for (int days = 0; days < n; days++) { vector<long long> curr_dp(3, 0); vector<long long> cost(3); for (int i = 0; i < 3; i++) { cin >> cost[i]; } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i != j) { curr_dp[j] = max(curr_dp[j], dp[i] + cost[j]); } } } dp = curr_dp; } cout << max(dp[0], max(dp[1], dp[2])) << "\n"; return 0; }
replace
26
30
26
30
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> using namespace std; #define endl '\n' #define ll long long #define int long long const int32_t INFint = 1e9; const ll INFll = 1e18; #define MOD 1000000007ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define vi vector<int> #define pii pair<int, int> #define pb push_back #define mp make_pair #define ff first #define ss second #define foreach(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #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 deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define For(i, a, b) for (ll i = a; i < b; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define all(v) v.begin(), v.end() #define gll(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define gint(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define setZero(a, n) \ for (int i = 0; i < n; i++) \ a[i] = 0; #define printArray(a, s, e) \ for (int i = s; i < e; i++) { \ cout << a[i] << " "; \ } \ cout << endl; //--------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------------- int32_t main() { fast; int t; // cin >> t; t = 1; while (t--) { int n; cin >> n; int arr[n][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> arr[i][j]; int dp[n][n]; for (int i = 0; i < 3; i++) dp[0][i] = arr[0][i]; for (int i = 1; i < n; i++) { dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = arr[i][2] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); } }
#include <bits/stdc++.h> #include <unordered_map> using namespace std; #define endl '\n' #define ll long long #define int long long const int32_t INFint = 1e9; const ll INFll = 1e18; #define MOD 1000000007ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define vi vector<int> #define pii pair<int, int> #define pb push_back #define mp make_pair #define ff first #define ss second #define foreach(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #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 deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define For(i, a, b) for (ll i = a; i < b; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define all(v) v.begin(), v.end() #define gll(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define gint(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define setZero(a, n) \ for (int i = 0; i < n; i++) \ a[i] = 0; #define printArray(a, s, e) \ for (int i = s; i < e; i++) { \ cout << a[i] << " "; \ } \ cout << endl; //--------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------------- int32_t main() { fast; int t; // cin >> t; t = 1; while (t--) { int n; cin >> n; int arr[n][3]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> arr[i][j]; int dp[n][3]; for (int i = 0; i < 3; i++) dp[0][i] = arr[0][i]; for (int i = 1; i < n; i++) { dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]); dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]); dp[i][2] = arr[i][2] + max(dp[i - 1][1], dp[i - 1][0]); } cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); } }
replace
75
76
75
76
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vec; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int, int> par; typedef vector<par> vpar; #define forn(i, n) for (ll i = 0; i < n; i++) #define wez(n) \ ll(n); \ cin >> (n); #define setmax(a, b) (a) = max((a), (b)) #define setmin(a, b) (a) = min((a), (b)) #define pb push_back #define mp make_pair #define outa(a, e) forn(i, e) cout << a[i] << (i == e - 1 ? '\n' : ' ') #define oute(n) cout << n << "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ wez(n); vector<ll> dp(3, 0); forn(i, n) { vector<ll> new_dp(3, 0); vector<int> cost(3); forn(j, 3) cin >> cost[j]; forn(j, 3) { forn(k, 3) { if (j != k) { new_dp[j] = max(new_dp[j], dp[i] + cost[j]); } } } dp = new_dp; } cout << max(dp[0], max(dp[1], dp[2])); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vec; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int, int> par; typedef vector<par> vpar; #define forn(i, n) for (ll i = 0; i < n; i++) #define wez(n) \ ll(n); \ cin >> (n); #define setmax(a, b) (a) = max((a), (b)) #define setmin(a, b) (a) = min((a), (b)) #define pb push_back #define mp make_pair #define outa(a, e) forn(i, e) cout << a[i] << (i == e - 1 ? '\n' : ' ') #define oute(n) cout << n << "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ wez(n); vector<ll> dp(3, 0); forn(i, n) { vector<ll> new_dp(3, 0); vector<int> cost(3); forn(j, 3) cin >> cost[j]; forn(j, 3) { forn(k, 3) { if (j != k) { new_dp[k] = max(new_dp[k], dp[j] + cost[k]); } } } dp = new_dp; } cout << max(dp[0], max(dp[1], dp[2])); return 0; }
replace
37
38
37
38
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int vis[MAXN][3], dp[MAXN][3], N, A[3][MAXN]; int solve(int pos, int last) { if (pos == N + 1) return 0; if (vis[pos][last]) return dp[pos][last]; int best = 0; for (int i = 0; i < 3; i++) { if (i != last) best = max(best, A[i][pos] + solve(pos + 1, i)); } return dp[pos][last] = best; } int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d %d %d", &A[0][i], &A[1][i], &A[2][i]); } printf("%d\n", max(solve(1, 0), max(solve(1, 1), solve(1, 2)))); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int vis[MAXN][3], dp[MAXN][3], N, A[3][MAXN]; int solve(int pos, int last) { if (pos == N + 1) return 0; if (vis[pos][last]) return dp[pos][last]; vis[pos][last] = 1; int best = 0; for (int i = 0; i < 3; i++) { if (i != last) best = max(best, A[i][pos] + solve(pos + 1, i)); } return dp[pos][last] = best; } int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d %d %d", &A[0][i], &A[1][i], &A[2][i]); } printf("%d\n", max(solve(1, 0), max(solve(1, 1), solve(1, 2)))); return 0; }
insert
14
14
14
15
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 123; int dp[mx][4], n; int a[mx][4]; int solve(int i, int f1) { if (i > n) return 0; if (dp[i][f1] != -1) return dp[i][f1]; int ret = 0; for (int j = 1; j <= n; j++) { if (j != f1) { ret = max(ret, a[i][j] + solve(i + 1, j)); } } return dp[i][f1] = ret; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2] >> a[i][3]; memset(dp, -1, sizeof(dp)); cout << solve(0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 123; int dp[mx][4], n; int a[mx][4]; int solve(int i, int f1) { if (i > n) return 0; if (dp[i][f1] != -1) return dp[i][f1]; int ret = 0; for (int j = 1; j <= 3; j++) { if (j != f1) { ret = max(ret, a[i][j] + solve(i + 1, j)); } } return dp[i][f1] = ret; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2] >> a[i][3]; memset(dp, -1, sizeof(dp)); cout << solve(0, 0) << endl; }
replace
14
15
14
15
0
p03162
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t, y = 1; // cin>>t; t = 1; while (t > 0) { t--; ll n, i, j, k, flag = 1, x = 0; cin >> n; ll a = 0, b = 0, c = 0; ll dp[(ll)1e5][3]; for (i = 1; i <= n; i++) { cin >> a >> b >> c; dp[i][1] = max(dp[i - 1][2] + a, dp[i - 1][3] + a); dp[i][2] = max(dp[i - 1][1] + b, dp[i - 1][3] + b); dp[i][3] = max(dp[i - 1][2] + c, dp[i - 1][1] + c); } x = max(dp[n][1], dp[n][2]); x = max(x, dp[n][3]); cout << x; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t, y = 1; // cin>>t; t = 1; while (t > 0) { t--; ll n, i, j, k, flag = 1, x = 0; cin >> n; ll a = 0, b = 0, c = 0; ll dp[(ll)1e5 + 1][3]; for (i = 1; i <= n; i++) { cin >> a >> b >> c; dp[i][1] = max(dp[i - 1][2] + a, dp[i - 1][3] + a); dp[i][2] = max(dp[i - 1][1] + b, dp[i - 1][3] + b); dp[i][3] = max(dp[i - 1][2] + c, dp[i - 1][1] + c); } x = max(dp[n][1], dp[n][2]); x = max(x, dp[n][3]); cout << x; } return 0; }
replace
15
16
15
16
0
p03162
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; using graph = vector<vector<int>>; const ll mod = pow(10, 9) + 7; const int INF = 1e9; const ll LINF = 1e18; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int dp[11000][3]; int a[11000], b[11000], c[11000]; int main() { int N; cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, N) { rep(j, 3) { dp[i][j] = 0; } } dp[0][0] += a[0], dp[0][1] += b[0]; dp[0][2] += c[0]; rep(i, N) { if (i != 0) { chmax(dp[i][0], max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i])); chmax(dp[i][1], max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i])); chmax(dp[i][2], max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i])); } } ll ans = max((ll)dp[N - 1][0], (ll)dp[N - 1][1]); ans = max(ans, (ll)dp[N - 1][2]); cout << ans << endl; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; using graph = vector<vector<int>>; const ll mod = pow(10, 9) + 7; const int INF = 1e9; const ll LINF = 1e18; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int dp[110000][3]; int a[110000], b[110000], c[110000]; int main() { int N; cin >> N; rep(i, N) { cin >> a[i] >> b[i] >> c[i]; } rep(i, N) { rep(j, 3) { dp[i][j] = 0; } } dp[0][0] += a[0], dp[0][1] += b[0]; dp[0][2] += c[0]; rep(i, N) { if (i != 0) { chmax(dp[i][0], max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i])); chmax(dp[i][1], max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i])); chmax(dp[i][2], max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i])); } } ll ans = max((ll)dp[N - 1][0], (ll)dp[N - 1][1]); ans = max(ans, (ll)dp[N - 1][2]); cout << ans << endl; }
replace
34
36
34
36
0
p03162
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <fstream> using namespace std; #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--) #define be(x) (x.begin(), x.end()) #define pb(t) push_back(t) #define ll long long int n; int dp[100005][4]; vector<vector<int>> A; int minicost(int v, int pre) { if (v >= n) return 0; if (dp[v][pre] != -1) return dp[v][pre]; int maxi = 0; if (pre != 0) { maxi = max(maxi, A[v][0] + minicost(v + 1, 0)); } if (pre != 1) { maxi = max(maxi, A[v][1] + minicost(v + 1, 1)); } if (pre != 2) { maxi = max(maxi, A[v][2] + minicost(v + 1, 2)); } return maxi; } int main() { cin >> n; A.resize(n); memset(dp, -1, sizeof(dp)); rep(i, 0, n) { A[i].resize(3); cin >> A[i][0] >> A[i][1] >> A[i][2]; } cout << minicost(0, 3); }
#include <bits/stdc++.h> #include <fstream> using namespace std; #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--) #define be(x) (x.begin(), x.end()) #define pb(t) push_back(t) #define ll long long int n; int dp[100005][4]; vector<vector<int>> A; int minicost(int v, int pre) { if (v >= n) return 0; if (dp[v][pre] != -1) return dp[v][pre]; int maxi = 0; if (pre != 0) { maxi = max(maxi, A[v][0] + minicost(v + 1, 0)); } if (pre != 1) { maxi = max(maxi, A[v][1] + minicost(v + 1, 1)); } if (pre != 2) { maxi = max(maxi, A[v][2] + minicost(v + 1, 2)); } return dp[v][pre] = maxi; } int main() { cin >> n; A.resize(n); memset(dp, -1, sizeof(dp)); rep(i, 0, n) { A[i].resize(3); cin >> A[i][0] >> A[i][1] >> A[i][2]; } cout << minicost(0, 3); }
replace
26
27
26
27
TLE
p03162
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; int arr[10010][10010]; int dp[10010][10010]; signed main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } for (int i = 0; i < 3; i++) { dp[0][i] = arr[0][i]; } for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0]); dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1]); dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2]); } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << "\n"; }
#include <bits/stdc++.h> #define int long long using namespace std; int arr[100100][4]; int dp[100100][4]; signed main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } for (int i = 0; i < 3; i++) { dp[0][i] = arr[0][i]; } for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0]); dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1]); dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2]); } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << "\n"; }
replace
3
5
3
5
-11
p03162
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define lli long long int #define f first #define s second #define sc(n) scanf("%d", &n); #define scl(n) scanf("%lld", &n); #define pr(n) printf("%d", n); #define prl(n) printf("%lld", n); #define nl printf("\n"); #define all(c) (c).begin(), (c).end() #define sz(a) int((a).size()) #define FN(i, n) for (int i = 0; i < (int)(n); ++i) #define FEN(i, n) for (int i = 1; i <= (int)(n); ++i) #define rep(i, a, b) for (int i = a; i < b; i++) #define tr(c, i) for (typeof((c).begin() i = (c).begin(); i != (c).end(); i++)) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { int n; cin >> n; int arr[11111][3]; int ans[11111]; for (int i = 1; i <= n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } int x, y, z; x = 0; y = 0; z = 0; for (int i = 1; i <= n; i++) { int x1, y1, z1; x1 = x; y1 = y; z1 = z; x = arr[i][0] + max(y1, z1); y = arr[i][1] + max(x1, z1); z = arr[i][2] + max(y1, x1); ans[i] = max(x, max(y, z)); } cout << ans[n]; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define lli long long int #define f first #define s second #define sc(n) scanf("%d", &n); #define scl(n) scanf("%lld", &n); #define pr(n) printf("%d", n); #define prl(n) printf("%lld", n); #define nl printf("\n"); #define all(c) (c).begin(), (c).end() #define sz(a) int((a).size()) #define FN(i, n) for (int i = 0; i < (int)(n); ++i) #define FEN(i, n) for (int i = 1; i <= (int)(n); ++i) #define rep(i, a, b) for (int i = a; i < b; i++) #define tr(c, i) for (typeof((c).begin() i = (c).begin(); i != (c).end(); i++)) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { int n; cin >> n; int arr[111111][3]; int ans[111111]; for (int i = 1; i <= n; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; } int x, y, z; x = 0; y = 0; z = 0; for (int i = 1; i <= n; i++) { int x1, y1, z1; x1 = x; y1 = y; z1 = z; x = arr[i][0] + max(y1, z1); y = arr[i][1] + max(x1, z1); z = arr[i][2] + max(y1, x1); ans[i] = max(x, max(y, z)); } cout << ans[n]; }
replace
55
57
55
57
0