Submission #332240

#TimeUsernameProblemLanguageResultExecution timeMemory
332240IgorIDevil's Share (RMI19_devil)C++17
0 / 100
157 ms1796 KiB
#include <bits/stdc++.h> using namespace std; string req(int c1, int c2) { if (c1 == 0 && c2 == 0) { return ""; } assert(c1 >= 1); if (c2 == 0) { return string(c1, '1'); } if (c2 <= c1) { int k = c1 / c2; string sss = ""; while (c2) { sss += "2"; for (int j = 0; j < k; j++) { sss += "1"; c1--; } c2--; } while (c1) { sss += "1"; c1--; } return sss; } //cout << "ask : " << c1 << " " << c2 << endl; for (int k = 2; ; k++) { int blocks = (c2 + k - 1) / k; if (blocks <= c1) { //cout << k << " " << blocks << endl; assert(2 * blocks > c1); if (c2 != blocks * k) { string g(k, '2'); g[k - 1] = '1'; return req(c1 - 1, c2 - k + 1) + g; } else { string g(k + 1, '2'); g[k] = '1'; return req(c1 - 1, c2 - k) + g; } } } } void solve() { int k; cin >> k; vector<int> d(10); for (int i = 1; i <= 9; i++) cin >> d[i]; int len = accumulate(d.begin(), d.end(), 0); if (d[1] == 0) { cout << string(len, '2') << "\n"; return; } string res(k - 1, '0'); for (int i = k - 2; i >= 0; i--) if (d[2]) res[i] = '2', d[2]--; else res[i] = '1', d[1]--; cout << req(d[1], d[2]) << res << "\n"; } int main() { int t; cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...