QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782304 | #8776. Not Another Constructive! | ucup-team4352# | WA | 256ms | 20012kb | C++23 | 2.7kb | 2024-11-25 19:39:43 | 2024-11-25 19:39:52 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define log(x) (63^__builtin_clzll(x))
#define pii pair<ll,ll>
#define ld long double
using namespace std;
int a[55];
char str[55];
struct node{
int N,NA,NAC,fr;
};
bool operator<(node a,node b){
if(a.N!=b.N)return a.N<b.N;
if(a.NA!=b.NA)return a.NA<b.NA;
if(a.NAC!=b.NAC)return a.NAC<b.NAC;
return a.fr<b.fr;
}
bool operator==(node a,node b){
return a.N==b.N&&a.NA==b.NA&&a.NAC==b.NAC;
}
inline node add(node a,int x){
if(x==1){
a.N++;
}
if(x==2){
a.NA+=a.N;
}
if(x==3){
a.NAC+=a.NA;
}
a.fr=x;
return a;
}
inline node sub(node a,int x){
if(x==1){
a.N--;
}
if(x==2){
a.NA-=a.N;
}
if(x==3){
a.NAC-=a.NA;
}
return a;
}
int T;
int n,k;
int fd[45][45][405];
void init(){
for(int i=0;i<=40;i++){
for(int N=0;N<=40;N++){
for(int NA=0;NA<=400;NA++){
for(int z=n-i;z>=1;z--){
for(int y=0;y+z<=n-i;y++){
int x=n-i-y-z;
fd[i][N][NA]=max(fd[i][N][NA],z*(NA+(N+x)*y));
}
}
}
}
}
}
inline bool check(node a){
if(a.NAC==k)return 1;
if(a.NAC+a.NA>k)return 0;
int mx=a.NAC+fd[T][a.N][a.NA];
if(mx<k)return 0;
return 1;
}
vector<node>dp[45];
int T1;
void solve(){
cin>>n>>k;
init();
for(int i=1;i<=n;i++){
char c;
cin>>c;
str[i]=c;
a[i]=4;
if(c=='?')a[i]=0;
if(c=='N')a[i]=1;
if(c=='A')a[i]=2;
if(c=='C')a[i]=3;
}
T1=clock();
dp[0]={{0,0,0,0}};
for(int i=1;i<=n;i++){
T=i;
for(auto u:dp[i-1]){
if(a[i]){
auto t=add(u,a[i]);
if(check(t))dp[i].push_back(t);
}
else{
for(int j=1;j<=4;j++){
auto t=add(u,j);
if(check(t))dp[i].push_back(t);
}
}
}
sort(dp[i].begin(),dp[i].end());
dp[i].resize(unique(dp[i].begin(),dp[i].end())-dp[i].begin());
if(dp[i].size()>10000){
random_shuffle(dp[i].begin(),dp[i].end());
dp[i].resize(10000);
}
// cout<<i<<" "<<dp[i].size()<<"\n";
}
string s="?NACB";
for(auto u:dp[n]){
if(u.NAC==k){
auto now=u;
vector<int>ans={now.fr};
for(int j=n-1;j>=1;j--){
now=sub(now,now.fr);
for(auto v:dp[j]){
if(v==now){
now=v;
break;
}
}
ans.push_back(now.fr);
}
reverse(ans.begin(),ans.end());
for(int j=0;j<n;j++){
if(a[j+1]!=4)cout<<s[ans[j]];
else cout<<str[j+1];
}
cout<<"\n";
return;
}
}
cout<<"-1\n";
}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
srand(123654789);
int t=1;
// cin>>t;
while(t--)solve();
// cout<<clock()-T1<<"\n";
return 0;
}
/*
22 2
N??A??????C???????????
18 0
COUNTINGSATELLITES
2 1
??
40 900
????NNNC????A??N?????????????????CCCCCCC
????????????????????????????????????????
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 32ms
memory: 5388kb
input:
22 2 N??A??????C???????????
output:
NCCABBBBBBCBBBBBBBBBBC
result:
ok correct
Test #2:
score: 0
Accepted
time: 18ms
memory: 4860kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
1 0 ?
output:
A
result:
ok correct
Test #5:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
1 0 N
output:
N
result:
ok correct
Test #6:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
1 0 X
output:
X
result:
ok correct
Test #7:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
1 1 ?
output:
-1
result:
ok correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
1 1 N
output:
-1
result:
ok correct
Test #9:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
1 1 X
output:
-1
result:
ok correct
Test #10:
score: 0
Accepted
time: 1ms
memory: 3976kb
input:
2 0 ??
output:
AA
result:
ok correct
Test #11:
score: 0
Accepted
time: 1ms
memory: 4016kb
input:
2 0 N?
output:
NC
result:
ok correct
Test #12:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
2 0 ?C
output:
AC
result:
ok correct
Test #13:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
2 1 N?
output:
-1
result:
ok correct
Test #14:
score: 0
Accepted
time: 1ms
memory: 3976kb
input:
2 1 ?C
output:
-1
result:
ok correct
Test #15:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
3 1 ???
output:
NAC
result:
ok correct
Test #16:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
3 1 N??
output:
NAC
result:
ok correct
Test #17:
score: 0
Accepted
time: 1ms
memory: 3940kb
input:
3 1 ?A?
output:
NAC
result:
ok correct
Test #18:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
3 1 ??C
output:
NAC
result:
ok correct
Test #19:
score: 0
Accepted
time: 1ms
memory: 4104kb
input:
3 1 NA?
output:
NAC
result:
ok correct
Test #20:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
3 1 N?C
output:
NAC
result:
ok correct
Test #21:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
3 1 ?AC
output:
NAC
result:
ok correct
Test #22:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
4 1 ????
output:
ANAC
result:
ok correct
Test #23:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
4 1 X???
output:
XNAC
result:
ok correct
Test #24:
score: 0
Accepted
time: 1ms
memory: 4012kb
input:
4 1 ???Z
output:
NACZ
result:
ok correct
Test #25:
score: 0
Accepted
time: 0ms
memory: 3948kb
input:
4 1 ?AA?
output:
-1
result:
ok correct
Test #26:
score: 0
Accepted
time: 1ms
memory: 4188kb
input:
4 1 N???
output:
NCAC
result:
ok correct
Test #27:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
4 1 ?N??
output:
ANAC
result:
ok correct
Test #28:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
4 1 ??N?
output:
NANC
result:
ok correct
Test #29:
score: 0
Accepted
time: 1ms
memory: 4116kb
input:
4 1 ???N
output:
NACN
result:
ok correct
Test #30:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
4 1 A???
output:
ANAC
result:
ok correct
Test #31:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
4 1 ?A??
output:
NABC
result:
ok correct
Test #32:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
4 1 ??A?
output:
ANAC
result:
ok correct
Test #33:
score: 0
Accepted
time: 1ms
memory: 4016kb
input:
4 1 ???A
output:
NACA
result:
ok correct
Test #34:
score: 0
Accepted
time: 1ms
memory: 3988kb
input:
4 1 C???
output:
CNAC
result:
ok correct
Test #35:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
4 1 ?C??
output:
NCAC
result:
ok correct
Test #36:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
4 1 ??C?
output:
NACB
result:
ok correct
Test #37:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
4 1 ???C
output:
ANAC
result:
ok correct
Test #38:
score: 0
Accepted
time: 2ms
memory: 4016kb
input:
5 4 ?????
output:
NAACC
result:
ok correct
Test #39:
score: 0
Accepted
time: 2ms
memory: 4156kb
input:
6 14 ??????
output:
-1
result:
ok correct
Test #40:
score: 0
Accepted
time: 0ms
memory: 4316kb
input:
7 14 ???????
output:
-1
result:
ok correct
Test #41:
score: 0
Accepted
time: 3ms
memory: 4156kb
input:
8 43 ????????
output:
-1
result:
ok correct
Test #42:
score: 0
Accepted
time: 4ms
memory: 4288kb
input:
9 55 ?????????
output:
-1
result:
ok correct
Test #43:
score: 0
Accepted
time: 4ms
memory: 4352kb
input:
10 112 ??????????
output:
-1
result:
ok correct
Test #44:
score: 0
Accepted
time: 5ms
memory: 4368kb
input:
11 110 ???????????
output:
-1
result:
ok correct
Test #45:
score: 0
Accepted
time: 7ms
memory: 4544kb
input:
12 4 ????????????
output:
AAAAAANACCCC
result:
ok correct
Test #46:
score: 0
Accepted
time: 8ms
memory: 4568kb
input:
13 193 ?????????????
output:
-1
result:
ok correct
Test #47:
score: 0
Accepted
time: 10ms
memory: 4524kb
input:
14 91 ??????????????
output:
NNNANAAACACCCC
result:
ok correct
Test #48:
score: 0
Accepted
time: 12ms
memory: 4836kb
input:
15 15 ???????????????
output:
NACCCCCCCCCACCC
result:
ok correct
Test #49:
score: 0
Accepted
time: 9ms
memory: 5012kb
input:
16 261 ????????????????
output:
-1
result:
ok correct
Test #50:
score: 0
Accepted
time: 12ms
memory: 4904kb
input:
17 514 ?????????????????
output:
-1
result:
ok correct
Test #51:
score: 0
Accepted
time: 14ms
memory: 4980kb
input:
18 678 ??????????????????
output:
-1
result:
ok correct
Test #52:
score: 0
Accepted
time: 30ms
memory: 6556kb
input:
19 40 ???????????????????
output:
NAACCCCCACCCCCCCCCC
result:
ok correct
Test #53:
score: 0
Accepted
time: 25ms
memory: 5024kb
input:
20 1019 ????????????????????
output:
-1
result:
ok correct
Test #54:
score: 0
Accepted
time: 19ms
memory: 5188kb
input:
21 1218 ?????????????????????
output:
-1
result:
ok correct
Test #55:
score: 0
Accepted
time: 31ms
memory: 5128kb
input:
22 1348 ??????????????????????
output:
-1
result:
ok correct
Test #56:
score: 0
Accepted
time: 35ms
memory: 5256kb
input:
23 476 ???????????????????????
output:
-1
result:
ok correct
Test #57:
score: 0
Accepted
time: 40ms
memory: 5324kb
input:
24 1445 ????????????????????????
output:
-1
result:
ok correct
Test #58:
score: 0
Accepted
time: 45ms
memory: 5396kb
input:
25 1331 ?????????????????????????
output:
-1
result:
ok correct
Test #59:
score: 0
Accepted
time: 66ms
memory: 8024kb
input:
26 459 ??????????????????????????
output:
NNNNANAAAAAACACCCCCACCCACC
result:
ok correct
Test #60:
score: 0
Accepted
time: 91ms
memory: 11112kb
input:
27 398 ???????????????????????????
output:
NNNAANAAACCCACAAACCCCCACCCC
result:
ok correct
Test #61:
score: 0
Accepted
time: 108ms
memory: 13256kb
input:
28 274 ????????????????????????????
output:
NNNAACAANACCCCAAAACBCCABBCCC
result:
ok correct
Test #62:
score: 0
Accepted
time: 59ms
memory: 5648kb
input:
29 1624 ?????????????????????????????
output:
-1
result:
ok correct
Test #63:
score: 0
Accepted
time: 74ms
memory: 5736kb
input:
30 2079 ??????????????????????????????
output:
-1
result:
ok correct
Test #64:
score: 0
Accepted
time: 81ms
memory: 6008kb
input:
31 2067 ???????????????????????????????
output:
-1
result:
ok correct
Test #65:
score: 0
Accepted
time: 86ms
memory: 5880kb
input:
32 1267 ????????????????????????????????
output:
-1
result:
ok correct
Test #66:
score: 0
Accepted
time: 128ms
memory: 11696kb
input:
33 928 ?????????????????????????????????
output:
NNNNNAAAAAAANAAACACCCACCACCCCCCCC
result:
ok correct
Test #67:
score: 0
Accepted
time: 181ms
memory: 17900kb
input:
34 298 ??????????????????????????????????
output:
NNAACANAACCACCCACAACACABBAACCBAACC
result:
ok correct
Test #68:
score: 0
Accepted
time: 115ms
memory: 6276kb
input:
35 2361 ???????????????????????????????????
output:
-1
result:
ok correct
Test #69:
score: 0
Accepted
time: 198ms
memory: 19076kb
input:
36 489 ????????????????????????????????????
output:
NNAAACANAAACAAACCCAACNCAACCAACCCCBAC
result:
ok correct
Test #70:
score: 0
Accepted
time: 218ms
memory: 19784kb
input:
37 294 ?????????????????????????????????????
output:
NNAAAAAAAAAACCCAABACBABCBNBBCCACCBBCC
result:
ok correct
Test #71:
score: 0
Accepted
time: 188ms
memory: 12264kb
input:
38 1558 ??????????????????????????????????????
output:
NNNNNNANAAAAAAAAACACAACCCCCCACCCCCCCCC
result:
ok correct
Test #72:
score: 0
Accepted
time: 225ms
memory: 16524kb
input:
39 1319 ???????????????????????????????????????
output:
NNNNANACANAAAAAAAAAACACNCCACAACCCCCCCCC
result:
ok correct
Test #73:
score: 0
Accepted
time: 256ms
memory: 20012kb
input:
40 993 ????????????????????????????????????????
output:
NNNNACNAANAAAAACAACCBCCBNCCAACCACCBCCCAC
result:
ok correct
Test #74:
score: 0
Accepted
time: 170ms
memory: 6668kb
input:
40 498 ACNANACNNACNACNNNCNCNNNANNNACNCCACAA?ANA
output:
-1
result:
ok correct
Test #75:
score: 0
Accepted
time: 169ms
memory: 6596kb
input:
40 855 NAAANAACNNNCNAANCNANCNANACANCCAANCACNCAC
output:
-1
result:
ok correct
Test #76:
score: 0
Accepted
time: 165ms
memory: 6504kb
input:
40 1007 ?CNACNNAANACANACNACCC?CAANNCCCCANNANCACN
output:
-1
result:
ok correct
Test #77:
score: 0
Accepted
time: 169ms
memory: 6592kb
input:
40 1778 NACANANN?CCANNCCAACNNCCNCCCNCCNACCNC?NNN
output:
-1
result:
ok correct
Test #78:
score: 0
Accepted
time: 165ms
memory: 6660kb
input:
40 2186 ACCCACAN?NNA?AACCNNNN?ANACCANCNCNNCA?NCN
output:
-1
result:
ok correct
Test #79:
score: 0
Accepted
time: 170ms
memory: 6512kb
input:
40 332 ACAC?NCCCANAA?ACCNNC?NAC?CAC?CNCNNACNNNN
output:
-1
result:
ok correct
Test #80:
score: 0
Accepted
time: 165ms
memory: 6424kb
input:
40 712 ANCNANAAC?CACAACA?CNACCCANAACCA?CNNAANCN
output:
-1
result:
ok correct
Test #81:
score: 0
Accepted
time: 165ms
memory: 6428kb
input:
40 1127 C?CAAAANNCANANAC?NCANACANAACAACANNCCNCAC
output:
-1
result:
ok correct
Test #82:
score: 0
Accepted
time: 165ms
memory: 6632kb
input:
40 1835 CANNCAANNNAANANNCACANAC?CCCCAACA?NNNCAC?
output:
-1
result:
ok correct
Test #83:
score: 0
Accepted
time: 165ms
memory: 6372kb
input:
40 2009 CANAAAN?ANAACNCCNCCNCAAANCANCCAN?CCNCAAN
output:
-1
result:
ok correct
Test #84:
score: 0
Accepted
time: 170ms
memory: 6700kb
input:
40 54 CNAC?ACAAC?ACC?ANC?C?NNCAANCCAC?NCN?CACA
output:
-1
result:
ok correct
Test #85:
score: 0
Accepted
time: 167ms
memory: 6796kb
input:
40 955 ?A?ANA?NN?C?ANC??CNNACAAC?N?AAN?AN??ANNA
output:
-1
result:
ok correct
Test #86:
score: 0
Accepted
time: 170ms
memory: 6400kb
input:
40 1451 ??CCCA?N?ACCN?C???NNN??C?ANAN??NCNA??NAN
output:
-1
result:
ok correct
Test #87:
score: 0
Accepted
time: 168ms
memory: 6656kb
input:
40 1526 CN??AC?CCCCNACCNCNCCNC?CAAN?C?CA??ANCN?A
output:
-1
result:
ok correct
Test #88:
score: 0
Accepted
time: 169ms
memory: 6628kb
input:
40 2453 C?NC?CCAAN?ACCCNCC??ACAANCANCNCNNAACC?NN
output:
-1
result:
ok correct
Test #89:
score: 0
Accepted
time: 180ms
memory: 9044kb
input:
40 166 ?NC??AACAN??NCA?CCAA?A??CNNN?ACNN?AN?ANC
output:
ANCCCAACANBCNCACCCAABACCCNNNCACNNCANBANC
result:
ok correct
Test #90:
score: 0
Accepted
time: 185ms
memory: 10776kb
input:
40 887 ?NA?AN?N?A?ANN??N?ANCAN?N????AC?NN?NA???
output:
NNANANCNAAAANNAANAANCANCNCACAACCNNCNACCC
result:
ok correct
Test #91:
score: 0
Accepted
time: 169ms
memory: 6640kb
input:
40 1310 CCN?NNANC??CANN??NC?N??NA?NNNNCN?N?CCCCC
output:
-1
result:
ok correct
Test #92:
score: 0
Accepted
time: 166ms
memory: 6368kb
input:
40 1568 ANCN?N?NACC??NNN?AAC?AANA?CA?NC?CNNAN??N
output:
-1
result:
ok correct
Test #93:
score: 0
Accepted
time: 165ms
memory: 6596kb
input:
40 2035 CA?N?ACCNN??CANA?NC?NACNC??CC???NCA?N?AC
output:
-1
result:
ok correct
Test #94:
score: 0
Accepted
time: 184ms
memory: 9588kb
input:
40 126 AC?CACCCN???C?NCCN?NN??CN?CNCN?C?N?C?A?C
output:
ACACACCCNACACANCCNBNNCACNCCNCNCCCNCCCACC
result:
ok correct
Test #95:
score: 0
Accepted
time: 184ms
memory: 9560kb
input:
40 962 CCC???A??????AN?N???C?NN??CANA?CNA??N???
output:
CCCNNNANNNNNAANANAAACCNNCACANAACNACCNCCC
result:
ok correct
Test #96:
score: 0
Accepted
time: 171ms
memory: 7224kb
input:
40 1043 ?A??NANA?CN?N?AN?ANN?CNAANCC??AAANNN????
output:
-1
result:
ok correct
Test #97:
score: 0
Accepted
time: 161ms
memory: 6460kb
input:
40 1638 N?ANA?NA???A??N?CNNAA???NC????CNN??AC??N
output:
-1
result:
ok correct
Test #98:
score: 0
Accepted
time: 170ms
memory: 6360kb
input:
40 2240 NNC??NCA???N?N?NNC??CNNNAN??C?AN??AC?C??
output:
-1
result:
ok correct
Test #99:
score: 0
Accepted
time: 175ms
memory: 7864kb
input:
40 55 N?NCNC????C?A??A?A?NN??ACC??C??NC???ACN?
output:
-1
result:
ok correct
Test #100:
score: 0
Accepted
time: 209ms
memory: 14852kb
input:
40 639 C???NN??C?N?N????N?CA?NCAN????AN????NA??
output:
CNNANNAACANANACCCNACACNCANCBBAANACCCNACC
result:
ok correct
Test #101:
score: 0
Accepted
time: 170ms
memory: 6440kb
input:
40 1438 ?C?A?NA?AN???CA???NAAAN??A?NNANNCAA?????
output:
-1
result:
ok correct
Test #102:
score: 0
Accepted
time: 170ms
memory: 6640kb
input:
40 1660 ???C?A???????NN??AANNAC???A?CN??ACN?AC?C
output:
-1
result:
ok correct
Test #103:
score: 0
Accepted
time: 169ms
memory: 6312kb
input:
40 2016 ??AA??N?N??A?C?C????????C????C?C?CN??N?A
output:
-1
result:
ok correct
Test #104:
score: 0
Accepted
time: 211ms
memory: 15392kb
input:
40 242 ?C???A???AA??A??C?CN???C???A?ANA?NN??AA?
output:
NCNAAACCCAACCACCCCCNCBCCCBAAAANACNNCBAAC
result:
ok correct
Test #105:
score: 0
Accepted
time: 225ms
memory: 15088kb
input:
40 711 ??A?AA?C??C???CCNA?????C????A?????A??C??
output:
NNANAANCAACCCACCNAACCCCCCABAACACCCAACCCC
result:
ok correct
Test #106:
score: 0
Accepted
time: 205ms
memory: 13064kb
input:
40 1094 ??AACN??N?A?????C????AA??CC???CC?N?A????
output:
NNAACNANNNAAAAAACCCCCAAACCCCACCCCNCACCCC
result:
ok correct
Test #107:
score: 0
Accepted
time: 162ms
memory: 6428kb
input:
40 1878 ?A??AACCA????N???A???C?C?C??C?NANC?N?NAC
output:
-1
result:
ok correct
Test #108:
score: 0
Accepted
time: 162ms
memory: 6600kb
input:
40 2082 AC??ACANC?CN?C?N???C?N???N??C?CC?????C?C
output:
-1
result:
ok correct
Test #109:
score: 0
Accepted
time: 218ms
memory: 14716kb
input:
40 268 N?N??NNNCNC??CAC????A?C?????N???AN??NC??
output:
NCNAANNNCNCCCCACACCCACCCBBCBNBCCANBCNCBB
result:
ok correct
Test #110:
score: 0
Accepted
time: 228ms
memory: 16860kb
input:
40 960 ?????????N???NA?????????C??AC???AN?A???A
output:
NNNNNAACNNNAANAAAABCNCCBCCCACCCCANCAACCA
result:
ok correct
Test #111:
score: -100
Wrong Answer
time: 208ms
memory: 11656kb
input:
40 1342 ???C?????C?????NA?N??N?C?????A?N???NA???
output:
-1
result:
wrong answer returned false