답안 #66236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66236 2018-08-10T05:23:14 Z 정원준(#1889) Can polan into space? (OJUZ11_space) C++11
100 / 100
172 ms 18416 KB
#include <bits/stdc++.h>
#define inf 1000000000000000L
#define L long long

using namespace std;

L n;
L dp[200020][4];

struct S{
	L a,b,c;
}a[200020];

L ans[200020];
L chk[200020];

bool ok(L x){
	if(chk[x]) return 0;
	//printf("%lld\n",x);
	if(ans[x]==0) return chk[x-1]+chk[x+1]==0;
	if(ans[x]==1||ans[x]==2) return chk[x-1]+chk[x+1]==1;
	if(ans[x]==3) return chk[x-1]+chk[x+1]==2;
}

int main()
{
	scanf("%lld",&n);
	L i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld %lld %lld",&a[i].a,&a[i].b,&a[i].c);
	}
	a[1].c=a[1].b;
	a[1].b=a[1].a;
	a[n].c=a[n].b;
	a[n].b=a[n].a;
	dp[0][0]=0;
	dp[0][1]=0;
	dp[0][2]=-inf;
	dp[0][3]=-inf;
	for(i=1;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][2],dp[i-1][3])+a[i].a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][1])+a[i].b;
		dp[i][2]=max(dp[i-1][2],dp[i-1][3])+a[i].b;
		dp[i][3]=max(dp[i-1][0],dp[i-1][1])+a[i].c;
		/*for(L j=0;j<4;j++)
		{
			printf("%lld ",dp[i][j]);
		}
		puts("");*/
	}
	printf("%lld\n",max(dp[n][2],dp[n][3]));
	L x=n,y=dp[n][2]>dp[n][3]?2:3;
	while(x)
	{
		ans[x]=y;
		if(y%2)
		{
			y=dp[x-1][0]>dp[x-1][1]?0:1;
		}
		else
		{
			y=dp[x-1][2]>dp[x-1][3]?2:3;
		}
		x--;
	}
	queue<L>Q;
	chk[0]=chk[n+1]=1;
	for(i=1;i<=n;i++)
	{
		//printf("ans %lld ",ans[i]);
		if(ok(i))
		{
			chk[i]=1;
			Q.push(i);
		}
	}
	//puts("");
	while(!Q.empty())
	{
		L x=Q.front();Q.pop();
		printf("%lld ",x);
		if(ok(x-1))
		{
			chk[x-1]=1;
			Q.push(x-1);
		}
		if(ok(x+1))
		{
			chk[x+1]=1;
			Q.push(x+1);
		}
	}
}

Compilation message

space.cpp: In function 'bool ok(long long int)':
space.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
space.cpp: In function 'int main()':
space.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
space.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&a[i].a,&a[i].b,&a[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 3 ms 784 KB Output is correct
16 Correct 2 ms 784 KB Output is correct
17 Correct 3 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 3 ms 784 KB Output is correct
20 Correct 3 ms 784 KB Output is correct
21 Correct 2 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 3 ms 784 KB Output is correct
16 Correct 2 ms 784 KB Output is correct
17 Correct 3 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 3 ms 784 KB Output is correct
20 Correct 3 ms 784 KB Output is correct
21 Correct 2 ms 784 KB Output is correct
22 Correct 2 ms 784 KB Output is correct
23 Correct 2 ms 784 KB Output is correct
24 Correct 2 ms 784 KB Output is correct
25 Correct 2 ms 784 KB Output is correct
26 Correct 2 ms 784 KB Output is correct
27 Correct 3 ms 784 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 2 ms 784 KB Output is correct
30 Correct 2 ms 784 KB Output is correct
31 Correct 2 ms 784 KB Output is correct
32 Correct 2 ms 784 KB Output is correct
33 Correct 2 ms 784 KB Output is correct
34 Correct 2 ms 784 KB Output is correct
35 Correct 2 ms 784 KB Output is correct
36 Correct 2 ms 784 KB Output is correct
37 Correct 2 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 3 ms 784 KB Output is correct
16 Correct 2 ms 784 KB Output is correct
17 Correct 3 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 3 ms 784 KB Output is correct
20 Correct 3 ms 784 KB Output is correct
21 Correct 2 ms 784 KB Output is correct
22 Correct 2 ms 784 KB Output is correct
23 Correct 2 ms 784 KB Output is correct
24 Correct 2 ms 784 KB Output is correct
25 Correct 2 ms 784 KB Output is correct
26 Correct 2 ms 784 KB Output is correct
27 Correct 3 ms 784 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 2 ms 784 KB Output is correct
30 Correct 2 ms 784 KB Output is correct
31 Correct 2 ms 784 KB Output is correct
32 Correct 2 ms 784 KB Output is correct
33 Correct 2 ms 784 KB Output is correct
34 Correct 2 ms 784 KB Output is correct
35 Correct 2 ms 784 KB Output is correct
36 Correct 2 ms 784 KB Output is correct
37 Correct 2 ms 784 KB Output is correct
38 Correct 2 ms 784 KB Output is correct
39 Correct 3 ms 784 KB Output is correct
40 Correct 2 ms 784 KB Output is correct
41 Correct 2 ms 784 KB Output is correct
42 Correct 2 ms 784 KB Output is correct
43 Correct 2 ms 784 KB Output is correct
44 Correct 2 ms 784 KB Output is correct
45 Correct 3 ms 784 KB Output is correct
46 Correct 2 ms 784 KB Output is correct
47 Correct 3 ms 784 KB Output is correct
48 Correct 3 ms 784 KB Output is correct
49 Correct 2 ms 784 KB Output is correct
50 Correct 3 ms 784 KB Output is correct
51 Correct 2 ms 784 KB Output is correct
52 Correct 3 ms 784 KB Output is correct
53 Correct 3 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 3 ms 784 KB Output is correct
16 Correct 2 ms 784 KB Output is correct
17 Correct 3 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 3 ms 784 KB Output is correct
20 Correct 3 ms 784 KB Output is correct
21 Correct 2 ms 784 KB Output is correct
22 Correct 2 ms 784 KB Output is correct
23 Correct 2 ms 784 KB Output is correct
24 Correct 2 ms 784 KB Output is correct
25 Correct 2 ms 784 KB Output is correct
26 Correct 2 ms 784 KB Output is correct
27 Correct 3 ms 784 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 2 ms 784 KB Output is correct
30 Correct 2 ms 784 KB Output is correct
31 Correct 2 ms 784 KB Output is correct
32 Correct 2 ms 784 KB Output is correct
33 Correct 2 ms 784 KB Output is correct
34 Correct 2 ms 784 KB Output is correct
35 Correct 2 ms 784 KB Output is correct
36 Correct 2 ms 784 KB Output is correct
37 Correct 2 ms 784 KB Output is correct
38 Correct 2 ms 784 KB Output is correct
39 Correct 3 ms 784 KB Output is correct
40 Correct 2 ms 784 KB Output is correct
41 Correct 2 ms 784 KB Output is correct
42 Correct 2 ms 784 KB Output is correct
43 Correct 2 ms 784 KB Output is correct
44 Correct 2 ms 784 KB Output is correct
45 Correct 3 ms 784 KB Output is correct
46 Correct 2 ms 784 KB Output is correct
47 Correct 3 ms 784 KB Output is correct
48 Correct 3 ms 784 KB Output is correct
49 Correct 2 ms 784 KB Output is correct
50 Correct 3 ms 784 KB Output is correct
51 Correct 2 ms 784 KB Output is correct
52 Correct 3 ms 784 KB Output is correct
53 Correct 3 ms 784 KB Output is correct
54 Correct 2 ms 784 KB Output is correct
55 Correct 15 ms 1440 KB Output is correct
56 Correct 10 ms 1440 KB Output is correct
57 Correct 10 ms 1456 KB Output is correct
58 Correct 12 ms 1472 KB Output is correct
59 Correct 10 ms 1472 KB Output is correct
60 Correct 11 ms 1552 KB Output is correct
61 Correct 8 ms 1552 KB Output is correct
62 Correct 7 ms 1552 KB Output is correct
63 Correct 5 ms 1552 KB Output is correct
64 Correct 10 ms 1552 KB Output is correct
65 Correct 8 ms 1552 KB Output is correct
66 Correct 9 ms 1552 KB Output is correct
67 Correct 6 ms 1552 KB Output is correct
68 Correct 4 ms 1552 KB Output is correct
69 Correct 12 ms 1552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 784 KB Output is correct
10 Correct 2 ms 784 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 784 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 3 ms 784 KB Output is correct
16 Correct 2 ms 784 KB Output is correct
17 Correct 3 ms 784 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 3 ms 784 KB Output is correct
20 Correct 3 ms 784 KB Output is correct
21 Correct 2 ms 784 KB Output is correct
22 Correct 2 ms 784 KB Output is correct
23 Correct 2 ms 784 KB Output is correct
24 Correct 2 ms 784 KB Output is correct
25 Correct 2 ms 784 KB Output is correct
26 Correct 2 ms 784 KB Output is correct
27 Correct 3 ms 784 KB Output is correct
28 Correct 2 ms 784 KB Output is correct
29 Correct 2 ms 784 KB Output is correct
30 Correct 2 ms 784 KB Output is correct
31 Correct 2 ms 784 KB Output is correct
32 Correct 2 ms 784 KB Output is correct
33 Correct 2 ms 784 KB Output is correct
34 Correct 2 ms 784 KB Output is correct
35 Correct 2 ms 784 KB Output is correct
36 Correct 2 ms 784 KB Output is correct
37 Correct 2 ms 784 KB Output is correct
38 Correct 2 ms 784 KB Output is correct
39 Correct 3 ms 784 KB Output is correct
40 Correct 2 ms 784 KB Output is correct
41 Correct 2 ms 784 KB Output is correct
42 Correct 2 ms 784 KB Output is correct
43 Correct 2 ms 784 KB Output is correct
44 Correct 2 ms 784 KB Output is correct
45 Correct 3 ms 784 KB Output is correct
46 Correct 2 ms 784 KB Output is correct
47 Correct 3 ms 784 KB Output is correct
48 Correct 3 ms 784 KB Output is correct
49 Correct 2 ms 784 KB Output is correct
50 Correct 3 ms 784 KB Output is correct
51 Correct 2 ms 784 KB Output is correct
52 Correct 3 ms 784 KB Output is correct
53 Correct 3 ms 784 KB Output is correct
54 Correct 2 ms 784 KB Output is correct
55 Correct 15 ms 1440 KB Output is correct
56 Correct 10 ms 1440 KB Output is correct
57 Correct 10 ms 1456 KB Output is correct
58 Correct 12 ms 1472 KB Output is correct
59 Correct 10 ms 1472 KB Output is correct
60 Correct 11 ms 1552 KB Output is correct
61 Correct 8 ms 1552 KB Output is correct
62 Correct 7 ms 1552 KB Output is correct
63 Correct 5 ms 1552 KB Output is correct
64 Correct 10 ms 1552 KB Output is correct
65 Correct 8 ms 1552 KB Output is correct
66 Correct 9 ms 1552 KB Output is correct
67 Correct 6 ms 1552 KB Output is correct
68 Correct 4 ms 1552 KB Output is correct
69 Correct 12 ms 1552 KB Output is correct
70 Correct 11 ms 1616 KB Output is correct
71 Correct 140 ms 16864 KB Output is correct
72 Correct 124 ms 17688 KB Output is correct
73 Correct 172 ms 17688 KB Output is correct
74 Correct 114 ms 17688 KB Output is correct
75 Correct 159 ms 17688 KB Output is correct
76 Correct 154 ms 17688 KB Output is correct
77 Correct 61 ms 17688 KB Output is correct
78 Correct 148 ms 17688 KB Output is correct
79 Correct 145 ms 17688 KB Output is correct
80 Correct 162 ms 18416 KB Output is correct
81 Correct 32 ms 18416 KB Output is correct
82 Correct 100 ms 18416 KB Output is correct
83 Correct 162 ms 18416 KB Output is correct
84 Correct 154 ms 18416 KB Output is correct
85 Correct 152 ms 18416 KB Output is correct
86 Correct 146 ms 18416 KB Output is correct
87 Correct 161 ms 18416 KB Output is correct
88 Correct 27 ms 18416 KB Output is correct
89 Correct 89 ms 18416 KB Output is correct
90 Correct 59 ms 18416 KB Output is correct
91 Correct 8 ms 18416 KB Output is correct
92 Correct 55 ms 18416 KB Output is correct