結果

問題 No.1777 万華鏡美術館
ユーザー 👑 NachiaNachia
提出日時 2021-12-12 23:00:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 3,153 ms
コード長 1,472 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 86,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 16:48:07
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 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
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
int M;
vector<int> num_edges;
vector<vector<int>> E;

int main() {
	int ans = 4;
	cin >> N;
	cin >> M;
	E.resize(N);
	num_edges.assign(N, 0);
	rep(i,M){
		int u,v; cin >> u >> v; u--; v--;
		E[v].push_back(u);
		num_edges[u]++;
		num_edges[v]++;
	}
	rep(i,N) if(num_edges[i] % 2 == 1) ans = 5;
	rep(i,N) sort(E[i].rbegin(), E[i].rend());

	vector<int> vertices = { 0 };
	vector<int> face_colors = { 0 };
	for(int p=1; p<N; p++){
		for(int e : E[p]){
			int num_vertices = 2;
			int color = 1 - face_colors.back();
			while(true){
				if(vertices.back() <= e) break;
				num_vertices++;
				vertices.pop_back();
				face_colors.pop_back();
				if(color == face_colors.back()) ans = 5;
			}
			if(num_vertices % 2 == 1 && color != 0) ans = 5;
			if(vertices.back() == e){
				face_colors.back() = color;
			}
			else{
				vertices.push_back(e);
				face_colors.push_back(color);
			}
		}
		vertices.push_back(p);
		face_colors.push_back(0);
	}
	{
		int num_vertices = vertices.size();
		int color = 1;
		if(num_vertices % 2 == 1) ans = 5;
		for(auto c : face_colors) if(c == color) ans = 5;
	}
	cout << ans << "\n";
	return 0;
}


struct ios_do_not_sync{
	ios_do_not_sync(){
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
	}
} ios_do_not_sync_instance;
0