// #include <bits/stdc++.h>
#include <vector>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <unordered_map>
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define inp1(a) scanf("%d",&a)
#define inp2(a,b) scanf("%d%d",&a,&b)
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)z
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vector<int> > vvi;
typedef pair<int,pair<int,int> > piii;
typedef pair<pii,pii> piiii;
typedef vector<piii> viii;
const double EPSILON = 1e-9;
const double PI = acos(-1);
const int MOD = 1000000007;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 102;
int N;
int cost[200003][3];
vi DAG[200003];
int visisted[200003];
vi v;
ll dp[200003][2];
void dfs(int here){
if(visisted[here]) return;
visisted[here]=1;
for(int there : DAG[here]) dfs(there);
v.pb(here);
}
ll solve(int pos, int prevGone){
if(pos==N) return 0;
ll& cache = dp[pos][prevGone];
if(cache!=-1) return cache;
ll ret=0;
ll ans1,ans2;
if(prevGone) {
ans1=cost[pos][1]+solve(pos+1,1);
ans2=0;
if(pos<N-1) ans2=cost[pos][2]+solve(pos+1,0);
}
else {
ans1=cost[pos][0]+solve(pos+1,1);
ans2=0;
if(pos<N-1) ans2=cost[pos][1]+solve(pos+1,0);
}
return cache=max(ans1,ans2);
}
void trace(int pos, int prevGone){
if(pos==N-1) return;
ll ans1 = (prevGone?cost[pos][1]+dp[pos+1][1]:cost[pos][0]+dp[pos+1][1]);
ll ans2 = (prevGone?cost[pos][2]+dp[pos+1][0]:cost[pos][1]+dp[pos+1][0]);
if(ans1>ans2){
DAG[pos].pb(pos+1);
}
else {
DAG[pos+1].pb(pos);
}
if(ans1>ans2) trace(pos+1,1);
else trace(pos+1,0);
}
int main() {
memset(dp,-1,sizeof(dp));
inp1(N);
FOR(i,N) FOR(j,3) inp1(cost[i][j]);
printf("%lld\n",solve(0,0));
trace(0,0);
FOR(i,N) dfs(i);
reverse(all(v));
FOR(i,sz(v)) printf("%d ",v[i]+1);
return 0;
}
Compilation message
space.cpp: In function 'll solve(int, int)':
space.cpp:60:5: warning: unused variable 'ret' [-Wunused-variable]
ll ret=0;
^
space.cpp: In function 'int main()':
space.cpp:89:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inp1(N);
^
space.cpp:90:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
FOR(i,N) FOR(j,3) inp1(cost[i][j]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12956 KB |
Output is correct |
2 |
Correct |
3 ms |
12956 KB |
Output is correct |
3 |
Correct |
3 ms |
12956 KB |
Output is correct |
4 |
Correct |
0 ms |
12956 KB |
Output is correct |
5 |
Correct |
0 ms |
12956 KB |
Output is correct |
6 |
Correct |
0 ms |
12956 KB |
Output is correct |
7 |
Correct |
3 ms |
12956 KB |
Output is correct |
8 |
Correct |
0 ms |
12956 KB |
Output is correct |
9 |
Correct |
0 ms |
12956 KB |
Output is correct |
10 |
Correct |
0 ms |
12956 KB |
Output is correct |
11 |
Correct |
0 ms |
12956 KB |
Output is correct |
12 |
Correct |
3 ms |
12956 KB |
Output is correct |
13 |
Correct |
3 ms |
12956 KB |
Output is correct |
14 |
Correct |
3 ms |
12956 KB |
Output is correct |
15 |
Correct |
0 ms |
12956 KB |
Output is correct |
16 |
Correct |
0 ms |
12956 KB |
Output is correct |
17 |
Correct |
3 ms |
12956 KB |
Output is correct |
18 |
Correct |
0 ms |
12956 KB |
Output is correct |
19 |
Correct |
3 ms |
12956 KB |
Output is correct |
20 |
Correct |
0 ms |
12956 KB |
Output is correct |
21 |
Correct |
0 ms |
12956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12956 KB |
Output is correct |
2 |
Correct |
3 ms |
12956 KB |
Output is correct |
3 |
Correct |
3 ms |
12956 KB |
Output is correct |
4 |
Correct |
0 ms |
12956 KB |
Output is correct |
5 |
Correct |
0 ms |
12956 KB |
Output is correct |
6 |
Correct |
0 ms |
12956 KB |
Output is correct |
7 |
Correct |
3 ms |
12956 KB |
Output is correct |
8 |
Correct |
0 ms |
12956 KB |
Output is correct |
9 |
Correct |
0 ms |
12956 KB |
Output is correct |
10 |
Correct |
0 ms |
12956 KB |
Output is correct |
11 |
Correct |
0 ms |
12956 KB |
Output is correct |
12 |
Correct |
3 ms |
12956 KB |
Output is correct |
13 |
Correct |
3 ms |
12956 KB |
Output is correct |
14 |
Correct |
3 ms |
12956 KB |
Output is correct |
15 |
Correct |
0 ms |
12956 KB |
Output is correct |
16 |
Correct |
0 ms |
12956 KB |
Output is correct |
17 |
Correct |
3 ms |
12956 KB |
Output is correct |
18 |
Correct |
0 ms |
12956 KB |
Output is correct |
19 |
Correct |
3 ms |
12956 KB |
Output is correct |
20 |
Correct |
0 ms |
12956 KB |
Output is correct |
21 |
Correct |
0 ms |
12956 KB |
Output is correct |
22 |
Correct |
0 ms |
12956 KB |
Output is correct |
23 |
Correct |
0 ms |
12956 KB |
Output is correct |
24 |
Correct |
0 ms |
12956 KB |
Output is correct |
25 |
Correct |
0 ms |
12956 KB |
Output is correct |
26 |
Correct |
0 ms |
12956 KB |
Output is correct |
27 |
Correct |
3 ms |
12956 KB |
Output is correct |
28 |
Correct |
0 ms |
12956 KB |
Output is correct |
29 |
Correct |
3 ms |
12956 KB |
Output is correct |
30 |
Correct |
0 ms |
12956 KB |
Output is correct |
31 |
Correct |
0 ms |
12956 KB |
Output is correct |
32 |
Correct |
3 ms |
12956 KB |
Output is correct |
33 |
Correct |
0 ms |
12956 KB |
Output is correct |
34 |
Correct |
3 ms |
12956 KB |
Output is correct |
35 |
Correct |
0 ms |
12956 KB |
Output is correct |
36 |
Correct |
0 ms |
12956 KB |
Output is correct |
37 |
Correct |
0 ms |
12956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12956 KB |
Output is correct |
2 |
Correct |
3 ms |
12956 KB |
Output is correct |
3 |
Correct |
3 ms |
12956 KB |
Output is correct |
4 |
Correct |
0 ms |
12956 KB |
Output is correct |
5 |
Correct |
0 ms |
12956 KB |
Output is correct |
6 |
Correct |
0 ms |
12956 KB |
Output is correct |
7 |
Correct |
3 ms |
12956 KB |
Output is correct |
8 |
Correct |
0 ms |
12956 KB |
Output is correct |
9 |
Correct |
0 ms |
12956 KB |
Output is correct |
10 |
Correct |
0 ms |
12956 KB |
Output is correct |
11 |
Correct |
0 ms |
12956 KB |
Output is correct |
12 |
Correct |
3 ms |
12956 KB |
Output is correct |
13 |
Correct |
3 ms |
12956 KB |
Output is correct |
14 |
Correct |
3 ms |
12956 KB |
Output is correct |
15 |
Correct |
0 ms |
12956 KB |
Output is correct |
16 |
Correct |
0 ms |
12956 KB |
Output is correct |
17 |
Correct |
3 ms |
12956 KB |
Output is correct |
18 |
Correct |
0 ms |
12956 KB |
Output is correct |
19 |
Correct |
3 ms |
12956 KB |
Output is correct |
20 |
Correct |
0 ms |
12956 KB |
Output is correct |
21 |
Correct |
0 ms |
12956 KB |
Output is correct |
22 |
Correct |
0 ms |
12956 KB |
Output is correct |
23 |
Correct |
0 ms |
12956 KB |
Output is correct |
24 |
Correct |
0 ms |
12956 KB |
Output is correct |
25 |
Correct |
0 ms |
12956 KB |
Output is correct |
26 |
Correct |
0 ms |
12956 KB |
Output is correct |
27 |
Correct |
3 ms |
12956 KB |
Output is correct |
28 |
Correct |
0 ms |
12956 KB |
Output is correct |
29 |
Correct |
3 ms |
12956 KB |
Output is correct |
30 |
Correct |
0 ms |
12956 KB |
Output is correct |
31 |
Correct |
0 ms |
12956 KB |
Output is correct |
32 |
Correct |
3 ms |
12956 KB |
Output is correct |
33 |
Correct |
0 ms |
12956 KB |
Output is correct |
34 |
Correct |
3 ms |
12956 KB |
Output is correct |
35 |
Correct |
0 ms |
12956 KB |
Output is correct |
36 |
Correct |
0 ms |
12956 KB |
Output is correct |
37 |
Correct |
0 ms |
12956 KB |
Output is correct |
38 |
Correct |
0 ms |
12956 KB |
Output is correct |
39 |
Correct |
0 ms |
12956 KB |
Output is correct |
40 |
Correct |
0 ms |
12956 KB |
Output is correct |
41 |
Correct |
0 ms |
12956 KB |
Output is correct |
42 |
Correct |
0 ms |
12956 KB |
Output is correct |
43 |
Correct |
0 ms |
12956 KB |
Output is correct |
44 |
Correct |
0 ms |
12956 KB |
Output is correct |
45 |
Correct |
3 ms |
12956 KB |
Output is correct |
46 |
Correct |
3 ms |
12956 KB |
Output is correct |
47 |
Correct |
0 ms |
12956 KB |
Output is correct |
48 |
Correct |
3 ms |
12956 KB |
Output is correct |
49 |
Correct |
0 ms |
12956 KB |
Output is correct |
50 |
Correct |
3 ms |
12956 KB |
Output is correct |
51 |
Correct |
0 ms |
12956 KB |
Output is correct |
52 |
Correct |
3 ms |
12956 KB |
Output is correct |
53 |
Correct |
0 ms |
12956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12956 KB |
Output is correct |
2 |
Correct |
3 ms |
12956 KB |
Output is correct |
3 |
Correct |
3 ms |
12956 KB |
Output is correct |
4 |
Correct |
0 ms |
12956 KB |
Output is correct |
5 |
Correct |
0 ms |
12956 KB |
Output is correct |
6 |
Correct |
0 ms |
12956 KB |
Output is correct |
7 |
Correct |
3 ms |
12956 KB |
Output is correct |
8 |
Correct |
0 ms |
12956 KB |
Output is correct |
9 |
Correct |
0 ms |
12956 KB |
Output is correct |
10 |
Correct |
0 ms |
12956 KB |
Output is correct |
11 |
Correct |
0 ms |
12956 KB |
Output is correct |
12 |
Correct |
3 ms |
12956 KB |
Output is correct |
13 |
Correct |
3 ms |
12956 KB |
Output is correct |
14 |
Correct |
3 ms |
12956 KB |
Output is correct |
15 |
Correct |
0 ms |
12956 KB |
Output is correct |
16 |
Correct |
0 ms |
12956 KB |
Output is correct |
17 |
Correct |
3 ms |
12956 KB |
Output is correct |
18 |
Correct |
0 ms |
12956 KB |
Output is correct |
19 |
Correct |
3 ms |
12956 KB |
Output is correct |
20 |
Correct |
0 ms |
12956 KB |
Output is correct |
21 |
Correct |
0 ms |
12956 KB |
Output is correct |
22 |
Correct |
0 ms |
12956 KB |
Output is correct |
23 |
Correct |
0 ms |
12956 KB |
Output is correct |
24 |
Correct |
0 ms |
12956 KB |
Output is correct |
25 |
Correct |
0 ms |
12956 KB |
Output is correct |
26 |
Correct |
0 ms |
12956 KB |
Output is correct |
27 |
Correct |
3 ms |
12956 KB |
Output is correct |
28 |
Correct |
0 ms |
12956 KB |
Output is correct |
29 |
Correct |
3 ms |
12956 KB |
Output is correct |
30 |
Correct |
0 ms |
12956 KB |
Output is correct |
31 |
Correct |
0 ms |
12956 KB |
Output is correct |
32 |
Correct |
3 ms |
12956 KB |
Output is correct |
33 |
Correct |
0 ms |
12956 KB |
Output is correct |
34 |
Correct |
3 ms |
12956 KB |
Output is correct |
35 |
Correct |
0 ms |
12956 KB |
Output is correct |
36 |
Correct |
0 ms |
12956 KB |
Output is correct |
37 |
Correct |
0 ms |
12956 KB |
Output is correct |
38 |
Correct |
0 ms |
12956 KB |
Output is correct |
39 |
Correct |
0 ms |
12956 KB |
Output is correct |
40 |
Correct |
0 ms |
12956 KB |
Output is correct |
41 |
Correct |
0 ms |
12956 KB |
Output is correct |
42 |
Correct |
0 ms |
12956 KB |
Output is correct |
43 |
Correct |
0 ms |
12956 KB |
Output is correct |
44 |
Correct |
0 ms |
12956 KB |
Output is correct |
45 |
Correct |
3 ms |
12956 KB |
Output is correct |
46 |
Correct |
3 ms |
12956 KB |
Output is correct |
47 |
Correct |
0 ms |
12956 KB |
Output is correct |
48 |
Correct |
3 ms |
12956 KB |
Output is correct |
49 |
Correct |
0 ms |
12956 KB |
Output is correct |
50 |
Correct |
3 ms |
12956 KB |
Output is correct |
51 |
Correct |
0 ms |
12956 KB |
Output is correct |
52 |
Correct |
3 ms |
12956 KB |
Output is correct |
53 |
Correct |
0 ms |
12956 KB |
Output is correct |
54 |
Correct |
0 ms |
12956 KB |
Output is correct |
55 |
Correct |
6 ms |
13892 KB |
Output is correct |
56 |
Correct |
13 ms |
13856 KB |
Output is correct |
57 |
Correct |
13 ms |
13888 KB |
Output is correct |
58 |
Correct |
9 ms |
13892 KB |
Output is correct |
59 |
Correct |
3 ms |
13892 KB |
Output is correct |
60 |
Correct |
6 ms |
13884 KB |
Output is correct |
61 |
Correct |
6 ms |
13848 KB |
Output is correct |
62 |
Correct |
6 ms |
13552 KB |
Output is correct |
63 |
Correct |
0 ms |
13088 KB |
Output is correct |
64 |
Correct |
9 ms |
13892 KB |
Output is correct |
65 |
Correct |
3 ms |
13852 KB |
Output is correct |
66 |
Correct |
6 ms |
13892 KB |
Output is correct |
67 |
Correct |
3 ms |
13264 KB |
Output is correct |
68 |
Correct |
0 ms |
13156 KB |
Output is correct |
69 |
Correct |
3 ms |
13728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12956 KB |
Output is correct |
2 |
Correct |
3 ms |
12956 KB |
Output is correct |
3 |
Correct |
3 ms |
12956 KB |
Output is correct |
4 |
Correct |
0 ms |
12956 KB |
Output is correct |
5 |
Correct |
0 ms |
12956 KB |
Output is correct |
6 |
Correct |
0 ms |
12956 KB |
Output is correct |
7 |
Correct |
3 ms |
12956 KB |
Output is correct |
8 |
Correct |
0 ms |
12956 KB |
Output is correct |
9 |
Correct |
0 ms |
12956 KB |
Output is correct |
10 |
Correct |
0 ms |
12956 KB |
Output is correct |
11 |
Correct |
0 ms |
12956 KB |
Output is correct |
12 |
Correct |
3 ms |
12956 KB |
Output is correct |
13 |
Correct |
3 ms |
12956 KB |
Output is correct |
14 |
Correct |
3 ms |
12956 KB |
Output is correct |
15 |
Correct |
0 ms |
12956 KB |
Output is correct |
16 |
Correct |
0 ms |
12956 KB |
Output is correct |
17 |
Correct |
3 ms |
12956 KB |
Output is correct |
18 |
Correct |
0 ms |
12956 KB |
Output is correct |
19 |
Correct |
3 ms |
12956 KB |
Output is correct |
20 |
Correct |
0 ms |
12956 KB |
Output is correct |
21 |
Correct |
0 ms |
12956 KB |
Output is correct |
22 |
Correct |
0 ms |
12956 KB |
Output is correct |
23 |
Correct |
0 ms |
12956 KB |
Output is correct |
24 |
Correct |
0 ms |
12956 KB |
Output is correct |
25 |
Correct |
0 ms |
12956 KB |
Output is correct |
26 |
Correct |
0 ms |
12956 KB |
Output is correct |
27 |
Correct |
3 ms |
12956 KB |
Output is correct |
28 |
Correct |
0 ms |
12956 KB |
Output is correct |
29 |
Correct |
3 ms |
12956 KB |
Output is correct |
30 |
Correct |
0 ms |
12956 KB |
Output is correct |
31 |
Correct |
0 ms |
12956 KB |
Output is correct |
32 |
Correct |
3 ms |
12956 KB |
Output is correct |
33 |
Correct |
0 ms |
12956 KB |
Output is correct |
34 |
Correct |
3 ms |
12956 KB |
Output is correct |
35 |
Correct |
0 ms |
12956 KB |
Output is correct |
36 |
Correct |
0 ms |
12956 KB |
Output is correct |
37 |
Correct |
0 ms |
12956 KB |
Output is correct |
38 |
Correct |
0 ms |
12956 KB |
Output is correct |
39 |
Correct |
0 ms |
12956 KB |
Output is correct |
40 |
Correct |
0 ms |
12956 KB |
Output is correct |
41 |
Correct |
0 ms |
12956 KB |
Output is correct |
42 |
Correct |
0 ms |
12956 KB |
Output is correct |
43 |
Correct |
0 ms |
12956 KB |
Output is correct |
44 |
Correct |
0 ms |
12956 KB |
Output is correct |
45 |
Correct |
3 ms |
12956 KB |
Output is correct |
46 |
Correct |
3 ms |
12956 KB |
Output is correct |
47 |
Correct |
0 ms |
12956 KB |
Output is correct |
48 |
Correct |
3 ms |
12956 KB |
Output is correct |
49 |
Correct |
0 ms |
12956 KB |
Output is correct |
50 |
Correct |
3 ms |
12956 KB |
Output is correct |
51 |
Correct |
0 ms |
12956 KB |
Output is correct |
52 |
Correct |
3 ms |
12956 KB |
Output is correct |
53 |
Correct |
0 ms |
12956 KB |
Output is correct |
54 |
Correct |
0 ms |
12956 KB |
Output is correct |
55 |
Correct |
6 ms |
13892 KB |
Output is correct |
56 |
Correct |
13 ms |
13856 KB |
Output is correct |
57 |
Correct |
13 ms |
13888 KB |
Output is correct |
58 |
Correct |
9 ms |
13892 KB |
Output is correct |
59 |
Correct |
3 ms |
13892 KB |
Output is correct |
60 |
Correct |
6 ms |
13884 KB |
Output is correct |
61 |
Correct |
6 ms |
13848 KB |
Output is correct |
62 |
Correct |
6 ms |
13552 KB |
Output is correct |
63 |
Correct |
0 ms |
13088 KB |
Output is correct |
64 |
Correct |
9 ms |
13892 KB |
Output is correct |
65 |
Correct |
3 ms |
13852 KB |
Output is correct |
66 |
Correct |
6 ms |
13892 KB |
Output is correct |
67 |
Correct |
3 ms |
13264 KB |
Output is correct |
68 |
Correct |
0 ms |
13156 KB |
Output is correct |
69 |
Correct |
3 ms |
13728 KB |
Output is correct |
70 |
Correct |
6 ms |
13884 KB |
Output is correct |
71 |
Correct |
143 ms |
31440 KB |
Output is correct |
72 |
Correct |
153 ms |
33204 KB |
Output is correct |
73 |
Correct |
136 ms |
31444 KB |
Output is correct |
74 |
Correct |
106 ms |
33208 KB |
Output is correct |
75 |
Correct |
139 ms |
31444 KB |
Output is correct |
76 |
Correct |
143 ms |
31444 KB |
Output is correct |
77 |
Correct |
66 ms |
20640 KB |
Output is correct |
78 |
Correct |
163 ms |
31444 KB |
Output is correct |
79 |
Correct |
133 ms |
31444 KB |
Output is correct |
80 |
Correct |
129 ms |
33208 KB |
Output is correct |
81 |
Correct |
26 ms |
16696 KB |
Output is correct |
82 |
Correct |
116 ms |
25908 KB |
Output is correct |
83 |
Correct |
143 ms |
31452 KB |
Output is correct |
84 |
Correct |
139 ms |
31444 KB |
Output is correct |
85 |
Correct |
163 ms |
31444 KB |
Output is correct |
86 |
Correct |
153 ms |
31448 KB |
Output is correct |
87 |
Correct |
156 ms |
30080 KB |
Output is correct |
88 |
Correct |
23 ms |
15748 KB |
Output is correct |
89 |
Correct |
89 ms |
23292 KB |
Output is correct |
90 |
Correct |
53 ms |
23060 KB |
Output is correct |
91 |
Correct |
3 ms |
13852 KB |
Output is correct |
92 |
Correct |
46 ms |
23064 KB |
Output is correct |