QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526480#8776. Not Another Constructive!OneWan#WA 100ms432332kbC++234.8kb2024-08-21 16:40:262024-08-21 16:40:27

Judging History

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

  • [2024-08-21 16:40:27]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:432332kb
  • [2024-08-21 16:40:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long; 
#define len 50
int ss[len][len][len][2505];  //0 pre 1 now
int pre[len][len][len][2505];
int idx=0;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    set<int>st;
    st.insert(0);
    s=" "+s;
    ss[0][0][0][0]=++idx;
    for (int i = 1; i <= n; i++) {  
        if(s[i] != 'N' && s[i] != 'A' && s[i] != 'C' && s[i] != '?') {
            for(int x=0;x<=40;x++){
            	for(int y=0;y<=40;y++){
            		for(int cnt=0;cnt<=2500;cnt++){ 
	            		if(ss[i-1][x][y][cnt]){
	            			ss[i][x][y][cnt]=++idx;
	            			pre[i][x][y][cnt]=ss[i-1][x][y][cnt];
	            		} 
            		}
            	}
            }
            continue;
        } 
        if(s[i] == 'N') {
            //set<int>nst;
//             
            // for (auto &a : st) {
            	// auto [x, y, cnt] = re(a);
                // if(!nst.count(get(x + 1, y, cnt))) 
                    // nst.insert(get(x + 1, y, cnt));
            // }
            // swap(st, nst);
            for(int x=0;x<=40;x++){
            	for(int y=0;y<=40;y++){
            		for(int cnt=0;cnt<=2500;cnt++){
            			if(ss[i-1][x][y][cnt]&&ss[i][x+1][y][cnt]==0){
            				ss[i][x+1][y][cnt]=++idx;
            				pre[i][x+1][y][cnt]=ss[i-1][x][y][cnt];
            			}
            		}
            	}
            }
        }
        if(s[i] == 'A') {
            // set<int>nst;
            // for (auto &a : st) {
            	       	// auto [x, y, cnt] = re(a);
                // if(!nst.count(get(x, y + x, cnt))) 
                    // nst.insert(get(x, y + x, cnt));
            // }
            // swap(st, nst);
            
             for(int x=0;x<=40;x++){
            	for(int y=0;y<=40;y++){
            		for(int cnt=0;cnt<=2500;cnt++){
            			if(ss[i-1][x][y][cnt]&&ss[i][x][y+x][cnt]==0){
            				ss[i][x][y+x][cnt]=++idx;
            				pre[i][x][y+x][cnt]=ss[i-1][x][y][cnt];
            			}
            		}
            	}
            }
        }
        if(s[i] == 'C') {
            // set<int>nst;
            // for (auto &a : st) {
            	 	// auto [x, y, cnt] = re(a);
                // if(cnt + y <= k && !nst.count(get(x, y, cnt + y))) 
                    // nst.insert(get(x, y, cnt + y));
            // }
            // swap(st, nst);
              for(int x=0;x<=40;x++){
            	for(int y=0;y<=40;y++){
            		for(int cnt=0;cnt<=2500;cnt++){
            			if(!ss[i-1][x][y][cnt])continue;
            			if(cnt+y<=k&&ss[i][x][y][cnt+y]==0){
            				ss[i][x][y][cnt+y]=++idx;
            				pre[i][x][y][cnt+y]=ss[i-1][x][y][cnt];
            			}
            		}
            	}
            }
        }
        if(s[i] == '?') { 
            for(int x=0;x<=40;x++){
            	for(int y=0;y<=40;y++){
            		for(int cnt=0;cnt<=2500;cnt++){
            			if(!ss[i-1][x][y][cnt])continue;
            			if(ss[i-1][x][y][cnt]){
	            			ss[i][x][y][cnt]=++idx;
	            			pre[i][x][y][cnt]=ss[i-1][x][y][cnt];
	            		} 
            			if(ss[i-1][x][y][cnt]&&ss[i][x+1][y][cnt]==0){
            				ss[i][x+1][y][cnt]=++idx;
            				pre[i][x+1][y][cnt]=ss[i-1][x][y][cnt];
            			}
            			if(ss[i-1][x][y][cnt]&&ss[i][x][y+x][cnt]==0){
            				ss[i][x][y+x][cnt]=++idx;
            				pre[i][x][y+x][cnt]=ss[i-1][x][y][cnt];
            			}
            			if(cnt+y<=k&&ss[i][x][y][cnt+y]==0){
            				ss[i][x][y][cnt+y]=++idx;
            				pre[i][x][y][cnt+y]=ss[i-1][x][y][cnt];
            			}
            		}
            	}
            }
          
        } 
    }  
    int i = n, x = -1, y = -1, cnt = k;
	for (int x1 = 0; x1 <= 40; x1++)
		for (int y1 = 0; y1 <= 40; y1++) {
			if(ss[n][x1][y1][k]) x = x1, y = y1;
		}
		
    if((x==-1)&&(y==-1)) {
    	cout << "-1\n";
    	return 0;
    }
    
    vector<char>ans;
    
    while(1) {
    	if(i==0)break;
    	if(pre[i][x][y][cnt] == ss[i - 1][x][y][cnt]) {
    		i--;
    		ans.push_back('B');
    		continue; 
    	}
    	if(pre[i][x][y][cnt] == ss[i - 1][x - 1][y][cnt]) {
    		x = x - 1;
    		i--;
    		ans.push_back('N');
    		continue; 
    	}
    	if(y - x >= 0 && pre[i][x][y][cnt] == ss[i - 1][x][y - x][cnt]) {
    		y -= x;
    		i--;
    		ans.push_back('A');
    		continue; 
    	}
    	if(pre[i][x][y][cnt] == ss[i - 1][x][y][cnt - y]) {
    		cnt -= y;
    		i--;
    		ans.push_back('C');
    		continue; 
    	}
    }
    
    for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i];
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 64ms
memory: 191668kb

