답안 #2328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
2328 2013-07-21T02:45:18 Z zyslee 생일수 I (GA4_birthday1) C++
100 / 100
116 ms 884 KB
#include<stdio.h>
int main()
{
	int n, i, t, j, a, b, c, k, l;
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		scanf("%d", &t);
		a = b = c = 0;
		for(j=t/8;j>=0;j--){
			for(k=(t-(j*8))/5;k>=0;k--){
				if(j+k+((t-(j*8)-(k*5))/3)>a+b+c && (a!=0 || b!=0 || c!=0)) break;
				if((t-(j*8)-(k*5))%3==0){
					if(j+k+((t-(j*8)-(k*5))/3)<a+b+c || (a==0 && b==0 && c==0)){
						a = j;
						b = k;
						c = (t-(j*8)-(k*5))/3;
					}
					else if(j+k+((t-(j*8)-(k*5))/3)==a+b+c){
						if(a<j){
							a = j;
							b = k;
							c = (t-(j*8)-(k*5))/3;
						}
						else if(a==j){
							if(b<k){
								a = j;
								b = k;
								c = (t-(j*8)-(k*5))/3;
							}
						}
					}
				}
			}
		}
		if(a==0 && b==0 && c==0) printf("-1\n");
		else{
			for(j=1;j<=c;j++) printf("3");
			for(j=1;j<=b;j++) printf("5");
			for(j=1;j<=a;j++) printf("8");
			printf("\n");
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 884 KB Output is correct
2 Correct 0 ms 884 KB Output is correct
3 Correct 0 ms 884 KB Output is correct
4 Correct 0 ms 884 KB Output is correct
5 Correct 0 ms 884 KB Output is correct
6 Correct 0 ms 884 KB Output is correct
7 Correct 0 ms 884 KB Output is correct
8 Correct 0 ms 884 KB Output is correct
9 Correct 0 ms 884 KB Output is correct
10 Correct 0 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 884 KB Output is correct
2 Correct 102 ms 884 KB Output is correct
3 Correct 116 ms 884 KB Output is correct
4 Correct 91 ms 884 KB Output is correct
5 Correct 106 ms 884 KB Output is correct
6 Correct 100 ms 884 KB Output is correct
7 Correct 105 ms 884 KB Output is correct
8 Correct 108 ms 884 KB Output is correct
9 Correct 106 ms 884 KB Output is correct
10 Correct 110 ms 884 KB Output is correct
11 Correct 97 ms 884 KB Output is correct
12 Correct 100 ms 884 KB Output is correct
13 Correct 95 ms 884 KB Output is correct
14 Correct 108 ms 884 KB Output is correct
15 Correct 94 ms 884 KB Output is correct
16 Correct 104 ms 884 KB Output is correct
17 Correct 99 ms 884 KB Output is correct
18 Correct 102 ms 884 KB Output is correct
19 Correct 111 ms 884 KB Output is correct
20 Correct 105 ms 884 KB Output is correct
21 Correct 107 ms 884 KB Output is correct
22 Correct 87 ms 884 KB Output is correct
23 Correct 99 ms 884 KB Output is correct
24 Correct 99 ms 884 KB Output is correct
25 Correct 96 ms 884 KB Output is correct