#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
using namespace std;
typedef long long ll;
const int INF = 987654321;
const ll LINF = (ll)1e15;
int TC;
int N;
int main (){
int x, y, z;
scanf("%d", &TC);
while(TC--) {
scanf("%d", &N);
int rx, ry, rz, rv = N+1;
for(z = N/8; z >= 0; z--) {
for(x = 0; x <= 5; x++) {
int m = N - 3*x - 8*z;
if(m % 5 == 0 && m >= 0) {
y = m / 5;
if(x+y+z < rv) {
rv=x+y+z;
rx = x;
ry = y;
rz = z;
}
}
}
}
if(rv > N) {
puts("-1");
}else {
while(rx--) putchar('3');
while(ry--) putchar('5');
while(rz--) putchar('8');
puts("");
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
2 |
Correct |
0 ms |
1088 KB |
Output is correct |
3 |
Correct |
0 ms |
1088 KB |
Output is correct |
4 |
Correct |
0 ms |
1088 KB |
Output is correct |
5 |
Correct |
0 ms |
1088 KB |
Output is correct |
6 |
Correct |
0 ms |
1088 KB |
Output is correct |
7 |
Correct |
0 ms |
1088 KB |
Output is correct |
8 |
Correct |
0 ms |
1088 KB |
Output is correct |
9 |
Correct |
0 ms |
1088 KB |
Output is correct |
10 |
Correct |
0 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
1088 KB |
Output is correct |
2 |
Correct |
160 ms |
1088 KB |
Output is correct |
3 |
Correct |
168 ms |
1088 KB |
Output is correct |
4 |
Correct |
172 ms |
1088 KB |
Output is correct |
5 |
Correct |
164 ms |
1088 KB |
Output is correct |
6 |
Correct |
164 ms |
1088 KB |
Output is correct |
7 |
Correct |
148 ms |
1088 KB |
Output is correct |
8 |
Correct |
156 ms |
1088 KB |
Output is correct |
9 |
Correct |
172 ms |
1088 KB |
Output is correct |
10 |
Correct |
160 ms |
1088 KB |
Output is correct |
11 |
Correct |
152 ms |
1088 KB |
Output is correct |
12 |
Correct |
140 ms |
1088 KB |
Output is correct |
13 |
Correct |
164 ms |
1088 KB |
Output is correct |
14 |
Correct |
160 ms |
1088 KB |
Output is correct |
15 |
Correct |
156 ms |
1088 KB |
Output is correct |
16 |
Correct |
160 ms |
1088 KB |
Output is correct |
17 |
Correct |
172 ms |
1088 KB |
Output is correct |
18 |
Correct |
132 ms |
1088 KB |
Output is correct |
19 |
Correct |
164 ms |
1088 KB |
Output is correct |
20 |
Correct |
136 ms |
1088 KB |
Output is correct |
21 |
Correct |
168 ms |
1088 KB |
Output is correct |
22 |
Correct |
152 ms |
1088 KB |
Output is correct |
23 |
Correct |
160 ms |
1088 KB |
Output is correct |
24 |
Correct |
164 ms |
1088 KB |
Output is correct |
25 |
Correct |
164 ms |
1088 KB |
Output is correct |