input:

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

output:

NNBANNNNNNCNNNNNNNNNNN

result:

ok correct

Test #2:

score: 0
Accepted
time: 49ms
memory: 71216kb

input:

18 0
COUNTINGSATELLITES

output:

BBBNBBNBBABBBBBBBB

result:

ok correct

Test #3:

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

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

score: 0
Accepted
time: 4ms
memory: 9932kb

input:

1 0
?

output:

N

result:

ok correct

Test #5:

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

input:

1 0
N

output:

N

result:

ok correct

Test #6:

score: 0
Accepted
time: 4ms
memory: 9628kb

input:

1 0
X

output:

B

result:

ok correct

Test #7:

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

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

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

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

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

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

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

input:

2 0
??

output:

NN

result:

ok correct

Test #11:

score: 0
Accepted
time: 4ms
memory: 13724kb

input:

2 0
N?

output:

NN

result:

ok correct

Test #12:

score: 0
Accepted
time: 7ms
memory: 11724kb

input:

2 0
?C

output:

NB

result:

ok correct

Test #13:

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

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

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

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

score: 0
Accepted
time: 10ms
memory: 17896kb

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

score: 0
Accepted
time: 9ms
memory: 19956kb

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

score: 0
Accepted
time: 11ms
memory: 16108kb

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

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

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

score: 0
Accepted
time: 12ms
memory: 13788kb

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

score: 0
Accepted
time: 11ms
memory: 13740kb

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

score: 0
Accepted
time: 12ms
memory: 20212kb

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

score: 0
Accepted
time: 9ms
memory: 24112kb

input:

4 1
????

output:

NACN

result:

ok correct

Test #23:

score: 0
Accepted
time: 11ms
memory: 28192kb

input:

4 1
X???

output:

BNAC

result:

ok correct

Test #24:

score: 0
Accepted
time: 15ms
memory: 32488kb

input:

4 1
???Z

output:

NACB

result:

ok correct

Test #25:

score: 0
Accepted
time: 16ms
memory: 24096kb

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

score: 0
Accepted
time: 15ms
memory: 19936kb

input:

4 1
N???

output:

NACN

result:

ok correct

Test #27:

score: 0
Accepted
time: 15ms
memory: 22044kb

input:

4 1
?N??

output:

BNAC

result:

ok correct

Test #28:

score: 0
Accepted
time: 11ms
memory: 22076kb

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

score: 0
Accepted
time: 16ms
memory: 26172kb

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

score: 0
Accepted
time: 15ms
memory: 26084kb

input:

4 1
A???

output:

BNAC

result:

ok correct

Test #31:

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

input:

4 1
?A??

output:

NACN

result:

ok correct

Test #32:

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

input:

4 1
??A?

output:

NBAC

result:

ok correct

Test #33:

score: 0
Accepted
time: 7ms
memory: 19904kb

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

