# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636775 | ogibogi2004 | Devil's Share (RMI19_devil) | C++14 | 1585 ms | 2124 KiB |
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<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)
# | 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... |