This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |