結果
| 問題 |
No.2393 Bit Grid Connected Component
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-01 22:49:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,426 bytes |
| コンパイル時間 | 2,357 ms |
| コンパイル使用メモリ | 195,376 KB |
| 実行使用メモリ | 291,840 KB |
| 最終ジャッジ日時 | 2024-10-11 18:28:17 |
| 合計ジャッジ時間 | 6,137 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 9 TLE * 1 -- * 10 |
ソースコード
#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;
}
}