답안 #18502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18502 2016-02-07T04:33:00 Z gs14004 생일수 I (GA4_birthday1) C++14
100 / 100
181 ms 5628 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int dp[1000005];
int d[3] = {3, 5, 8};

void solve(int x){
	if(x == 0){
		putchar('\n');
		return;
	}
	for(int i=0; i<3; i++){
		if(x >= d[i] && dp[x] == dp[x - d[i]] + 1){
			putchar(d[i] + '0');
			solve(x - d[i]);
			return;
		}
	}
}
int main(){
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 1;
	for(int i=1; i<=1000000; i++){
		for(int j=0; j<3; j++){
			if(i >= d[j]){
				dp[i] = min(dp[i - d[j]] + 1, dp[i]);
			}
		}
	}
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		if(dp[n] > 1e9){
			puts("-1");
			continue;
		}
		solve(n);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5628 KB Output is correct
2 Correct 5 ms 5628 KB Output is correct
3 Correct 10 ms 5628 KB Output is correct
4 Correct 6 ms 5628 KB Output is correct
5 Correct 10 ms 5628 KB Output is correct
6 Correct 9 ms 5628 KB Output is correct
7 Correct 11 ms 5628 KB Output is correct
8 Correct 5 ms 5628 KB Output is correct
9 Correct 12 ms 5628 KB Output is correct
10 Correct 8 ms 5628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 5628 KB Output is correct
2 Correct 119 ms 5628 KB Output is correct
3 Correct 111 ms 5628 KB Output is correct
4 Correct 117 ms 5628 KB Output is correct
5 Correct 113 ms 5628 KB Output is correct
6 Correct 110 ms 5628 KB Output is correct
7 Correct 162 ms 5628 KB Output is correct
8 Correct 139 ms 5628 KB Output is correct
9 Correct 116 ms 5628 KB Output is correct
10 Correct 120 ms 5628 KB Output is correct
11 Correct 106 ms 5628 KB Output is correct
12 Correct 122 ms 5628 KB Output is correct
13 Correct 95 ms 5628 KB Output is correct
14 Correct 138 ms 5628 KB Output is correct
15 Correct 130 ms 5628 KB Output is correct
16 Correct 102 ms 5628 KB Output is correct
17 Correct 117 ms 5628 KB Output is correct
18 Correct 106 ms 5628 KB Output is correct
19 Correct 164 ms 5628 KB Output is correct
20 Correct 99 ms 5628 KB Output is correct
21 Correct 106 ms 5628 KB Output is correct
22 Correct 133 ms 5628 KB Output is correct
23 Correct 156 ms 5628 KB Output is correct
24 Correct 113 ms 5628 KB Output is correct
25 Correct 176 ms 5628 KB Output is correct