CODE FESTIVAL 2016 Relay (Parallel)

Submission #1352124

Source codeソースコード

#include <cstdio>
#include <algorithm>
int n, q, x[100009], y[100009], a[100009], p[100009]; bool ok[100009];
int main() {
	scanf("%d %d", &n, &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &x[i], &y[i]); x[i]--, y[i]--; a[i + 1] = a[i];
		if (a[i] == x[i]) a[i + 1] = y[i];
		if (a[i] == y[i]) a[i + 1] = x[i];
	}
	ok[a[q]] = true;
	for (int i = 0; i < n; i++) p[i] = i;
	for (int i = q; i >= 0; i--) {
		if (i != q) std::swap(p[x[i]], p[y[i]]);
		if (a[i] != 0) ok[p[a[i] - 1]] = true;
		if (a[i] != n - 1) ok[p[a[i] + 1]] = true;
	}
	int ret = 0;
	for (int i = 0; i < n; i++) ret += ok[i];
	printf("%d\n", ret);
	return 0;
}

Submission

Task問題 G - 超能力 / Magician
User nameユーザ名 square1001
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 654 Byte
File nameファイル名
Exec time実行時間 18 ms
Memory usageメモリ使用量 1792 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:5:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
^
./Main.cpp:7:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x[i], &y[i]); x[i]--, y[i]--; a[i + 1] = a[i];
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 100 / 100 sample_01.txt,sample_02.txt,sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 128 KB
sample_02.txt AC 1 ms 128 KB
subtask1_01.txt AC 18 ms 1792 KB
subtask1_02.txt AC 18 ms 1792 KB
subtask1_03.txt AC 18 ms 1792 KB
subtask1_04.txt AC 18 ms 1792 KB
subtask1_05.txt AC 18 ms 1792 KB
subtask1_06.txt AC 18 ms 1792 KB
subtask1_07.txt AC 18 ms 1792 KB
subtask1_08.txt AC 18 ms 1792 KB
subtask1_09.txt AC 18 ms 1792 KB
subtask1_10.txt AC 18 ms 1792 KB
subtask1_11.txt AC 18 ms 1792 KB
subtask1_12.txt AC 18 ms 1792 KB
subtask1_13.txt AC 18 ms 1792 KB
subtask1_14.txt AC 18 ms 1792 KB
subtask1_15.txt AC 18 ms 1792 KB
subtask1_16.txt AC 18 ms 1792 KB
subtask1_17.txt AC 18 ms 1792 KB
subtask1_18.txt AC 18 ms 1792 KB
subtask1_19.txt AC 18 ms 1792 KB