QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733830#8776. Not Another Constructive!nice333TL 764ms201116kbC++231.5kb2024-11-10 21:25:152024-11-10 21:25:17

Judging History

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

  • [2024-11-10 21:25:17]
  • 评测
  • 测评结果:TL
  • 用时:764ms
  • 内存:201116kb
  • [2024-11-10 21:25:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    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')f[i][{a1+1,a2,a3}]={'N',o};
            else if(s[i]=='A')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]=='?'){
                if(a1+1<=k)
                    f[i][{a1+1,a2,a3}]={'N',o};
                if(a1+a2<=k)
                    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 0;
    }
    s[n]=cur;
    for(int i=n-1;i>0;i--){
        auto &[o,oo]=f[i][last];
        s[i]=o;
        last=oo;
    }
    s.erase(s.begin());
    cout<<s<<"\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3796kb

input:

22 2
N??A??????C???????????

output:

NEEACEEEEECEEEEEEEEEEE

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

1 0
?

output:

E

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

1 0
N

output:

N

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

1 0
X

output:

X

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2 0
??

output:

EE

result:

ok correct

Test #11:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

2 0
N?

output:

NE

result:

ok correct

Test #12:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

2 0
?C

output:

EC

result:

ok correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

4 1
????

output:

NACE

result:

ok correct

Test #23:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

4 1
N???

output:

NACE

result:

ok correct

Test #27:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

4 1
?N??

output:

ENAC

result:

ok correct

Test #28:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

4 1
?A??

output:

NACE

result:

ok correct

Test #32:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

4 1
??A?

output:

NEAC

result:

ok correct

Test #33:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 1
??C?

output:

NACE

result:

ok correct

Test #37:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

4 1
???C

output:

NAEC

result:

ok correct

Test #38:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

5 4
?????

output:

NAACC

result:

ok correct

Test #39:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

10 112
??????????

output:

-1

result:

ok correct

Test #44:

score: 0
Accepted
time: 2ms
memory: 4104kb

input:

11 110
???????????

output:

-1

result:

ok correct

Test #45:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

12 4
????????????

output:

NACCCCEEEEEE

result:

ok correct

Test #46:

score: 0
Accepted
time: 5ms
memory: 5048kb

input:

13 193
?????????????

output:

-1

result:

ok correct

Test #47:

score: 0
Accepted
time: 5ms
memory: 6076kb

input:

14 91
??????????????

output:

NNNANAAACACCCC

result:

ok correct

Test #48:

score: 0
Accepted
time: 3ms
memory: 4600kb

input:

15 15
???????????????

output:

NACACCCCCCCEEEE

result:

ok correct

Test #49:

score: 0
Accepted
time: 21ms
memory: 9888kb

input:

16 261
????????????????

output:

-1

result:

ok correct

Test #50:

score: 0
Accepted
time: 28ms
memory: 13084kb

input:

17 514
?????????????????

output:

-1

result:

ok correct

Test #51:

score: 0
Accepted
time: 42ms
memory: 17968kb

input:

18 678
??????????????????

output:

-1

result:

ok correct

Test #52:

score: 0
Accepted
time: 30ms
memory: 12624kb

input:

19 40
???????????????????

output:

NACAACCCCCCCCCCCCCE

result:

ok correct

Test #53:

score: 0
Accepted
time: 101ms
memory: 34372kb

input:

20 1019
????????????????????

output:

-1

result:

ok correct

Test #54:

score: 0
Accepted
time: 156ms
memory: 46804kb

input:

21 1218
?????????????????????

output:

-1

result:

ok correct

Test #55:

score: 0
Accepted
time: 222ms
memory: 64064kb

input:

22 1348
??????????????????????

output:

-1

result:

ok correct

Test #56:

score: 0
Accepted
time: 308ms
memory: 86512kb

input:

23 476
???????????????????????

output:

-1

result:

ok correct

Test #57:

score: 0
Accepted
time: 428ms
memory: 115952kb

input:

24 1445
????????????????????????

output:

-1

result:

ok correct

Test #58:

score: 0
Accepted
time: 606ms
memory: 154132kb

input:

25 1331
?????????????????????????

output:

-1

result:

ok correct

Test #59:

score: 0
Accepted
time: 764ms
memory: 201116kb

input:

26 459
??????????????????????????

output:

NNNANAAAAAAAAAAAACCCCCCCCC

result:

ok correct

Test #60:

score: -100
Time Limit Exceeded

input:

27 398
???????????????????????????

output:

NNANAAAACAAAAAACCCCCCCCCCCC

result: