제출 #258183

#제출 시각아이디문제언어결과실행 시간메모리
258183oolimryDevil's Share (RMI19_devil)C++14
0 / 100
318 ms262148 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() using namespace std; typedef pair<int,int> ii; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int TC; cin >> TC; while(TC--){ int K; cin >> K; int cnt[10]; int S = 0; for(int i = 1;i <= 9;i++){ cin >> cnt[i]; S += cnt[i]; } vector<int> lastK; int _K = K-1; int big = 9; while(_K--){ while(cnt[big] == 0) big--; cnt[big]--; lastK.push_back(big); } S -= (K-1); vector<int> front; if(cnt[2] == 0){ front.assign(S,1); } else if(cnt[1] == 1){ front.assign(S,2); } else if(cnt[1] >= cnt[2]){ int grp = S / cnt[2]; while(cnt[2]--){ front.push_back(2); for(int i = 1;i < grp;i++){ front.push_back(1); cnt[1]--; } } while(cnt[1]--) front.push_back(1); } else{ int grp = S / cnt[1]; if(S % cnt[1] != 0) grp++; for(int i = 0;i < S;i++){ if(i % grp == 0) front.push_back(1); else front.push_back(2); } reverse(all(front)); } for(int x : front) cout << x; reverse(all(lastK)); for(int x : lastK) cout << x; cout << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...