結果
| 問題 | No.26 シャッフルゲーム | 
| コンテスト | |
| ユーザー |  sora410_t | 
| 提出日時 | 2020-03-31 17:01:54 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 920 bytes | 
| コンパイル時間 | 890 ms | 
| コンパイル使用メモリ | 78,316 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-24 20:36:35 | 
| 合計ジャッジ時間 | 1,369 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#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;
}
            
            
            
        