//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,k;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC;
cin>>TC;
while (TC--){
cin>>k;
n=0;
vector<int> v;
rep(x,1,10){
int t;
cin>>t;
n+=t;
rep(y,0,t) v.push_back(x);
}
ll best=1e18;
ll ans;
do{
ll cbest=0;
rep(x,0,n-k+1){
ll curr=0;
rep(y,x,x+k) curr=curr*10+v[y];
cbest=max(cbest,curr);
}
if (cbest<best){
best=cbest;
ans=0;
rep(x,0,n) ans=ans*10+v[x];
}
} while (next_permutation(all(v)));
cout<<ans<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
803 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1568 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1581 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
803 ms |
524 KB |
Output is correct |
2 |
Execution timed out |
1568 ms |
384 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |