답안 #69023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69023 2018-08-19T13:47:12 Z 검수컵(#1978, imsifile) 천사의 모래시계 (FXCUP3_hourglass) C++
100 / 100
5 ms 1508 KB
#include<stdio.h>

int N, dy[5050][4][6];

int mins(int a, int b){
	if(!a) return b;
	if(!b) return a;
	return a<b?a:b;
}

int sub(int a, int b){
	return a<b?0:a-b;
}

int getdy(int t, int h1, int h2){
	if(t == 0) return 0;
	if(t < 0) return 9999;
	if(dy[t][h1][h2]) return dy[t][h1][h2];

	int dap = 9999, gap;
	if(h1 == 0){
		gap = getdy(t, 3, h2) + 1;
		if(dap > gap) dap = gap;
		if(0 < h2 && h2 < 5){
			gap = getdy(t, 3, 5-h2) + 1;
			if(dap > gap) dap = gap;
		}
	}
	if(h2 == 0){
		gap = getdy(t, h1, 5) + 1;
		if(dap > gap) dap = gap;
		if(0 < h1 && h1 < 3){
			gap = getdy(t, 3-h1, 5) + 1;
			if(dap > gap) dap = gap;
		}
	}

	int m = mins(h1, h2);
	if(m){
		gap = getdy(t-m, sub(h1,m), sub(h2,m));
		if(dap > gap) dap = gap;
	}

	return dy[t][h1][h2] = dap;
}

int main(){
	scanf("%d", &N);
	int v = getdy(N,0,0);
	printf("%d\n", v == 9999 ? -1 : v);
	return 0;
}

Compilation message

hourglass.cpp: In function 'int main()':
hourglass.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1128 KB Output is correct
2 Correct 2 ms 1128 KB Output is correct
3 Correct 5 ms 1128 KB Output is correct
4 Correct 3 ms 1128 KB Output is correct
5 Correct 3 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1128 KB Output is correct
2 Correct 2 ms 1128 KB Output is correct
3 Correct 2 ms 1128 KB Output is correct
4 Correct 3 ms 1128 KB Output is correct
5 Correct 2 ms 1128 KB Output is correct
6 Correct 2 ms 1128 KB Output is correct
7 Correct 2 ms 1128 KB Output is correct
8 Correct 3 ms 1128 KB Output is correct
9 Correct 2 ms 1128 KB Output is correct
10 Correct 3 ms 1128 KB Output is correct
11 Correct 3 ms 1128 KB Output is correct
12 Correct 2 ms 1128 KB Output is correct
13 Correct 3 ms 1128 KB Output is correct
14 Correct 3 ms 1128 KB Output is correct
15 Correct 2 ms 1128 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 2 ms 1128 KB Output is correct
18 Correct 3 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1128 KB Output is correct
2 Correct 3 ms 1128 KB Output is correct
3 Correct 5 ms 1508 KB Output is correct
4 Correct 4 ms 1128 KB Output is correct
5 Correct 2 ms 1128 KB Output is correct
6 Correct 2 ms 1128 KB Output is correct
7 Correct 3 ms 1128 KB Output is correct
8 Correct 3 ms 1128 KB Output is correct
9 Correct 2 ms 1128 KB Output is correct
10 Correct 4 ms 1428 KB Output is correct
11 Correct 2 ms 1128 KB Output is correct
12 Correct 3 ms 1128 KB Output is correct