QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73728#4273. Good Game123456780 24ms66940kbC++142.2kb2023-01-27 20:12:152023-01-27 20:12:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-27 20:12:18]
  • 评测
  • 测评结果:0
  • 用时:24ms
  • 内存:66940kb
  • [2023-01-27 20:12:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define inf 1e9
#define pii pair <int, int>
const int mod = 1e9 + 7;
inline int read () {
	int x = 0, f = 1;
	char ch = getchar ();
	while (ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar ();
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ();
	return x * f;
}
inline void write (int x) {
	if (x < 0) x = -x, putchar ('-');
	if (x >= 10) write (x / 10);
	putchar (x % 10 + '0');
}
int n;
char ch[1000005];
int tot;
pii a[1000005];
vector <pii> Ans;
int f[1000005][3], pre[1000005][3];
signed main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	n = read();
	scanf("%s", ch + 1);
	a[tot = 1] = mp((ch[1] == 'A') ? 0 : 1, 1);
	for(int i = 2; i <= n; i++) {
		if(ch[i] != ch[i-1]) a[++tot] = mp((ch[i] == 'A') ? 0 : 1, 1);
		else a[tot].second++;
	}
	f[0][0] = 1;
	for(int i = 0; i <= tot; i++) f[i][1] = f[i][2] = inf;
	for(int i = 1; i <= tot; i++) {
		if(f[i-1][0]) {
			if(a[i].second >= 2) f[i][0] = 1, pre[i][0] = 0;
			if(!a[i].first) f[i][1] = 1, pre[i][1] = 0;
			else f[i][2] = 1, pre[i][2] = 0;
		}
		if(f[i-1][1] != inf) {
			if(!a[i].first) {
				if(f[i-1][1] == 1) f[i][0] = 1, pre[i][0] = 1;
				else {
					if(f[i-1][1] < f[i][1]) f[i][1] = f[i-1][1], pre[i][1] = 1;
					if(f[i-1][1] - 1 < f[i][2]) f[i][2] = f[i-1][1] - 1, pre[i][2] = 1;
				}	
			}
			else {
				if(f[i-1][1] + 1 < f[i][2]) f[i][2] = f[i-1][1] + 1, pre[i][2] = 1;
				if(a[i].second >= 2 && f[i-1][1] < f[i][1]) f[i][1] = f[i-1][1], pre[i][1] = 1; 
			}
		}
		if(f[i-1][2] != inf) {
			if(a[i].first) {
				if(f[i-1][2] == 1) f[i][0] = 1, pre[i][0] = 2;
				else {
					if(f[i-1][2] < f[i][2]) f[i][2] = f[i-1][2], pre[i][2] = 2;
					if(f[i-1][2] - 1 < f[i][1]) f[i][1] = f[i-1][2] - 1, pre[i][1] = 2;
				}	
			}
			else {
				if(f[i-1][2] + 1 < f[i][1]) f[i][1] = f[i-1][2] + 1, pre[i][1] = 2;
				if(a[i].second >= 2 && f[i-1][2] < f[i][2]) f[i][2] = f[i-1][2], pre[i][2] = 2; 
			}
		}
	}
	if(!f[tot][0]) return printf("-1\n") & 0;
	
	write((int)Ans.size()), putchar('\n');
	for(auto x : Ans) write(x.first), putchar(' '), write(x.second), putchar('\n');
	return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5332kb

input:

9
ABAABBBAA

output:

0

result:

wrong answer the string has not been fully deleted

Subtask #2:

score: 0
Wrong Answer

Test #51:

score: 6
Accepted
time: 1ms
memory: 5512kb

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

ok no solution

Test #52:

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

input:

300
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...

output:

-1

result:

ok no solution

Test #53:

score: -6
Wrong Answer
time: 2ms
memory: 3624kb

input:

299
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

-1

result:

wrong answer you didn't find a solution but jury did

Subtask #3:

score: 0
Wrong Answer

Test #102:

score: 0
Wrong Answer
time: 0ms
memory: 3856kb

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

-1

result:

wrong answer you didn't find a solution but jury did

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 0
Wrong Answer
time: 24ms
memory: 66940kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

wrong answer you didn't find a solution but jury did