# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258160 | 2020-08-05T13:00:08 Z | cheeheng | Devil's Share (RMI19_devil) | C++14 | 1500 ms | 1400 KB |
#include <bits/stdc++.h> using namespace std; int D[12]; int X[505]; int ans[505]; int main(){ int T; scanf("%d", &T); while(T --){ int K; scanf("%d", &K); int S = 0; for(int i = 1; i < 10; i ++){ scanf("%d", &D[i]); S += D[i]; } int cnt = 0; for(int i = 1; i < 10; i ++){ for(int j = 0; j < D[i]; j ++){ X[cnt++] = i; } } sort(X, X+S); if(K == 2){ for(int i = 0; i < S; i ++){ if(i%2 == 0){ ans[i] = X[S-1-i/2]; }else{ ans[i] = X[i/2]; } } reverse(ans, ans+S); for(int i = 0; i < S; i ++){ printf("%d", ans[i]); } printf("\n"); continue; } long long minVal = 1LL << 62; do{ long long tempMax = 0; for(int i = 0; i <= S-K; i ++){ long long temp = 0; for(int j = i; j < i+K; j ++){ temp = temp*10+X[j]; } //printf("%lld\n", temp); tempMax = max(tempMax, temp); } if(tempMax < minVal){ for(int i = 0; i < S; i ++){ ans[i] = X[i]; } minVal = tempMax; //printf("tempMax=%lld\n", tempMax); } }while(next_permutation(X, X+S)); for(int i = 0; i < S; i ++){ printf("%d", ans[i]); } printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 417 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 132 ms | 1272 KB | Output is correct |
2 | Correct | 115 ms | 1364 KB | Output is correct |
3 | Correct | 125 ms | 1400 KB | Output is correct |
4 | Correct | 149 ms | 1272 KB | Output is correct |
5 | Runtime error | 92 ms | 1400 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1588 ms | 364 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 417 ms | 504 KB | Output is correct |
2 | Correct | 132 ms | 1272 KB | Output is correct |
3 | Correct | 115 ms | 1364 KB | Output is correct |
4 | Correct | 125 ms | 1400 KB | Output is correct |
5 | Correct | 149 ms | 1272 KB | Output is correct |
6 | Runtime error | 92 ms | 1400 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
7 | Halted | 0 ms | 0 KB | - |