Submission #272889

#TimeUsernameProblemLanguageResultExecution timeMemory
272889Atill83Devil's Share (RMI19_devil)C++14
100 / 100
104 ms5232 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e6+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
int dg[10];
vector<string> vc;
deque<string> d;

string doit(){
    int c = vc.size() - 1;

    while(!d.empty()){
        string cur = d.front();
        vc[c] += cur;
        d.pop_front();
        if(c != 0 && (d.empty() || d.front() != cur)){
            while(vc.size() > c){
                d.push_back(vc.back());
                vc.pop_back();
            }
        }
        c--;
        if(c == -1) c = vc.size() - 1;
    }

    string ans;

    for(string l: vc) ans += l;

    return ans;
}



void solve(){
    vc.clear();
    ll k;
    cin>>k;
    for(int i = 1; i <= 9; i++){
        cin>>dg[i];
    }

    int cur = 9;
    string suf;
    for(int i = 0; i < k - 1; i++){
        while(dg[cur] == 0) cur--;
        suf += '0' + cur;
        dg[cur]--;
    }

    while(dg[cur] == 0) cur--;
    while(dg[cur]) vc.push_back(string(1, '0' + cur)), dg[cur]--;

    for(int i = 1; i <= 9; i++){
        while(dg[i]){
            d.push_back(string(1, '0' + i));
             dg[i]--;
            }
    }
    string ans = doit();
    reverse(suf.begin(), suf.end());
    cout<<ans + suf<<endl;


}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    int t;
    cin>>t;

    while(t--)
        solve();

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message (stderr)

devil.cpp: In function 'std::string doit()':
devil.cpp:27:29: warning: comparison of integer expressions of different signedness: 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             while(vc.size() > c){
      |                   ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...