QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733326 | #8776. Not Another Constructive! | aYi_7 | WA | 2ms | 4324kb | C++17 | 1.8kb | 2024-11-10 18:17:35 | 2024-11-10 18:17:36 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
using namespace std;
void solve() {
int n,k;cin>>n>>k;
string s;cin>>s;s="#"+s;
vector<map<array<int,3>,pair<char,array<int,3>>>>f(n+1,map<array<int,3>,pair<char,array<int,3>>>());
f[0][{0,0,0}]={'#',{0,0,0}};
for(int i=1;i<=n;i++){
for(auto [o,oo]:f[i-1]){
auto [a1,a2,a3]=o;
if(s[i]=='N'){
if(a1+1<=k)
f[i][{a1+1,a2,a3}]={'N',o};
}
else if(s[i]=='A'){
if(a1+a2<=k)
f[i][{a1,a1+a2,a3}]={'A',o};
}
else if(s[i]=='C'){
if(a2+a3<=k)
f[i][{a1,a2,a2+a3}]={'C',o};
}
else if(s[i]=='?'){
f[i][{a1+1,a2,a3}]={'N',o};
f[i][{a1,a1+a2,a3}]={'A',o};
if(a2+a3<=k)
f[i][{a1,a2,a2+a3}]={'C',o};
f[i][o]={'E',o};
}
else f[i][o]={s[i],o};
}
}
char cur='#';
array<int,3>last;
for(auto [o,oo]:f[n]){
auto [a1,a2,a3]=o;
if(a3==k){
cur=oo.first;
last=oo.second;
break;
}
}
if(cur=='#'){
cout<<"-1\n";
return;
}
s[n]=cur;
for(int i=n-1;i>0;i--){
//cout<<i<<" "<<last[0]<<" "<<last[1]<<" "<<last[2]<<"\n";
auto [o,oo]=f[i][last];
s[i]=o;
last=oo;
}
s.erase(s.begin());
cout<<s<<"\n";
}
/**
22 2
N??A??????C???????????
* **/
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4324kb
input:
22 2 N??A??????C???????????
output:
NEEACEEEEECEEEEEEEEEEE
result:
ok correct
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3576kb
input:
18 0 COUNTINGSATELLITES
output:
-1
result:
wrong answer returned false