Submission #20877

# Submission time Handle Problem Language Result Execution time Memory
20877 2017-03-02T11:28:27 Z jjwdi0 생일수 I (GA4_birthday1) C++11
100 / 100
263 ms 16740 KB
#include <stdio.h>
#define INF 987654321
int dp[1000035][4], test, a[3]={3, 5, 8};
main()
{
	scanf("%d", &test);
	for(int i=0; i<=1000000; i++)dp[i][0]=INF;
	dp[3][0]=dp[3][1]=dp[5][0]=dp[5][2]=dp[8][0]=dp[8][3]=1;
	for(int i=0; i<=999997; i++)
	{
		if(dp[i][0]!=INF)
		{
			for(int j=0; j<3; j++)
			{
				if(dp[i+a[j]][0]>dp[i][0]+1)
				{
					for(int k=1; k<=3; k++)dp[i+a[j]][k]=dp[i][k];
					dp[i+a[j]][0]=dp[i][0]+1;
					dp[i+a[j]][j+1]++;
				}
			}
		}
	}
	while(test--)
	{
		int n;
		scanf("%d", &n);
		if(dp[n][0]==INF)puts("-1");
		else
		{
			for(int i=0; i<dp[n][1]; i++)printf("3");
			for(int i=0; i<dp[n][2]; i++)printf("5");
			for(int i=0; i<dp[n][3]; i++)printf("8");
			puts("");
		}
	}
}

Compilation message

birthday1.cpp:4:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
birthday1.cpp: In function 'int main()':
birthday1.cpp:6:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &test);
                    ^
birthday1.cpp:27:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16740 KB Output is correct
2 Correct 9 ms 16740 KB Output is correct
3 Correct 6 ms 16740 KB Output is correct
4 Correct 9 ms 16740 KB Output is correct
5 Correct 9 ms 16740 KB Output is correct
6 Correct 6 ms 16740 KB Output is correct
7 Correct 6 ms 16740 KB Output is correct
8 Correct 13 ms 16740 KB Output is correct
9 Correct 13 ms 16740 KB Output is correct
10 Correct 13 ms 16740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 16740 KB Output is correct
2 Correct 236 ms 16740 KB Output is correct
3 Correct 263 ms 16740 KB Output is correct
4 Correct 249 ms 16740 KB Output is correct
5 Correct 226 ms 16740 KB Output is correct
6 Correct 256 ms 16740 KB Output is correct
7 Correct 223 ms 16740 KB Output is correct
8 Correct 246 ms 16740 KB Output is correct
9 Correct 253 ms 16740 KB Output is correct
10 Correct 219 ms 16740 KB Output is correct
11 Correct 226 ms 16740 KB Output is correct
12 Correct 226 ms 16740 KB Output is correct
13 Correct 236 ms 16740 KB Output is correct
14 Correct 229 ms 16740 KB Output is correct
15 Correct 206 ms 16740 KB Output is correct
16 Correct 243 ms 16740 KB Output is correct
17 Correct 236 ms 16740 KB Output is correct
18 Correct 206 ms 16740 KB Output is correct
19 Correct 209 ms 16740 KB Output is correct
20 Correct 199 ms 16740 KB Output is correct
21 Correct 243 ms 16740 KB Output is correct
22 Correct 229 ms 16740 KB Output is correct
23 Correct 236 ms 16740 KB Output is correct
24 Correct 263 ms 16740 KB Output is correct
25 Correct 226 ms 16740 KB Output is correct