結果

問題 No.1149 色塗りゲーム
ユーザー yudedakoyudedako
提出日時 2020-08-22 18:52:57
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,677 bytes
コンパイル時間 1,329 ms
コンパイル使用メモリ 125,936 KB
実行使用メモリ 25,220 KB
平均クエリ数 19.90
最終ジャッジ日時 2024-07-17 06:36:55
合計ジャッジ時間 8,190 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>


int main() {
	int n; std::cin >> n;
	std::unordered_map<int, std::unordered_set<int>> map;
	std::set<int> block; block.insert(0); block.insert(n + 1);
	if ((n & 1) == 1) {
		std::cout << "1 " << ((n + 1) >> 1) << std::endl;;
		map[n >> 1].insert(1);;
		map[n >> 1].insert((n >> 1) + 2);
		block.insert((n + 1) >> 1);
	}
	else {
		std::cout << "2 " << (n >> 1) << std::endl;;
		map[(n >> 1) - 1].insert(1);;
		map[(n >> 1) - 1].insert((n >> 1) + 2);
		block.insert(n >> 1); block.insert((n >> 1) + 1);
	}
	while (true) {
		int responce; std::cin >> responce;
		if (responce == 0) break;
		if (responce != 3) throw 0;
		int k, x; std::cin >> k >> x;
		const auto pos = block.lower_bound(x);
		const auto right = *pos;
		const auto left = *std::prev(pos) + 1;
		map[x - left].insert(left);
		map[right - x - k].insert(x + k);
		map[right - left].erase(left);
		block.insert(x);
		if (k == 2) block.insert(x + 1);
		const auto target = map[right - left].begin();
		const auto xx = x - left + *target;
		std::cout << k << ' ' << xx << std::endl;
		map[x - left].insert(*target);
		map[right - x - k].insert(xx + k);
		map[right - left].erase(target);
		block.insert(xx);
		if (k == 2) block.insert(xx + 1);
	}
}
0