QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203941 | #87. Devil's Share | Ahmed57# | 0 | 0ms | 0kb | C++23 | 3.3kb | 2023-10-06 22:32:16 | 2024-07-04 02:17:05 |
answer
#include <bits/stdc++.h>
using namespace std;
int arr[5];string s;
string maa;string w;int k,x;
string lol[4*4*4*4][13];
void rec(){
bool ss = 0;
for(int i = 1;i<=4;i++){
if(arr[i]){
ss = 1;
arr[i]--;s+=char(i+'0');
rec();
arr[i]++;
s.pop_back();
}
}
if(ss==0){
string ma;
for(int j = 0;j<s.size()-k+1;j++){
string se;
for(int e = j;e<j+k;e++)se+=s[e];
if(ma.empty())ma = se;
ma = max(ma,se);
}
if(maa.empty()||ma<maa){
maa = ma;
w = s;
}
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
for(int t = 1;t<4*4*4*4;t++){
int de = 0;
int e = t;
int sum = 0;
for(int i = 1;i<=4;i++){
arr[i] = e%4;
e/=4;
sum+=arr[i];
}for(int K = 1;K<=sum;K++){
k = K;
maa = "";
rec();
lol[t][k] = w;
}
}
int t;cin>>t;
while(t--){
int k;cin>>k;
if(k==2){
int arr[10] = {0};
for(int i = 1;i<10;i++)cin>>arr[i];
if(k<2){
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
cout<<char(i+'0');
}
}
cout<<endl;
}else{
int su = 0;
string v;int ind = 0;
for(int i = 9;i>=1;i--){
su+=arr[i];
if(su>=2){
su-=arr[i];
ind = i;break;
}else{
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
arr[i] = 0;
}
}
if(su==1){
int lol = 1;
while(arr[ind]){
while(arr[lol]==0)lol++;
v+=char(lol+'0');
arr[lol]--;
if(arr[ind]){
v+=char(ind+'0');
arr[ind]--;
}
}
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
}
}else{
int lol = 1;
while(arr[ind]){
if(arr[ind]){
v+=char(ind+'0');
arr[ind]--;
}
while(lol<10&&arr[lol]==0)lol++;
if(lol<10){
v+=char(lol+'0');
arr[lol]--;
}
}
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
}
}
reverse(v.begin(),v.end());
cout<<v<<endl;
}
}
int de = 0;
for(int i = 1;i<=4;i++){
cin>>arr[i];
}
for(int i = 5;i<10;i++)cin>>x;
for(int i = 4;i>=1;i--){de*=4;de+=arr[i];}
cout<<lol[de][k]<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1536 4 2 1 2 2 0 0 0 0 0 2 3 2 3 3 0 0 0 0 0 3 1 2 0 3 0 0 0 0 0 4 2 2 3 2 0 0 0 0 0 1 3 3 2 2 0 0 0 0 0 3 1 2 2 0 0 0 0 0 0 3 2 1 2 3 0 0 0 0 0 6 1 3 3 0 0 0 0 0 0 4 1 0 1 2 0 0 0 0 0 4 2 1 2 3 0 0 0 0 0 4 2 3 0 2 0 0 0 0 0 5 3 2 3 3 0 0 0 0 0 3 2 2 1 1 0 0 0 0 0 3 2 3 2 0 0 0 0 0 0 8 1 3 1 3 0 0 0...
output:
3112344 33322141414 112313 ...
result:
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
35960 2 0 0 5 2 0 0 17 0 7 2 0 6 0 15 0 0 0 4 5 2 3 0 0 1 20 0 0 0 8 2 0 5 0 0 15 0 5 7 0 2 0 0 2 11 0 0 4 0 10 2 0 14 0 0 11 0 0 6 1 2 0 0 10 3 0 0 8 0 1 2 0 1 9 0 2 0 0 6 0 2 0 0 0 0 5 0 12 7 3 2 0 0 5 0 0 2 0 8 9 2 7 2 0 0 0 0 0 6 8 2 0 0 0 4 1 0 3 18 0 2 0 0 14 4 8 0 0 0 1 2 0 2 0 0 0 13 3 9 0 2...
output:
7777777777777777749493939393939 31314 11222
result:
Subtask #3:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
26488 21 7 19 0 0 0 0 0 0 0 3 15 21 0 0 0 0 0 0 0 7 4 35 0 0 0 0 0 0 0 5 28 12 0 0 0 0 0 0 0 22 40 3 0 0 0 0 0 0 0 1 7 6 0 0 0 0 0 0 0 5 12 21 0 0 0 0 0 0 0 18 27 13 0 0 0 0 0 0 0 2 36 6 0 0 0 0 0 0 0 15 19 14 0 0 0 0 0 0 0 34 17 20 0 0 0 0 0 0 0 11 17 5 0 0 0 0 0 0 0 19 10 12 0 0 0 0 0 0 0 28 29 9 ...
output:
131134 1112223 111111111111111111111111111111121212121212
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%