結果

問題 No.26 シャッフルゲーム
ユーザー sora410_tsora410_t
提出日時 2020-03-31 16:54:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 77,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 01:45:49
合計ジャッジ時間 1,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 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 bfr {p-1};
		const int aft {q-1};

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