結果

問題 No.2393 Bit Grid Connected Component
ユーザー anago-pieanago-pie
提出日時 2023-08-01 22:49:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,426 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 190,476 KB
実行使用メモリ 315,040 KB
最終ジャッジ日時 2024-04-19 23:42:47
合計ジャッジ時間 6,083 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,880 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 82 ms
18,688 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iterator>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 1
using ll = long long;
using ld = long double;
const int mod = 998244353;
const double pi = atan2(0, -1);
#include <time.h>
#include <chrono>

int main() {
	int T;
	cin >> T;
	map<vector<ll>, ll> mp;
	rep(test, T) {
		ll x, y;
		cin >> x >> y;
		if (mp.count({ x,y })) {
			cout << mp[{x, y}] << endl;
			continue;
		}
		set<vector<ll>> s;
		s.insert({ x,y });
		queue<vector<ll>> q;
		q.push({ x,y });
		while (!q.empty()) {
			ll nowx = q.front()[0];
			int nowy = q.front()[1];
			q.pop();
			if (nowx > 1) {
				bitset<60> b = nowx - 1;
				if (b[nowy]&&!s.count({nowx-1, nowy})) {
					s.insert({ nowx - 1, nowy });
					q.push({ nowx - 1 , nowy });
				}
			}
			if (nowy > 0) {
				bitset<60>b = nowx;
				if (b[nowy - 1] && !s.count({ nowx, nowy - 1 })) {
					s.insert({ nowx, nowy - 1 });
					q.push({ nowx, nowy - 1 });
				}
			}
			if (nowy < 59) {
				bitset<60> b = nowx;
				if (b[nowy + 1] && !s.count({ nowx, nowy + 1 })) {
					s.insert({ nowx, nowy + 1 });
					q.push({ nowx, nowy + 1 });
				}
			}
			if (nowx+1LL < (1LL << 60LL)) {
				bitset<60> b = nowx + 1;
				if (b[nowy] && !s.count({ nowx + 1, nowy })) {
					s.insert({ nowx + 1, nowy });
					q.push({ nowx + 1, nowy });
				}
			}
		}
		for (vector<ll> v : s) {
			mp[v] = s.size();
		}
		cout << s.size() << endl;
	}
}
0