CODE FESTIVAL 2016 Relay (Parallel)

Submission #1350832

Source codeソースコード

#include<iostream>
#include<cmath>
using namespace std;
int n, q, a[100009], b[100009], c[100009], d[100009], e[100009];
int main() {
	cin >> n >> q; c[0] = 1;
	for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i]; if (c[i - 1] == a[i])c[i] = b[i]; else if (c[i - 1] == b[i])c[i] = a[i]; else c[i] = c[i - 1]; }
	for (int i = 1; i <= n; i++) { d[i] = i; if (abs(d[i] - c[q]) <= 1)e[i] = 1; }
	for (int i = q; i >= 1; i--) {
		swap(d[a[i]], d[b[i]]);
		e[d[c[i - 1] - 1]] = 1; e[d[c[i - 1]]] = 1; e[d[c[i - 1] + 1]] = 1;
	}
	int cnt = 0; for (int i = 1; i <= n; i++)cnt += e[i];
	cout << cnt << endl;
	return 0;
}

Submission

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

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 256 KB
sample_02.txt AC 1 ms 256 KB
subtask1_01.txt AC 71 ms 1792 KB
subtask1_02.txt AC 73 ms 1792 KB
subtask1_03.txt AC 71 ms 1792 KB
subtask1_04.txt AC 72 ms 1792 KB
subtask1_05.txt AC 71 ms 1792 KB
subtask1_06.txt AC 73 ms 1792 KB
subtask1_07.txt AC 71 ms 1792 KB
subtask1_08.txt AC 72 ms 1792 KB
subtask1_09.txt AC 72 ms 1920 KB
subtask1_10.txt AC 71 ms 1792 KB
subtask1_11.txt AC 72 ms 1792 KB
subtask1_12.txt AC 71 ms 1792 KB
subtask1_13.txt AC 73 ms 1792 KB
subtask1_14.txt AC 71 ms 1792 KB
subtask1_15.txt AC 73 ms 1792 KB
subtask1_16.txt AC 71 ms 1792 KB
subtask1_17.txt AC 73 ms 1792 KB
subtask1_18.txt AC 74 ms 1792 KB
subtask1_19.txt AC 72 ms 1792 KB