// #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;
unordered_map<ll,ll> dp[2][2];
ll dnc(int s, int e, int l, int r){
auto& cache = dp[l][r][(ll)s*200000+e];
if(s==e) return cache=cost[s][l+r];
if(cache!=0) return cache;
int m=(s+e)>>1;
ll ans1 = dnc(s,m,l,0)+dnc(m+1,e,1,r);
ll ans2 = dnc(s,m,l,1)+dnc(m+1,e,0,r);
return cache=max(ans1,ans2);
}
void trace(int s, int e, int l, int r){
if(s==e) return;
int m=(s+e)>>1;
ll ans1 = dp[l][0][(ll)s*200000+m]+dp[1][r][(ll)(m+1)*200000+e];
ll ans2 = dp[l][1][(ll)s*200000+m]+dp[0][r][(ll)(m+1)*200000+e];
if(ans1>ans2) {
DAG[m].pb(m+1);
trace(s,m,l,0);
trace(m+1,e,1,r);
}
else {
DAG[m+1].pb(m);
trace(s,m,l,1);
trace(m+1,e,0,r);
}
}
void dfs(int here){
if(visisted[here]) return;
visisted[here]=1;
for(int there : DAG[here]) dfs(there);
v.pb(here);
}
int main() {
inp1(N);
FOR(i,N) FOR(j,3) inp1(cost[i][j]);
printf("%lld\n",dnc(0,N-1,0,0));
trace(0,N-1,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 'int main()':
space.cpp:81:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inp1(N);
^
space.cpp:82: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 |
3 ms |
9840 KB |
Output is correct |
2 |
Correct |
0 ms |
9840 KB |
Output is correct |
3 |
Correct |
0 ms |
9840 KB |
Output is correct |
4 |
Correct |
0 ms |
9840 KB |
Output is correct |
5 |
Correct |
0 ms |
9840 KB |
Output is correct |
6 |
Correct |
0 ms |
9840 KB |
Output is correct |
7 |
Correct |
0 ms |
9840 KB |
Output is correct |
8 |
Correct |
3 ms |
9840 KB |
Output is correct |
9 |
Correct |
3 ms |
9840 KB |
Output is correct |
10 |
Correct |
3 ms |
9840 KB |
Output is correct |
11 |
Correct |
3 ms |
9840 KB |
Output is correct |
12 |
Correct |
0 ms |
9840 KB |
Output is correct |
13 |
Correct |
0 ms |
9840 KB |
Output is correct |
14 |
Correct |
0 ms |
9840 KB |
Output is correct |
15 |
Correct |
3 ms |
9840 KB |
Output is correct |
16 |
Correct |
3 ms |
9840 KB |
Output is correct |
17 |
Correct |
3 ms |
9840 KB |
Output is correct |
18 |
Correct |
0 ms |
9840 KB |
Output is correct |
19 |
Correct |
3 ms |
9840 KB |
Output is correct |
20 |
Correct |
0 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
9840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9840 KB |
Output is correct |
2 |
Correct |
0 ms |
9840 KB |
Output is correct |
3 |
Correct |
0 ms |
9840 KB |
Output is correct |
4 |
Correct |
0 ms |
9840 KB |
Output is correct |
5 |
Correct |
0 ms |
9840 KB |
Output is correct |
6 |
Correct |
0 ms |
9840 KB |
Output is correct |
7 |
Correct |
0 ms |
9840 KB |
Output is correct |
8 |
Correct |
3 ms |
9840 KB |
Output is correct |
9 |
Correct |
3 ms |
9840 KB |
Output is correct |
10 |
Correct |
3 ms |
9840 KB |
Output is correct |
11 |
Correct |
3 ms |
9840 KB |
Output is correct |
12 |
Correct |
0 ms |
9840 KB |
Output is correct |
13 |
Correct |
0 ms |
9840 KB |
Output is correct |
14 |
Correct |
0 ms |
9840 KB |
Output is correct |
15 |
Correct |
3 ms |
9840 KB |
Output is correct |
16 |
Correct |
3 ms |
9840 KB |
Output is correct |
17 |
Correct |
3 ms |
9840 KB |
Output is correct |
18 |
Correct |
0 ms |
9840 KB |
Output is correct |
19 |
Correct |
3 ms |
9840 KB |
Output is correct |
20 |
Correct |
0 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
9840 KB |
Output is correct |
22 |
Correct |
0 ms |
9840 KB |
Output is correct |
23 |
Correct |
3 ms |
9840 KB |
Output is correct |
24 |
Correct |
3 ms |
9840 KB |
Output is correct |
25 |
Correct |
0 ms |
9840 KB |
Output is correct |
26 |
Correct |
3 ms |
9840 KB |
Output is correct |
27 |
Correct |
0 ms |
9840 KB |
Output is correct |
28 |
Correct |
3 ms |
9840 KB |
Output is correct |
29 |
Correct |
3 ms |
9840 KB |
Output is correct |
30 |
Correct |
3 ms |
9840 KB |
Output is correct |
31 |
Correct |
3 ms |
9840 KB |
Output is correct |
32 |
Correct |
3 ms |
9840 KB |
Output is correct |
33 |
Correct |
0 ms |
9840 KB |
Output is correct |
34 |
Correct |
0 ms |
9840 KB |
Output is correct |
35 |
Correct |
0 ms |
9840 KB |
Output is correct |
36 |
Correct |
3 ms |
9840 KB |
Output is correct |
37 |
Correct |
3 ms |
9840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9840 KB |
Output is correct |
2 |
Correct |
0 ms |
9840 KB |
Output is correct |
3 |
Correct |
0 ms |
9840 KB |
Output is correct |
4 |
Correct |
0 ms |
9840 KB |
Output is correct |
5 |
Correct |
0 ms |
9840 KB |
Output is correct |
6 |
Correct |
0 ms |
9840 KB |
Output is correct |
7 |
Correct |
0 ms |
9840 KB |
Output is correct |
8 |
Correct |
3 ms |
9840 KB |
Output is correct |
9 |
Correct |
3 ms |
9840 KB |
Output is correct |
10 |
Correct |
3 ms |
9840 KB |
Output is correct |
11 |
Correct |
3 ms |
9840 KB |
Output is correct |
12 |
Correct |
0 ms |
9840 KB |
Output is correct |
13 |
Correct |
0 ms |
9840 KB |
Output is correct |
14 |
Correct |
0 ms |
9840 KB |
Output is correct |
15 |
Correct |
3 ms |
9840 KB |
Output is correct |
16 |
Correct |
3 ms |
9840 KB |
Output is correct |
17 |
Correct |
3 ms |
9840 KB |
Output is correct |
18 |
Correct |
0 ms |
9840 KB |
Output is correct |
19 |
Correct |
3 ms |
9840 KB |
Output is correct |
20 |
Correct |
0 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
9840 KB |
Output is correct |
22 |
Correct |
0 ms |
9840 KB |
Output is correct |
23 |
Correct |
3 ms |
9840 KB |
Output is correct |
24 |
Correct |
3 ms |
9840 KB |
Output is correct |
25 |
Correct |
0 ms |
9840 KB |
Output is correct |
26 |
Correct |
3 ms |
9840 KB |
Output is correct |
27 |
Correct |
0 ms |
9840 KB |
Output is correct |
28 |
Correct |
3 ms |
9840 KB |
Output is correct |
29 |
Correct |
3 ms |
9840 KB |
Output is correct |
30 |
Correct |
3 ms |
9840 KB |
Output is correct |
31 |
Correct |
3 ms |
9840 KB |
Output is correct |
32 |
Correct |
3 ms |
9840 KB |
Output is correct |
33 |
Correct |
0 ms |
9840 KB |
Output is correct |
34 |
Correct |
0 ms |
9840 KB |
Output is correct |
35 |
Correct |
0 ms |
9840 KB |
Output is correct |
36 |
Correct |
3 ms |
9840 KB |
Output is correct |
37 |
Correct |
3 ms |
9840 KB |
Output is correct |
38 |
Correct |
0 ms |
9840 KB |
Output is correct |
39 |
Correct |
0 ms |
9972 KB |
Output is correct |
40 |
Correct |
3 ms |
9972 KB |
Output is correct |
41 |
Correct |
0 ms |
9972 KB |
Output is correct |
42 |
Correct |
3 ms |
9972 KB |
Output is correct |
43 |
Correct |
0 ms |
9972 KB |
Output is correct |
44 |
Correct |
3 ms |
9972 KB |
Output is correct |
45 |
Correct |
0 ms |
9972 KB |
Output is correct |
46 |
Correct |
3 ms |
9972 KB |
Output is correct |
47 |
Correct |
0 ms |
9972 KB |
Output is correct |
48 |
Correct |
0 ms |
9972 KB |
Output is correct |
49 |
Correct |
3 ms |
9972 KB |
Output is correct |
50 |
Correct |
0 ms |
9972 KB |
Output is correct |
51 |
Correct |
3 ms |
9972 KB |
Output is correct |
52 |
Correct |
0 ms |
9972 KB |
Output is correct |
53 |
Correct |
0 ms |
9972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9840 KB |
Output is correct |
2 |
Correct |
0 ms |
9840 KB |
Output is correct |
3 |
Correct |
0 ms |
9840 KB |
Output is correct |
4 |
Correct |
0 ms |
9840 KB |
Output is correct |
5 |
Correct |
0 ms |
9840 KB |
Output is correct |
6 |
Correct |
0 ms |
9840 KB |
Output is correct |
7 |
Correct |
0 ms |
9840 KB |
Output is correct |
8 |
Correct |
3 ms |
9840 KB |
Output is correct |
9 |
Correct |
3 ms |
9840 KB |
Output is correct |
10 |
Correct |
3 ms |
9840 KB |
Output is correct |
11 |
Correct |
3 ms |
9840 KB |
Output is correct |
12 |
Correct |
0 ms |
9840 KB |
Output is correct |
13 |
Correct |
0 ms |
9840 KB |
Output is correct |
14 |
Correct |
0 ms |
9840 KB |
Output is correct |
15 |
Correct |
3 ms |
9840 KB |
Output is correct |
16 |
Correct |
3 ms |
9840 KB |
Output is correct |
17 |
Correct |
3 ms |
9840 KB |
Output is correct |
18 |
Correct |
0 ms |
9840 KB |
Output is correct |
19 |
Correct |
3 ms |
9840 KB |
Output is correct |
20 |
Correct |
0 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
9840 KB |
Output is correct |
22 |
Correct |
0 ms |
9840 KB |
Output is correct |
23 |
Correct |
3 ms |
9840 KB |
Output is correct |
24 |
Correct |
3 ms |
9840 KB |
Output is correct |
25 |
Correct |
0 ms |
9840 KB |
Output is correct |
26 |
Correct |
3 ms |
9840 KB |
Output is correct |
27 |
Correct |
0 ms |
9840 KB |
Output is correct |
28 |
Correct |
3 ms |
9840 KB |
Output is correct |
29 |
Correct |
3 ms |
9840 KB |
Output is correct |
30 |
Correct |
3 ms |
9840 KB |
Output is correct |
31 |
Correct |
3 ms |
9840 KB |
Output is correct |
32 |
Correct |
3 ms |
9840 KB |
Output is correct |
33 |
Correct |
0 ms |
9840 KB |
Output is correct |
34 |
Correct |
0 ms |
9840 KB |
Output is correct |
35 |
Correct |
0 ms |
9840 KB |
Output is correct |
36 |
Correct |
3 ms |
9840 KB |
Output is correct |
37 |
Correct |
3 ms |
9840 KB |
Output is correct |
38 |
Correct |
0 ms |
9840 KB |
Output is correct |
39 |
Correct |
0 ms |
9972 KB |
Output is correct |
40 |
Correct |
3 ms |
9972 KB |
Output is correct |
41 |
Correct |
0 ms |
9972 KB |
Output is correct |
42 |
Correct |
3 ms |
9972 KB |
Output is correct |
43 |
Correct |
0 ms |
9972 KB |
Output is correct |
44 |
Correct |
3 ms |
9972 KB |
Output is correct |
45 |
Correct |
0 ms |
9972 KB |
Output is correct |
46 |
Correct |
3 ms |
9972 KB |
Output is correct |
47 |
Correct |
0 ms |
9972 KB |
Output is correct |
48 |
Correct |
0 ms |
9972 KB |
Output is correct |
49 |
Correct |
3 ms |
9972 KB |
Output is correct |
50 |
Correct |
0 ms |
9972 KB |
Output is correct |
51 |
Correct |
3 ms |
9972 KB |
Output is correct |
52 |
Correct |
0 ms |
9972 KB |
Output is correct |
53 |
Correct |
0 ms |
9972 KB |
Output is correct |
54 |
Correct |
3 ms |
9972 KB |
Output is correct |
55 |
Correct |
26 ms |
13632 KB |
Output is correct |
56 |
Correct |
26 ms |
14112 KB |
Output is correct |
57 |
Correct |
29 ms |
13632 KB |
Output is correct |
58 |
Correct |
33 ms |
13632 KB |
Output is correct |
59 |
Correct |
26 ms |
13632 KB |
Output is correct |
60 |
Correct |
33 ms |
13632 KB |
Output is correct |
61 |
Correct |
26 ms |
13768 KB |
Output is correct |
62 |
Correct |
19 ms |
12404 KB |
Output is correct |
63 |
Correct |
6 ms |
10688 KB |
Output is correct |
64 |
Correct |
19 ms |
13632 KB |
Output is correct |
65 |
Correct |
29 ms |
13768 KB |
Output is correct |
66 |
Correct |
33 ms |
13632 KB |
Output is correct |
67 |
Correct |
16 ms |
11720 KB |
Output is correct |
68 |
Correct |
3 ms |
10952 KB |
Output is correct |
69 |
Correct |
29 ms |
13676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9840 KB |
Output is correct |
2 |
Correct |
0 ms |
9840 KB |
Output is correct |
3 |
Correct |
0 ms |
9840 KB |
Output is correct |
4 |
Correct |
0 ms |
9840 KB |
Output is correct |
5 |
Correct |
0 ms |
9840 KB |
Output is correct |
6 |
Correct |
0 ms |
9840 KB |
Output is correct |
7 |
Correct |
0 ms |
9840 KB |
Output is correct |
8 |
Correct |
3 ms |
9840 KB |
Output is correct |
9 |
Correct |
3 ms |
9840 KB |
Output is correct |
10 |
Correct |
3 ms |
9840 KB |
Output is correct |
11 |
Correct |
3 ms |
9840 KB |
Output is correct |
12 |
Correct |
0 ms |
9840 KB |
Output is correct |
13 |
Correct |
0 ms |
9840 KB |
Output is correct |
14 |
Correct |
0 ms |
9840 KB |
Output is correct |
15 |
Correct |
3 ms |
9840 KB |
Output is correct |
16 |
Correct |
3 ms |
9840 KB |
Output is correct |
17 |
Correct |
3 ms |
9840 KB |
Output is correct |
18 |
Correct |
0 ms |
9840 KB |
Output is correct |
19 |
Correct |
3 ms |
9840 KB |
Output is correct |
20 |
Correct |
0 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
9840 KB |
Output is correct |
22 |
Correct |
0 ms |
9840 KB |
Output is correct |
23 |
Correct |
3 ms |
9840 KB |
Output is correct |
24 |
Correct |
3 ms |
9840 KB |
Output is correct |
25 |
Correct |
0 ms |
9840 KB |
Output is correct |
26 |
Correct |
3 ms |
9840 KB |
Output is correct |
27 |
Correct |
0 ms |
9840 KB |
Output is correct |
28 |
Correct |
3 ms |
9840 KB |
Output is correct |
29 |
Correct |
3 ms |
9840 KB |
Output is correct |
30 |
Correct |
3 ms |
9840 KB |
Output is correct |
31 |
Correct |
3 ms |
9840 KB |
Output is correct |
32 |
Correct |
3 ms |
9840 KB |
Output is correct |
33 |
Correct |
0 ms |
9840 KB |
Output is correct |
34 |
Correct |
0 ms |
9840 KB |
Output is correct |
35 |
Correct |
0 ms |
9840 KB |
Output is correct |
36 |
Correct |
3 ms |
9840 KB |
Output is correct |
37 |
Correct |
3 ms |
9840 KB |
Output is correct |
38 |
Correct |
0 ms |
9840 KB |
Output is correct |
39 |
Correct |
0 ms |
9972 KB |
Output is correct |
40 |
Correct |
3 ms |
9972 KB |
Output is correct |
41 |
Correct |
0 ms |
9972 KB |
Output is correct |
42 |
Correct |
3 ms |
9972 KB |
Output is correct |
43 |
Correct |
0 ms |
9972 KB |
Output is correct |
44 |
Correct |
3 ms |
9972 KB |
Output is correct |
45 |
Correct |
0 ms |
9972 KB |
Output is correct |
46 |
Correct |
3 ms |
9972 KB |
Output is correct |
47 |
Correct |
0 ms |
9972 KB |
Output is correct |
48 |
Correct |
0 ms |
9972 KB |
Output is correct |
49 |
Correct |
3 ms |
9972 KB |
Output is correct |
50 |
Correct |
0 ms |
9972 KB |
Output is correct |
51 |
Correct |
3 ms |
9972 KB |
Output is correct |
52 |
Correct |
0 ms |
9972 KB |
Output is correct |
53 |
Correct |
0 ms |
9972 KB |
Output is correct |
54 |
Correct |
3 ms |
9972 KB |
Output is correct |
55 |
Correct |
26 ms |
13632 KB |
Output is correct |
56 |
Correct |
26 ms |
14112 KB |
Output is correct |
57 |
Correct |
29 ms |
13632 KB |
Output is correct |
58 |
Correct |
33 ms |
13632 KB |
Output is correct |
59 |
Correct |
26 ms |
13632 KB |
Output is correct |
60 |
Correct |
33 ms |
13632 KB |
Output is correct |
61 |
Correct |
26 ms |
13768 KB |
Output is correct |
62 |
Correct |
19 ms |
12404 KB |
Output is correct |
63 |
Correct |
6 ms |
10688 KB |
Output is correct |
64 |
Correct |
19 ms |
13632 KB |
Output is correct |
65 |
Correct |
29 ms |
13768 KB |
Output is correct |
66 |
Correct |
33 ms |
13632 KB |
Output is correct |
67 |
Correct |
16 ms |
11720 KB |
Output is correct |
68 |
Correct |
3 ms |
10952 KB |
Output is correct |
69 |
Correct |
29 ms |
13676 KB |
Output is correct |
70 |
Correct |
33 ms |
13648 KB |
Output is correct |
71 |
Execution timed out |
1000 ms |
82724 KB |
Execution timed out |
72 |
Execution timed out |
1000 ms |
84488 KB |
Execution timed out |
73 |
Execution timed out |
1000 ms |
82732 KB |
Execution timed out |
74 |
Execution timed out |
1000 ms |
84488 KB |
Execution timed out |
75 |
Execution timed out |
1000 ms |
82732 KB |
Execution timed out |
76 |
Execution timed out |
1000 ms |
82728 KB |
Execution timed out |
77 |
Correct |
439 ms |
41256 KB |
Output is correct |
78 |
Execution timed out |
1000 ms |
82720 KB |
Execution timed out |
79 |
Execution timed out |
1000 ms |
82728 KB |
Execution timed out |
80 |
Execution timed out |
1000 ms |
93740 KB |
Execution timed out |
81 |
Correct |
149 ms |
25280 KB |
Output is correct |
82 |
Correct |
793 ms |
64968 KB |
Output is correct |
83 |
Execution timed out |
1000 ms |
82732 KB |
Execution timed out |
84 |
Execution timed out |
1000 ms |
82724 KB |
Execution timed out |
85 |
Execution timed out |
1000 ms |
82728 KB |
Execution timed out |
86 |
Execution timed out |
1000 ms |
82728 KB |
Execution timed out |
87 |
Execution timed out |
1000 ms |
81364 KB |
Execution timed out |
88 |
Correct |
133 ms |
22692 KB |
Output is correct |
89 |
Correct |
586 ms |
49776 KB |
Output is correct |
90 |
Correct |
503 ms |
47084 KB |
Output is correct |
91 |
Correct |
29 ms |
13832 KB |
Output is correct |
92 |
Correct |
539 ms |
47084 KB |
Output is correct |