Submission #20662

# Submission time Handle Problem Language Result Execution time Memory
20662 2017-02-13T11:09:00 Z 우리OJ(#80, cki86201) Can polan into space? (OJUZ11_space) C++14
100 / 100
153 ms 31648 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;

int N;
int A[200010][3];
ll D[200020][2];
int pre[200020][2];
vector <int> E[200020], v;
int vis[200020];

void dfs(int x){
	vis[x] = 1;
	for(int e : E[x])if(vis[e] == 0)dfs(e);
	v.pb(x);
}

void solve(){
	scanf("%d", &N);
	for(int i=1;i<=N;i++)scanf("%d%d%d", A[i], A[i]+1, A[i]+2);
	if(N == 1){
		printf("%d\n%d\n", A[1][0], 1);
		return;
	}
	D[2][0] = A[2][0] + A[1][1];
	D[2][1] = A[2][1] + A[1][0];
	for(int i=3;i<=N;i++){
		if(D[i-1][0] + A[i-1][1] - A[i-1][0] > D[i-1][1] + A[i-1][2] - A[i-1][1]){
			D[i][0] = D[i-1][0] + A[i-1][1] - A[i-1][0] + A[i][0];
			pre[i][0] = 0;
		}
		else{
			D[i][0] = D[i-1][1] + A[i-1][2] - A[i-1][1] + A[i][0];
			pre[i][0] = 1;
		}
		if(D[i-1][0] > D[i-1][1]){
			D[i][1] = A[i][1] + D[i-1][0];
			pre[i][1] = 0;
		}
		else{
			D[i][1] = D[i-1][1] + A[i][1];
			pre[i][1] = 1;
		}
	}
	int x = 0;
	if(D[N][0] < D[N][1])x = 1;
	printf("%lld\n", D[N][x]);
	for(int i=N;i>1;i--){
		if(x)E[i-1].pb(i);
		else E[i].pb(i-1);
		x = pre[i][x];
	}
	for(int i=1;i<=N;i++)if(vis[i] == 0)dfs(i);
	reverse(all(v));
	for(int e : v)printf("%d ", e); puts("");
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Compilation message

space.cpp: In function 'void solve()':
space.cpp:47:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
space.cpp:48:60: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++)scanf("%d%d%d", A[i], A[i]+1, A[i]+2);
                                                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 14520 KB Output is correct
2 Correct 3 ms 14520 KB Output is correct
3 Correct 3 ms 14520 KB Output is correct
4 Correct 3 ms 14520 KB Output is correct
5 Correct 0 ms 14520 KB Output is correct
6 Correct 0 ms 14520 KB Output is correct
7 Correct 0 ms 14520 KB Output is correct
8 Correct 0 ms 14520 KB Output is correct
9 Correct 0 ms 14520 KB Output is correct
10 Correct 0 ms 14520 KB Output is correct
11 Correct 0 ms 14520 KB Output is correct
12 Correct 0 ms 14520 KB Output is correct
13 Correct 0 ms 14520 KB Output is correct
14 Correct 3 ms 14520 KB Output is correct
15 Correct 3 ms 14520 KB Output is correct
16 Correct 3 ms 14520 KB Output is correct
17 Correct 0 ms 14520 KB Output is correct
18 Correct 0 ms 14520 KB Output is correct
19 Correct 0 ms 14520 KB Output is correct
20 Correct 3 ms 14520 KB Output is correct
21 Correct 0 ms 14520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 14520 KB Output is correct
2 Correct 3 ms 14520 KB Output is correct
3 Correct 3 ms 14520 KB Output is correct
4 Correct 3 ms 14520 KB Output is correct
5 Correct 0 ms 14520 KB Output is correct
6 Correct 0 ms 14520 KB Output is correct
7 Correct 0 ms 14520 KB Output is correct
8 Correct 0 ms 14520 KB Output is correct
9 Correct 0 ms 14520 KB Output is correct
10 Correct 0 ms 14520 KB Output is correct
11 Correct 0 ms 14520 KB Output is correct
12 Correct 0 ms 14520 KB Output is correct
13 Correct 0 ms 14520 KB Output is correct
14 Correct 3 ms 14520 KB Output is correct
15 Correct 3 ms 14520 KB Output is correct
16 Correct 3 ms 14520 KB Output is correct
17 Correct 0 ms 14520 KB Output is correct
18 Correct 0 ms 14520 KB Output is correct
19 Correct 0 ms 14520 KB Output is correct
20 Correct 3 ms 14520 KB Output is correct
21 Correct 0 ms 14520 KB Output is correct
22 Correct 0 ms 14520 KB Output is correct
23 Correct 0 ms 14520 KB Output is correct
24 Correct 0 ms 14520 KB Output is correct
25 Correct 0 ms 14520 KB Output is correct
26 Correct 3 ms 14520 KB Output is correct
27 Correct 0 ms 14520 KB Output is correct
28 Correct 0 ms 14520 KB Output is correct
29 Correct 0 ms 14520 KB Output is correct
30 Correct 3 ms 14520 KB Output is correct
31 Correct 0 ms 14520 KB Output is correct
32 Correct 0 ms 14520 KB Output is correct
33 Correct 0 ms 14520 KB Output is correct
34 Correct 0 ms 14520 KB Output is correct
35 Correct 0 ms 14520 KB Output is correct
36 Correct 0 ms 14520 KB Output is correct
37 Correct 0 ms 14520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 14520 KB Output is correct
2 Correct 3 ms 14520 KB Output is correct
3 Correct 3 ms 14520 KB Output is correct
4 Correct 3 ms 14520 KB Output is correct
5 Correct 0 ms 14520 KB Output is correct
6 Correct 0 ms 14520 KB Output is correct
7 Correct 0 ms 14520 KB Output is correct
8 Correct 0 ms 14520 KB Output is correct
9 Correct 0 ms 14520 KB Output is correct
10 Correct 0 ms 14520 KB Output is correct
11 Correct 0 ms 14520 KB Output is correct
12 Correct 0 ms 14520 KB Output is correct
13 Correct 0 ms 14520 KB Output is correct
14 Correct 3 ms 14520 KB Output is correct
15 Correct 3 ms 14520 KB Output is correct
16 Correct 3 ms 14520 KB Output is correct
17 Correct 0 ms 14520 KB Output is correct
18 Correct 0 ms 14520 KB Output is correct
19 Correct 0 ms 14520 KB Output is correct
20 Correct 3 ms 14520 KB Output is correct
21 Correct 0 ms 14520 KB Output is correct
22 Correct 0 ms 14520 KB Output is correct
23 Correct 0 ms 14520 KB Output is correct
24 Correct 0 ms 14520 KB Output is correct
25 Correct 0 ms 14520 KB Output is correct
26 Correct 3 ms 14520 KB Output is correct
27 Correct 0 ms 14520 KB Output is correct
28 Correct 0 ms 14520 KB Output is correct
29 Correct 0 ms 14520 KB Output is correct
30 Correct 3 ms 14520 KB Output is correct
31 Correct 0 ms 14520 KB Output is correct
32 Correct 0 ms 14520 KB Output is correct
33 Correct 0 ms 14520 KB Output is correct
34 Correct 0 ms 14520 KB Output is correct
35 Correct 0 ms 14520 KB Output is correct
36 Correct 0 ms 14520 KB Output is correct
37 Correct 0 ms 14520 KB Output is correct
38 Correct 0 ms 14520 KB Output is correct
39 Correct 3 ms 14520 KB Output is correct
40 Correct 3 ms 14520 KB Output is correct
41 Correct 3 ms 14520 KB Output is correct
42 Correct 0 ms 14520 KB Output is correct
43 Correct 0 ms 14520 KB Output is correct
44 Correct 0 ms 14520 KB Output is correct
45 Correct 0 ms 14520 KB Output is correct
46 Correct 0 ms 14520 KB Output is correct
47 Correct 0 ms 14520 KB Output is correct
48 Correct 0 ms 14520 KB Output is correct
49 Correct 0 ms 14520 KB Output is correct
50 Correct 0 ms 14520 KB Output is correct
51 Correct 3 ms 14520 KB Output is correct
52 Correct 3 ms 14520 KB Output is correct
53 Correct 0 ms 14520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 14520 KB Output is correct
2 Correct 3 ms 14520 KB Output is correct
3 Correct 3 ms 14520 KB Output is correct
4 Correct 3 ms 14520 KB Output is correct
5 Correct 0 ms 14520 KB Output is correct
6 Correct 0 ms 14520 KB Output is correct
7 Correct 0 ms 14520 KB Output is correct
8 Correct 0 ms 14520 KB Output is correct
9 Correct 0 ms 14520 KB Output is correct
10 Correct 0 ms 14520 KB Output is correct
11 Correct 0 ms 14520 KB Output is correct
12 Correct 0 ms 14520 KB Output is correct
13 Correct 0 ms 14520 KB Output is correct
14 Correct 3 ms 14520 KB Output is correct
15 Correct 3 ms 14520 KB Output is correct
16 Correct 3 ms 14520 KB Output is correct
17 Correct 0 ms 14520 KB Output is correct
18 Correct 0 ms 14520 KB Output is correct
19 Correct 0 ms 14520 KB Output is correct
20 Correct 3 ms 14520 KB Output is correct
21 Correct 0 ms 14520 KB Output is correct
22 Correct 0 ms 14520 KB Output is correct
23 Correct 0 ms 14520 KB Output is correct
24 Correct 0 ms 14520 KB Output is correct
25 Correct 0 ms 14520 KB Output is correct
26 Correct 3 ms 14520 KB Output is correct
27 Correct 0 ms 14520 KB Output is correct
28 Correct 0 ms 14520 KB Output is correct
29 Correct 0 ms 14520 KB Output is correct
30 Correct 3 ms 14520 KB Output is correct
31 Correct 0 ms 14520 KB Output is correct
32 Correct 0 ms 14520 KB Output is correct
33 Correct 0 ms 14520 KB Output is correct
34 Correct 0 ms 14520 KB Output is correct
35 Correct 0 ms 14520 KB Output is correct
36 Correct 0 ms 14520 KB Output is correct
37 Correct 0 ms 14520 KB Output is correct
38 Correct 0 ms 14520 KB Output is correct
39 Correct 3 ms 14520 KB Output is correct
40 Correct 3 ms 14520 KB Output is correct
41 Correct 3 ms 14520 KB Output is correct
42 Correct 0 ms 14520 KB Output is correct
43 Correct 0 ms 14520 KB Output is correct
44 Correct 0 ms 14520 KB Output is correct
45 Correct 0 ms 14520 KB Output is correct
46 Correct 0 ms 14520 KB Output is correct
47 Correct 0 ms 14520 KB Output is correct
48 Correct 0 ms 14520 KB Output is correct
49 Correct 0 ms 14520 KB Output is correct
50 Correct 0 ms 14520 KB Output is correct
51 Correct 3 ms 14520 KB Output is correct
52 Correct 3 ms 14520 KB Output is correct
53 Correct 0 ms 14520 KB Output is correct
54 Correct 0 ms 14520 KB Output is correct
55 Correct 3 ms 14952 KB Output is correct
56 Correct 3 ms 15264 KB Output is correct
57 Correct 3 ms 14952 KB Output is correct
58 Correct 9 ms 14952 KB Output is correct
59 Correct 6 ms 14952 KB Output is correct
60 Correct 6 ms 14952 KB Output is correct
61 Correct 0 ms 15256 KB Output is correct
62 Correct 6 ms 14792 KB Output is correct
63 Correct 0 ms 14652 KB Output is correct
64 Correct 6 ms 14952 KB Output is correct
65 Correct 6 ms 14916 KB Output is correct
66 Correct 6 ms 14952 KB Output is correct
67 Correct 0 ms 14652 KB Output is correct
68 Correct 3 ms 14652 KB Output is correct
69 Correct 3 ms 14788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 14520 KB Output is correct
2 Correct 3 ms 14520 KB Output is correct
3 Correct 3 ms 14520 KB Output is correct
4 Correct 3 ms 14520 KB Output is correct
5 Correct 0 ms 14520 KB Output is correct
6 Correct 0 ms 14520 KB Output is correct
7 Correct 0 ms 14520 KB Output is correct
8 Correct 0 ms 14520 KB Output is correct
9 Correct 0 ms 14520 KB Output is correct
10 Correct 0 ms 14520 KB Output is correct
11 Correct 0 ms 14520 KB Output is correct
12 Correct 0 ms 14520 KB Output is correct
13 Correct 0 ms 14520 KB Output is correct
14 Correct 3 ms 14520 KB Output is correct
15 Correct 3 ms 14520 KB Output is correct
16 Correct 3 ms 14520 KB Output is correct
17 Correct 0 ms 14520 KB Output is correct
18 Correct 0 ms 14520 KB Output is correct
19 Correct 0 ms 14520 KB Output is correct
20 Correct 3 ms 14520 KB Output is correct
21 Correct 0 ms 14520 KB Output is correct
22 Correct 0 ms 14520 KB Output is correct
23 Correct 0 ms 14520 KB Output is correct
24 Correct 0 ms 14520 KB Output is correct
25 Correct 0 ms 14520 KB Output is correct
26 Correct 3 ms 14520 KB Output is correct
27 Correct 0 ms 14520 KB Output is correct
28 Correct 0 ms 14520 KB Output is correct
29 Correct 0 ms 14520 KB Output is correct
30 Correct 3 ms 14520 KB Output is correct
31 Correct 0 ms 14520 KB Output is correct
32 Correct 0 ms 14520 KB Output is correct
33 Correct 0 ms 14520 KB Output is correct
34 Correct 0 ms 14520 KB Output is correct
35 Correct 0 ms 14520 KB Output is correct
36 Correct 0 ms 14520 KB Output is correct
37 Correct 0 ms 14520 KB Output is correct
38 Correct 0 ms 14520 KB Output is correct
39 Correct 3 ms 14520 KB Output is correct
40 Correct 3 ms 14520 KB Output is correct
41 Correct 3 ms 14520 KB Output is correct
42 Correct 0 ms 14520 KB Output is correct
43 Correct 0 ms 14520 KB Output is correct
44 Correct 0 ms 14520 KB Output is correct
45 Correct 0 ms 14520 KB Output is correct
46 Correct 0 ms 14520 KB Output is correct
47 Correct 0 ms 14520 KB Output is correct
48 Correct 0 ms 14520 KB Output is correct
49 Correct 0 ms 14520 KB Output is correct
50 Correct 0 ms 14520 KB Output is correct
51 Correct 3 ms 14520 KB Output is correct
52 Correct 3 ms 14520 KB Output is correct
53 Correct 0 ms 14520 KB Output is correct
54 Correct 0 ms 14520 KB Output is correct
55 Correct 3 ms 14952 KB Output is correct
56 Correct 3 ms 15264 KB Output is correct
57 Correct 3 ms 14952 KB Output is correct
58 Correct 9 ms 14952 KB Output is correct
59 Correct 6 ms 14952 KB Output is correct
60 Correct 6 ms 14952 KB Output is correct
61 Correct 0 ms 15256 KB Output is correct
62 Correct 6 ms 14792 KB Output is correct
63 Correct 0 ms 14652 KB Output is correct
64 Correct 6 ms 14952 KB Output is correct
65 Correct 6 ms 14916 KB Output is correct
66 Correct 6 ms 14952 KB Output is correct
67 Correct 0 ms 14652 KB Output is correct
68 Correct 3 ms 14652 KB Output is correct
69 Correct 3 ms 14788 KB Output is correct
70 Correct 6 ms 14952 KB Output is correct
71 Correct 149 ms 20632 KB Output is correct
72 Correct 99 ms 31648 KB Output is correct
73 Correct 133 ms 20636 KB Output is correct
74 Correct 93 ms 22396 KB Output is correct
75 Correct 136 ms 20636 KB Output is correct
76 Correct 139 ms 20636 KB Output is correct
77 Correct 59 ms 17216 KB Output is correct
78 Correct 143 ms 20628 KB Output is correct
79 Correct 153 ms 20636 KB Output is correct
80 Correct 133 ms 31644 KB Output is correct
81 Correct 26 ms 15888 KB Output is correct
82 Correct 109 ms 19168 KB Output is correct
83 Correct 139 ms 20640 KB Output is correct
84 Correct 143 ms 20632 KB Output is correct
85 Correct 133 ms 20636 KB Output is correct
86 Correct 133 ms 20636 KB Output is correct
87 Correct 119 ms 19268 KB Output is correct
88 Correct 23 ms 15444 KB Output is correct
89 Correct 76 ms 17916 KB Output is correct
90 Correct 43 ms 18500 KB Output is correct
91 Correct 3 ms 14916 KB Output is correct
92 Correct 39 ms 18500 KB Output is correct