This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("trapv")
#pragma GCC target("avx,avx2,ssse3,sse2,sse,fma,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using namespace __gnu_pbds;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
int k, a[11], perm[12];
void solve() {
int s = 0;
for(int i = 1; i <= 9; i++) s += a[i];
int c = 1;
pair<ll, string> ans = {1e13, ""};
for(int i = 0; i < s; i++) {
while(a[c]==0) c++;
perm[i] = c;
a[c]--;
}
do {
string t;
ll mx = 0, cur = 0, pw = 1;
for(int i = 0; i < k; i++) pw*=10;
for(int i = 0; i < s; i++) {
t.pb(perm[i]+'0');
cur = cur*10 + perm[i];
if(i>=k) cur -= pw*perm[i-k];
mx = max(mx, cur);
}
ans = min(ans, {mx, t});
} while(next_permutation(perm, perm+s));
cout << ans.second << " " << ans.first << "\n";
}
void solve2() {
}
void read() {
cin >> k;
for(int i = 1; i <= 9; i++) cin >> a[i];
// if(k==2) solve2();
// else
solve();
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) read();
return 0;
}
# | 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... |