score: 0
Accepted
time: 14ms
memory: 24132kb

input:

4 1
C???

output:

BNAC

result:

ok correct

Test #35:

score: 0
Accepted
time: 11ms
memory: 28172kb

input:

4 1
?C??

output:

NBAC

result:

ok correct

Test #36:

score: 0
Accepted
time: 9ms
memory: 26400kb

input:

4 1
??C?

output:

NACN

result:

ok correct

Test #37:

score: 0
Accepted
time: 10ms
memory: 20236kb

input:

4 1
???C

output:

NANC

result:

ok correct

Test #38:

score: 0
Accepted
time: 15ms
memory: 34488kb

input:

5 4
?????

output:

NNAAC

result:

ok correct

Test #39:

score: 0
Accepted
time: 15ms
memory: 44844kb

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

score: 0
Accepted
time: 12ms
memory: 48840kb

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

score: 0
Accepted
time: 8ms
memory: 55176kb

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

score: 0
Accepted
time: 23ms
memory: 70476kb

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

score: 0
Accepted
time: 31ms
memory: 79332kb

input:

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

output:

-1

result:

ok correct

Test #44:

score: 0
Accepted
time: 25ms
memory: 85772kb

input:

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

output:

-1

result:

ok correct

Test #45:

score: 0
Accepted
time: 35ms
memory: 93228kb

input:

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

output:

NNNNACNNNNNN

result:

ok correct

Test #46:

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

input:

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

output:

-1

result:

ok correct

Test #47:

score: 0
Accepted
time: 23ms
memory: 120332kb

input:

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

output:

NNNNANAAACACCC

result:

ok correct

Test #48:

score: 0
Accepted
time: 37ms
memory: 133328kb

input:

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

output:

NNNNNNNANACNNNN

result:

ok correct

Test #49:

score: 0
Accepted
time: 47ms
memory: 152852kb

input:

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

output:

-1

result:

ok correct

Test #50:

score: 0
Accepted
time: 39ms
memory: 165572kb

input:

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

output:

-1

result:

ok correct

Test #51:

score: 0
Accepted
time: 43ms
memory: 180932kb

input:

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

output:

-1

result:

ok correct

Test #52:

score: 0
Accepted
time: 40ms
memory: 190096kb

input:

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

output:

NNNNNNNNNNNNNAANACN

result:

ok correct

Test #53:

score: 0
Accepted
time: 45ms
memory: 205916kb

input:

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

output:

-1

result:

ok correct

Test #54:

score: 0
Accepted
time: 62ms
memory: 219740kb

input:

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

output:

-1

result:

ok correct

Test #55:

score: 0
Accepted
time: 52ms
memory: 226216kb

input:

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

output:

-1

result:

ok correct

Test #56:

score: 0
Accepted
time: 63ms
memory: 235072kb

input:

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

output:

-1

result:

ok correct

Test #57:

score: 0
Accepted
time: 61ms
memory: 245624kb

input:

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

output:

-1

result:

ok correct

Test #58:

score: 0
Accepted
time: 60ms
memory: 257496kb

input:

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

output:

-1

result:

ok correct

Test #59:

score: 0
Accepted
time: 78ms
memory: 268100kb

input:

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

output:

NNNNNNNAANAACNACCCCCCCCCCC

result:

ok correct

Test #60:

score: 0
Accepted
time: 60ms
memory: 280324kb

input:

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

output:

NNNNNNNNNANACCANACCCCCCCCCN

result:

ok correct

Test #61:

score: 0
Accepted
time: 80ms
memory: 293424kb

input:

28 274
????????????????????????????

output:

NNNNNNNNNNACNNNNACNNACCCCCCN

result:

ok correct

Test #62:

score: 0
Accepted
time: 83ms
memory: 335364kb

input:

29 1624
?????????????????????????????

output:

-1

result:

ok correct

Test #63:

score: 0
Accepted
time: 85ms
memory: 368012kb

input:

30 2079
??????????????????????????????

output:

-1

result:

ok correct

Test #64:

score: 0
Accepted
time: 91ms
memory: 386792kb

input:

31 2067
???????????????????????????????

output:

-1

result:

ok correct

Test #65:

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

input:

32 1267
????????????????????????????????

output:

-1

result:

ok correct

Test #66:

score: -100
Wrong Answer
time: 84ms
memory: 432332kb

input:

33 928
?????????????????????????????????

output:

-1

result:

wrong answer returned false