結果

問題 No.26 シャッフルゲーム
ユーザー sora410_tsora410_t
提出日時 2020-03-31 17:01:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 920 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 01:58:46
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <numeric>
#include <iterator>
#include <cmath>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;

namespace Estd {
	// return 1's position (...3210) by given bs;
	// invarient: bs.count() == 1;
	// ex: 0000100 -> 2
	template<size_t N>
	constexpr size_t position(const bitset<N> bs) {
		assert(bs.count() == 1);
		for (int i = 0; i < N; ++i) {
			if (bs[i] == 1)
				return i;
		}
		throw;
	}
};

int main() {
	int N {};
	int M {};
	cin >> N >> M;

	bitset<3> res {};
	res.set(N-1);
	for (int i = 0; i < M; ++i) {
		int p {};
		int q {};
		cin >> p >> q;

		const int fir {p-1};
		const int sec {q-1};

		if (res[fir]) {
			res.reset(fir);
			res.set(sec);
		} else if (res[sec]) {
			res.set(fir);
			res.reset(sec);
		} else {
			continue;
		}
	}
	cout << Estd::position(res) + 1 << endl;
}
0