提出 #77901016
ソースコード 拡げる
Copy
#include <stdio.h>int N;char S[512345];int nodes[512345];int main(void) {int head = 1;int i;int prev;if (scanf("%d", &N) != 1) return 1;if (scanf("%512343s", S + 1) != 1) return 1;nodes[1] = 2;for (i = 2; i < N; i++) {nodes[i] = (i - 1) ^ (i + 1);}nodes[N] = N - 1;/* i=1 は、1項だけ反転してもどうせ変わらないので飛ばす */for (i = 2; i <= N; i++) {if (S[i] == 'o') {
#include <stdio.h>
int N;
char S[512345];
int nodes[512345];
int main(void) {
int head = 1;
int i;
int prev;
if (scanf("%d", &N) != 1) return 1;
if (scanf("%512343s", S + 1) != 1) return 1;
nodes[1] = 2;
for (i = 2; i < N; i++) {
nodes[i] = (i - 1) ^ (i + 1);
}
nodes[N] = N - 1;
/* i=1 は、1項だけ反転してもどうせ変わらないので飛ばす */
for (i = 2; i <= N; i++) {
if (S[i] == 'o') {
if (i < N) {
nodes[i + 1] ^= i ^ head;
nodes[i] ^= i + 1;
nodes[head] ^= i + 1;
}
head = i;
}
}
for (prev = 0, i = head; i > 0; ) {
int next;
printf(" %d" + (i == head), i);
next = nodes[i] ^ prev;
prev = i;
i = next;
}
putchar('\n');
return 0;
}
/*
こういう時は……Rotateでおなじみ?xor線形リストや!
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Reverse Permutation |
| ユーザ | mikecat |
| 言語 | C23 (GCC 14.2.0) |
| 得点 | 300 |
| コード長 | 837 Byte |
| 結果 | AC |
| 実行時間 | 26 ms |
| メモリ | 6276 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1756 KiB |
| 00_sample_01.txt | AC | 0 ms | 1724 KiB |
| 00_sample_02.txt | AC | 0 ms | 1628 KiB |
| 01_random_00.txt | AC | 23 ms | 6232 KiB |
| 01_random_01.txt | AC | 23 ms | 6276 KiB |
| 01_random_02.txt | AC | 25 ms | 6160 KiB |
| 01_random_03.txt | AC | 25 ms | 6184 KiB |
| 01_random_04.txt | AC | 26 ms | 6240 KiB |
| 01_random_05.txt | AC | 25 ms | 6056 KiB |
| 01_random_06.txt | AC | 24 ms | 6136 KiB |
| 01_random_07.txt | AC | 24 ms | 6240 KiB |
| 01_random_08.txt | AC | 24 ms | 6064 KiB |
| 01_random_09.txt | AC | 24 ms | 6148 KiB |
| 01_random_10.txt | AC | 1 ms | 1628 KiB |
| 01_random_11.txt | AC | 0 ms | 1640 KiB |
| 01_random_12.txt | AC | 0 ms | 1640 KiB |
| 01_random_13.txt | AC | 0 ms | 1648 KiB |
| 01_random_14.txt | AC | 6 ms | 2180 KiB |
| 01_random_15.txt | AC | 3 ms | 2056 KiB |
| 01_random_16.txt | AC | 22 ms | 5412 KiB |
| 01_random_17.txt | AC | 11 ms | 2664 KiB |