Submission #636775

#TimeUsernameProblemLanguageResultExecution timeMemory
636775ogibogi2004Devil's Share (RMI19_devil)C++14
27 / 100
1585 ms2124 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long ll D[10],k; void solve1() { vector<int>digits; for(int i=1;i<10;i++) { for(int j=0;j<D[i];j++) { digits.push_back(i); } } vector<int>ans; ll min_of_max=(ll)1e15; ll pw10=1; for(int j=0;j<k;j++)pw10*=10; do { ll num=0,biggestnum=0; for(int j=0;j<k;j++) { num=num*10+digits[j]; } biggestnum=num; for(int j=k;j<digits.size();j++) { num*=10; num+=digits[j]; num%=pw10; biggestnum=max(biggestnum,num); } if(biggestnum<min_of_max) { ans=digits; min_of_max=biggestnum; } }while(next_permutation(digits.begin(),digits.end())); for(auto xd:ans)cout<<xd; cout<<endl; } void solve2() { string ans=""; deque<int>dq; for(int i=1;i<=9;i++) { for(int j=0;j<D[i];j++) { dq.push_back(i); } } while(!dq.empty()) { ans+=char('0'+dq.back()); dq.pop_back(); if(!dq.empty()) { ans+=char('0'+dq.front()); dq.pop_front(); } } reverse(ans.begin(),ans.end()); cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { cin>>k; for(int i=1;i<=9;i++)cin>>D[i]; if(k==2)solve2(); else solve1(); } return 0; }

Compilation message (stderr)

devil.cpp: In function 'void solve1()':
devil.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int j=k;j<digits.size();j++)
      |                     ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...