QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72942#4273. Good GameSSL_TJH0 63ms29024kbC++142.8kb2023-01-20 21:11:162023-01-20 21:11:20

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-20 21:11:20]
  • 评测
  • 测评结果:0
  • 用时:63ms
  • 内存:29024kb
  • [2023-01-20 21:11:16]
  • 提交

answer

#include<cstdio>
#include<vector>

using namespace std;

const int N = 1e6 + 100;
int n, m, ls[N], rs[N], a[N], Ls[N], Rs[N];
char s[N];
vector <pair<int, int> > ans;
bool shit;

void write() {
	if (shit) {printf("-1"); return ;}
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second);
}

void clean(int l, int sz) {
	if (sz & 1) ans.push_back(make_pair(l, 3)), sz -= 3;
	while (sz) ans.push_back(make_pair(l, 2)), sz -= 2;
}

void lnk_clean(int x, int y) {
	clean(ls[x], rs[x] - ls[x] + 1 + rs[y] - ls[y] + 1);
}

void work() {
	if (shit) return ;
	int k = (m + 1) / 2;
	if (a[k] == 2) {
		int clsz = 0;
		for (int i = 1; i <= k; i++) {
			int l = k - i + 1, r = k + i - 1;
			clean(ls[l], rs[r] - ls[l] + 1 - clsz);
			clsz = rs[r] - ls[l] + 1;
		}
		return ;
	}
	int lc = -1, rc = -1;
	for (int i = k - 1; i >= 1; i--) if (a[i] == 2) {lc = i; break;}
	for (int i = k + 1; i <= m; i++) if (a[i] == 2) {rc = i; break;}
	if (lc == -1 || rc == -1) {shit = 1; return ;}
	if (lc != rc) {
		int dis = min(k - lc, rc - k);
		if (k - lc < rc - k) {
			for (int i = 1; i <= dis; i++) lnk_clean(rc - i + 1, rc + i - 1);
			int tmp = rs[rc + dis - 1] - ls[rc - dis + 1] + 1;
			for (int i = rc + dis + 1; i <= m; i++) ls[i - dis * 2] = ls[i] - tmp, rs[i - dis * 2] = rs[i] - tmp;
			m -= dis * 2;
		}
		else {
			for (int i = 1; i <= dis; i++) lnk_clean(lc - i + 1, lc + i - 1);
			int tmp = rs[lc + dis - 1] - ls[lc - dis + 1] + 1;
			for (int i = lc + dis + 1; i <= m; i++) ls[i - dis * 2] = ls[i] - tmp, rs[i - dis * 2] = rs[i] - tmp;
			m -= dis * 2;
		}
	}
	k = (m + 1) / 2;
	int clsz = 0;
	for (int i = 1; i <= k; i++) {
		int l = k - i + 1, r = k + i - 1;
		clean(ls[l], rs[r] - ls[l] + 1 - clsz);
		clsz = rs[r] - ls[l] + 1;
	}
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	
	for (int L = 1, R; L <= n; L = R + 1) {
		R = L; while (R < n && s[R + 1] == s[R]) R++;
		m++; ls[m] = L; rs[m] = R; if (L != R) a[m] = 2; else a[m] = 1;
	}
	
	int num = 0;
	for (int i = 1; i <= m; i++) {
		if (a[i] == 2) Ls[i] = Ls[i - 1], num = 0;
			else {
				num++; Ls[i] = max(Ls[i - 1], num);
			}
	}
	num = 0;
	for (int i = m; i >= 1; i--) {
		if (a[i] == 2) Rs[i] = Rs[i + 1], num = 0;
			else {
				num++; Rs[i] = max(Rs[i + 1], num);
			}
	}
	
	if (m & 1) {work(); write(); return 0;}
	
	int bk = -1;
	for (int i = 1; i <= m; i += 2)
		if ((a[(i + 1) / 2] == 2 || Ls[i] < i / 2) && (a[(m + i + 1) / 2] == 2 || Rs[i + 1] < (m - i) / 2)) {
			bk = i; break;
		}
	if (bk == -1) shit = 1;
	int tmp = m, tmp_d = rs[bk];
	m = bk; work(); m = tmp;
	for (int i = bk + 1; i <= m; i++) ls[i - bk] = ls[i] - tmp_d, rs[i - bk] = rs[i] - tmp_d, a[i - bk] = a[i];
	m = m - bk; work(); m = tmp;
	write();
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 3ms
memory: 9264kb

input:

9
ABAABBBAA

output:

4
3 2
2 2
2 2
1 3

result:

ok good solution!

Test #2:

score: -3
Wrong Answer
time: 3ms
memory: 9172kb

input:

13
ABABBABABBABA

output:

7
4 2
4 2
3 2
5 2
4 2
2 3
1 2

result:

wrong answer invalid operation on step #2: AB

Subtask #2:

score: 0
Wrong Answer

Test #51:

score: 6
Accepted
time: 0ms
memory: 9080kb

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

ok no solution

Test #52:

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

input:

300
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...

output:

-1

result:

ok no solution

Test #53:

score: -6
Wrong Answer
time: 3ms
memory: 9236kb

input:

299
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

153
96 2
96 2
96 2
96 2
96 2
96 2
96 2
96 2
95 2
94 2
93 2
92 2
91 2
90 2
89 2
88 2
87 2
86 2
85 2
84 2
83 2
82 2
81 2
80 2
79 2
78 2
77 2
76 2
75 2
74 2
73 2
72 2
71 2
70 2
69 2
68 2
67 2
66 2
65 2
64 2
63 2
62 2
61 2
60 2
59 2
58 2
57 2
56 2
55 2
54 2
53 2
52 2
51 2
50 2
49 2
97 2
97 2
97 2
96 2
9...

result:

wrong answer invalid operation on step #5: AB

Subtask #3:

score: 0
Wrong Answer

Test #102:

score: 0
Wrong Answer
time: 1ms
memory: 9236kb

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

3000
1996 2
1996 2
1996 2
1996 2
1995 2
1994 2
1993 2
1992 2
1991 2
1990 2
1989 2
1988 2
1987 2
1986 2
1985 2
1984 2
1983 2
1982 2
1981 2
1980 2
1979 2
1978 2
1977 2
1976 2
1975 2
1974 2
1973 2
1972 2
1971 2
1970 2
1969 2
1968 2
1967 2
1966 2
1965 2
1964 2
1963 2
1962 2
1961 2
1960 2
1959 2
1958 2
1...

result:

wrong answer invalid operation on step #3: BA

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 0
Wrong Answer
time: 63ms
memory: 29024kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

500001
333328 2
333328 2
333328 2
333328 2
333328 2
333328 2
333327 2
333326 2
333325 2
333324 2
333323 2
333322 2
333321 2
333320 2
333319 2
333318 2
333317 2
333316 2
333315 2
333314 2
333313 2
333312 2
333311 2
333310 2
333309 2
333308 2
333307 2
333306 2
333305 2
333304 2
333303 2
333302 2
33330...

result:

wrong answer invalid operation on step #4: AB