Submission #69062698
Source Code Expand
Copy
#include <stdio.h>#include <inttypes.h>int N;char S[512345 * 2];int main(void) {int i, next;char wanted;uint64_t ans1 = 0, ans2 = 0;if (scanf("%d", &N) != 1) return 1;if (scanf("%1012344s", S) != 1) return 1;/* ABAB… にする */for (i = 0, next = 0, wanted = 'A'; i < 2 * N; i++) {if (S[i] == wanted) {if (next == i) {next++;wanted = wanted == 'A' ? 'B' : 'A';} else {ans1 += i - next;
#include <stdio.h>
#include <inttypes.h>
int N;
char S[512345 * 2];
int main(void) {
int i, next;
char wanted;
uint64_t ans1 = 0, ans2 = 0;
if (scanf("%d", &N) != 1) return 1;
if (scanf("%1012344s", S) != 1) return 1;
/* ABAB… にする */
for (i = 0, next = 0, wanted = 'A'; i < 2 * N; i++) {
if (S[i] == wanted) {
if (next == i) {
next++;
wanted = wanted == 'A' ? 'B' : 'A';
} else {
ans1 += i - next;
next += 2;
}
}
}
/* BABA… にする */
for (i = 0, next = 0, wanted = 'B'; i < 2 * N; i++) {
if (S[i] == wanted) {
if (next == i) {
next++;
wanted = wanted == 'A' ? 'B' : 'A';
} else {
ans2 += i - next;
next += 2;
}
}
}
printf("%" PRIu64 "\n", ans1 <= ans2 ? ans1 : ans2);
return 0;
}
/*
wanted: ABABAB
actual: BBAABA
ABBABA ans1 += 2
ABABBA ans1 += 1
ABABAB ans1 += 1
wanted: ABABAB
actual: AAABBB
*/
Submission Info
| Submission Time | |
|---|---|
| Task | C - Alternated |
| User | mikecat |
| Language | C (gcc 12.2.0) |
| Score | 350 |
| Code Size | 969 Byte |
| Status | AC |
| Exec Time | 11 ms |
| Memory | 2724 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 10 ms | 2700 KiB |
| random_02.txt | AC | 9 ms | 2428 KiB |
| random_03.txt | AC | 11 ms | 2724 KiB |
| random_04.txt | AC | 4 ms | 2008 KiB |
| random_05.txt | AC | 11 ms | 2632 KiB |
| random_06.txt | AC | 5 ms | 2208 KiB |
| random_07.txt | AC | 4 ms | 2608 KiB |
| random_08.txt | AC | 4 ms | 2600 KiB |
| random_09.txt | AC | 4 ms | 2680 KiB |
| random_10.txt | AC | 3 ms | 2612 KiB |
| random_11.txt | AC | 3 ms | 2576 KiB |
| random_12.txt | AC | 3 ms | 2712 KiB |
| random_13.txt | AC | 0 ms | 1624 KiB |
| sample_01.txt | AC | 0 ms | 1752 KiB |
| sample_02.txt | AC | 0 ms | 1728 KiB |
| sample_03.txt | AC | 0 ms | 1628 KiB |