QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733326#8776. Not Another Constructive!aYi_7WA 2ms4324kbC++171.8kb2024-11-10 18:17:352024-11-10 18:17:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 18:17:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4324kb
  • [2024-11-10 18:17:35]
  • 提交

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;
}

詳細信息

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