# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642509 | Tenis0206 | Devil's Share (RMI19_devil) | C++11 | 455 ms | 5168 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;
int k;
vector<string> v;
queue<string> q;
int fr[15];
int get_max()
{
for(int c=9; c>=1; c--)
{
if(fr[c])
{
return c;
}
}
}
void solve_test()
{
cin>>k;
for(int i=1; i<=9; i++)
{
cin>>fr[i];
}
string rez;
for(int i=1; i<k; i++)
{
rez.push_back(get_max() + '0');
--fr[get_max()];
}
reverse(rez.begin(),rez.end());
int Max = get_max();
for(int i=1; i<=fr[Max]; i++)
{
string aux;
aux.push_back(Max + '0');
v.push_back(aux);
}
for(int c=1; c<Max; c++)
{
for(int i=1; i<=fr[c]; i++)
{
string aux;
aux.push_back(c + '0');
q.push(aux);
}
}
int poz = v.size() - 1;
while(!q.empty())
{
string s = q.front();
q.pop();
v[poz] += s;
--poz;
if(poz < 0)
{
poz = v.size() - 1;
}
else if(q.empty() || s!=q.front())
{
while(v.size()-1 > poz)
{
q.push(v.back());
v.pop_back();
}
}
}
for(int i=v.size()-1; i>=0; i--)
{
rez = v[i] + rez;
}
v.clear();
cout<<rez<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
for(int test=1; test<=t; test++)
{
solve_test();
}
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... |