Submission #258622

#TimeUsernameProblemLanguageResultExecution timeMemory
258622dantoh000Devil's Share (RMI19_devil)C++14
14 / 100
443 ms1912 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int k; int d[10]; int ans[100005]; int n; int main(){ int TC; scanf("%d",&TC); while (TC--){ scanf("%d",&k); n = 0; for (int i = 1; i <= 9; i++){ scanf("%d",&d[i]); n += d[i]; } if (k == 2){ int F = 1, S = 9; for (int i = n-1; i >= 0; i--){ while (d[F] == 0) F++; while (d[S] == 0) S--; //printf("%d digit: %d %d\n",i,F,S); if ((n-i) % 2 == 1){ ans[i] = S; d[S]--; } else{ ans[i] = F; d[F]--; } } for (int i = 0; i < n; i++){ printf("%d",ans[i]); } printf("\n"); } else if (n <= 12){ vector<int> v; for (int i = 1; i <= 4; i++) for (int j = 0; j < d[i]; j++) v.emplace_back(i); vector<int> ans(n); ll best = 100000000000; do{ ll mx = 0; for (int i = 0; i <= n-k; i++){ ll cur = 0; for (int j = 0; j < k; j++){ cur = (10*cur + v[j+i]); } mx = max(cur,mx); } if (best > mx){ //printf("%d: ",mx); best = mx; for (int i = 0; i < n; i++){ ans[i] = v[i]; //printf("%d",ans[i]); } //printf("\n"); } } while (next_permutation(v.begin(),v.end())); for (int i = 0; i < n; i++){ printf("%d",ans[i]); } printf("\n"); } } }

Compilation message (stderr)

devil.cpp: In function 'int main()':
devil.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&TC);
     ~~~~~^~~~~~~~~~
devil.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
         ~~~~~^~~~~~~~~
devil.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&d[i]);
             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...