Submission #20443

# Submission time Handle Problem Language Result Execution time Memory
20443 2017-02-11T14:30:06 Z 600913C0d3J4M(#54, sgc109) Can polan into space? (OJUZ11_space) C++11
46 / 100
1000 ms 13404 KB
// #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>
#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;
map<piiii,ll> dp;
ll dnc(int s, int e, int l, int r){
	auto& cache = dp[{{s,e},{l,r}}];
	if(s==e) return cache=cost[s][l+r];
	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[{{s,m},{l,0}}]+dp[{{m+1,e},{1,r}}];
	ll ans2 = dp[{{s,m},{l,1}}]+dp[{{m+1,e},{0,r}}];
	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 0 ms 9840 KB Output is correct
2 Correct 3 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 3 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 0 ms 9840 KB Output is correct
9 Correct 0 ms 9840 KB Output is correct
10 Correct 0 ms 9840 KB Output is correct
11 Correct 0 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 0 ms 9840 KB Output is correct
17 Correct 0 ms 9840 KB Output is correct
18 Correct 0 ms 9840 KB Output is correct
19 Correct 0 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 0 ms 9840 KB Output is correct
2 Correct 3 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 3 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 0 ms 9840 KB Output is correct
9 Correct 0 ms 9840 KB Output is correct
10 Correct 0 ms 9840 KB Output is correct
11 Correct 0 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 0 ms 9840 KB Output is correct
17 Correct 0 ms 9840 KB Output is correct
18 Correct 0 ms 9840 KB Output is correct
19 Correct 0 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 0 ms 9840 KB Output is correct
24 Correct 0 ms 9840 KB Output is correct
25 Correct 3 ms 9840 KB Output is correct
26 Correct 0 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 0 ms 9840 KB Output is correct
30 Correct 3 ms 9840 KB Output is correct
31 Correct 0 ms 9840 KB Output is correct
32 Correct 0 ms 9840 KB Output is correct
33 Correct 0 ms 9840 KB Output is correct
34 Correct 3 ms 9840 KB Output is correct
35 Correct 0 ms 9840 KB Output is correct
36 Correct 0 ms 9840 KB Output is correct
37 Correct 0 ms 9840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9840 KB Output is correct
2 Correct 3 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 3 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 0 ms 9840 KB Output is correct
9 Correct 0 ms 9840 KB Output is correct
10 Correct 0 ms 9840 KB Output is correct
11 Correct 0 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 0 ms 9840 KB Output is correct
17 Correct 0 ms 9840 KB Output is correct
18 Correct 0 ms 9840 KB Output is correct
19 Correct 0 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 0 ms 9840 KB Output is correct
24 Correct 0 ms 9840 KB Output is correct
25 Correct 3 ms 9840 KB Output is correct
26 Correct 0 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 0 ms 9840 KB Output is correct
30 Correct 3 ms 9840 KB Output is correct
31 Correct 0 ms 9840 KB Output is correct
32 Correct 0 ms 9840 KB Output is correct
33 Correct 0 ms 9840 KB Output is correct
34 Correct 3 ms 9840 KB Output is correct
35 Correct 0 ms 9840 KB Output is correct
36 Correct 0 ms 9840 KB Output is correct
37 Correct 0 ms 9840 KB Output is correct
38 Correct 0 ms 9840 KB Output is correct
39 Correct 9 ms 9972 KB Output is correct
40 Correct 9 ms 9972 KB Output is correct
41 Correct 9 ms 9972 KB Output is correct
42 Correct 13 ms 9972 KB Output is correct
43 Correct 9 ms 9972 KB Output is correct
44 Correct 13 ms 9972 KB Output is correct
45 Correct 9 ms 9972 KB Output is correct
46 Correct 6 ms 9972 KB Output is correct
47 Correct 9 ms 9972 KB Output is correct
48 Correct 0 ms 9972 KB Output is correct
49 Correct 9 ms 9972 KB Output is correct
50 Correct 9 ms 9972 KB Output is correct
51 Correct 3 ms 9972 KB Output is correct
52 Correct 13 ms 9972 KB Output is correct
53 Correct 9 ms 9972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9840 KB Output is correct
2 Correct 3 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 3 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 0 ms 9840 KB Output is correct
9 Correct 0 ms 9840 KB Output is correct
10 Correct 0 ms 9840 KB Output is correct
11 Correct 0 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 0 ms 9840 KB Output is correct
17 Correct 0 ms 9840 KB Output is correct
18 Correct 0 ms 9840 KB Output is correct
19 Correct 0 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 0 ms 9840 KB Output is correct
24 Correct 0 ms 9840 KB Output is correct
25 Correct 3 ms 9840 KB Output is correct
26 Correct 0 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 0 ms 9840 KB Output is correct
30 Correct 3 ms 9840 KB Output is correct
31 Correct 0 ms 9840 KB Output is correct
32 Correct 0 ms 9840 KB Output is correct
33 Correct 0 ms 9840 KB Output is correct
34 Correct 3 ms 9840 KB Output is correct
35 Correct 0 ms 9840 KB Output is correct
36 Correct 0 ms 9840 KB Output is correct
37 Correct 0 ms 9840 KB Output is correct
38 Correct 0 ms 9840 KB Output is correct
39 Correct 9 ms 9972 KB Output is correct
40 Correct 9 ms 9972 KB Output is correct
41 Correct 9 ms 9972 KB Output is correct
42 Correct 13 ms 9972 KB Output is correct
43 Correct 9 ms 9972 KB Output is correct
44 Correct 13 ms 9972 KB Output is correct
45 Correct 9 ms 9972 KB Output is correct
46 Correct 6 ms 9972 KB Output is correct
47 Correct 9 ms 9972 KB Output is correct
48 Correct 0 ms 9972 KB Output is correct
49 Correct 9 ms 9972 KB Output is correct
50 Correct 9 ms 9972 KB Output is correct
51 Correct 3 ms 9972 KB Output is correct
52 Correct 13 ms 9972 KB Output is correct
53 Correct 9 ms 9972 KB Output is correct
54 Correct 13 ms 9972 KB Output is correct
55 Execution timed out 1000 ms 12348 KB Execution timed out
56 Execution timed out 1000 ms 12348 KB Execution timed out
57 Execution timed out 1000 ms 12348 KB Execution timed out
58 Execution timed out 1000 ms 12348 KB Execution timed out
59 Execution timed out 1000 ms 12348 KB Execution timed out
60 Execution timed out 1000 ms 12348 KB Execution timed out
61 Execution timed out 1000 ms 12348 KB Execution timed out
62 Execution timed out 1000 ms 13404 KB Execution timed out
63 Correct 379 ms 10896 KB Output is correct
64 Execution timed out 1000 ms 12348 KB Execution timed out
65 Execution timed out 1000 ms 12348 KB Execution timed out
66 Execution timed out 1000 ms 12348 KB Execution timed out
67 Execution timed out 1000 ms 12216 KB Execution timed out
68 Execution timed out 1000 ms 11560 KB Execution timed out
69 Execution timed out 1000 ms 12348 KB Execution timed out
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9840 KB Output is correct
2 Correct 3 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 3 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 0 ms 9840 KB Output is correct
9 Correct 0 ms 9840 KB Output is correct
10 Correct 0 ms 9840 KB Output is correct
11 Correct 0 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 0 ms 9840 KB Output is correct
17 Correct 0 ms 9840 KB Output is correct
18 Correct 0 ms 9840 KB Output is correct
19 Correct 0 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 0 ms 9840 KB Output is correct
24 Correct 0 ms 9840 KB Output is correct
25 Correct 3 ms 9840 KB Output is correct
26 Correct 0 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 0 ms 9840 KB Output is correct
30 Correct 3 ms 9840 KB Output is correct
31 Correct 0 ms 9840 KB Output is correct
32 Correct 0 ms 9840 KB Output is correct
33 Correct 0 ms 9840 KB Output is correct
34 Correct 3 ms 9840 KB Output is correct
35 Correct 0 ms 9840 KB Output is correct
36 Correct 0 ms 9840 KB Output is correct
37 Correct 0 ms 9840 KB Output is correct
38 Correct 0 ms 9840 KB Output is correct
39 Correct 9 ms 9972 KB Output is correct
40 Correct 9 ms 9972 KB Output is correct
41 Correct 9 ms 9972 KB Output is correct
42 Correct 13 ms 9972 KB Output is correct
43 Correct 9 ms 9972 KB Output is correct
44 Correct 13 ms 9972 KB Output is correct
45 Correct 9 ms 9972 KB Output is correct
46 Correct 6 ms 9972 KB Output is correct
47 Correct 9 ms 9972 KB Output is correct
48 Correct 0 ms 9972 KB Output is correct
49 Correct 9 ms 9972 KB Output is correct
50 Correct 9 ms 9972 KB Output is correct
51 Correct 3 ms 9972 KB Output is correct
52 Correct 13 ms 9972 KB Output is correct
53 Correct 9 ms 9972 KB Output is correct
54 Correct 13 ms 9972 KB Output is correct
55 Execution timed out 1000 ms 12348 KB Execution timed out
56 Execution timed out 1000 ms 12348 KB Execution timed out
57 Execution timed out 1000 ms 12348 KB Execution timed out
58 Execution timed out 1000 ms 12348 KB Execution timed out
59 Execution timed out 1000 ms 12348 KB Execution timed out
60 Execution timed out 1000 ms 12348 KB Execution timed out
61 Execution timed out 1000 ms 12348 KB Execution timed out
62 Execution timed out 1000 ms 13404 KB Execution timed out
63 Correct 379 ms 10896 KB Output is correct
64 Execution timed out 1000 ms 12348 KB Execution timed out
65 Execution timed out 1000 ms 12348 KB Execution timed out
66 Execution timed out 1000 ms 12348 KB Execution timed out
67 Execution timed out 1000 ms 12216 KB Execution timed out
68 Execution timed out 1000 ms 11560 KB Execution timed out
69 Execution timed out 1000 ms 12348 KB Execution timed out
70 Execution timed out 1000 ms 12348 KB Execution timed out
71 Execution timed out 1000 ms 13008 KB Execution timed out
72 Execution timed out 1000 ms 13008 KB Execution timed out
73 Execution timed out 1000 ms 13008 KB Execution timed out
74 Execution timed out 1000 ms 13008 KB Execution timed out
75 Execution timed out 1000 ms 13008 KB Execution timed out
76 Execution timed out 1000 ms 13008 KB Execution timed out
77 Execution timed out 1000 ms 12348 KB Execution timed out
78 Execution timed out 1000 ms 13008 KB Execution timed out
79 Execution timed out 1000 ms 13008 KB Execution timed out
80 Execution timed out 1000 ms 13008 KB Execution timed out
81 Execution timed out 1000 ms 12348 KB Execution timed out
82 Execution timed out 1000 ms 12480 KB Execution timed out
83 Execution timed out 1000 ms 13008 KB Execution timed out
84 Execution timed out 1000 ms 13008 KB Execution timed out
85 Execution timed out 1000 ms 13008 KB Execution timed out
86 Execution timed out 1000 ms 13008 KB Execution timed out
87 Execution timed out 1000 ms 13008 KB Execution timed out
88 Execution timed out 1000 ms 12876 KB Execution timed out
89 Execution timed out 1000 ms 13404 KB Execution timed out
90 Execution timed out 1000 ms 13008 KB Execution timed out
91 Execution timed out 1000 ms 12348 KB Execution timed out
92 Execution timed out 1000 ms 13008 KB Execution timed out