結果
問題 | No.1266 7 Colors |
ユーザー | やむなく |
提出日時 | 2020-10-23 22:19:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 346 ms / 3,000 ms |
コード長 | 4,092 bytes |
コンパイル時間 | 2,004 ms |
コンパイル使用メモリ | 178,576 KB |
実行使用メモリ | 15,028 KB |
最終ジャッジ日時 | 2024-07-21 10:56:52 |
合計ジャッジ時間 | 8,979 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 260 ms
5,888 KB |
testcase_04 | AC | 322 ms
11,264 KB |
testcase_05 | AC | 267 ms
6,272 KB |
testcase_06 | AC | 333 ms
12,160 KB |
testcase_07 | AC | 339 ms
13,440 KB |
testcase_08 | AC | 325 ms
11,520 KB |
testcase_09 | AC | 309 ms
9,600 KB |
testcase_10 | AC | 295 ms
8,960 KB |
testcase_11 | AC | 278 ms
6,912 KB |
testcase_12 | AC | 281 ms
7,680 KB |
testcase_13 | AC | 289 ms
8,192 KB |
testcase_14 | AC | 267 ms
6,272 KB |
testcase_15 | AC | 346 ms
13,572 KB |
testcase_16 | AC | 291 ms
7,808 KB |
testcase_17 | AC | 338 ms
13,056 KB |
testcase_18 | AC | 286 ms
15,028 KB |
testcase_19 | AC | 174 ms
14,716 KB |
testcase_20 | AC | 176 ms
14,592 KB |
testcase_21 | AC | 232 ms
5,376 KB |
ソースコード
//// Created by yamunaku on 2020/10/23.//#include <bits/stdc++.h>//#include <atcoder/all>using namespace std;//using namespace atcoder;#define rep(i, n) for(int i = 0; i < (n); i++)#define repl(i, l, r) for(int i = (l); i < (r); i++)#define per(i, n) for(int i = ((n)-1); i >= 0; i--)#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)#define all(x) (x).begin(),(x).end()#define MOD9 998244353#define MOD1 1000000007#define IINF 1000000000#define LINF 1000000000000000000#define SP <<" "<<#define CYES cout<<"Yes"<<endl#define CNO cout<<"No"<<endl#define CFS cin.tie(0);ios::sync_with_stdio(false)#define CST(x) cout<<fixed<<setprecision(x)using ll = long long;using ld = long double;using vi = vector<int>;using mti = vector<vector<int>>;using vl = vector<ll>;using mtl = vector<vector<ll>>;using pi = pair<int, int>;using pl = pair<ll, ll>;template<typename T>using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;struct dsu {public:dsu() : _n(0) {}dsu(int n) : _n(n), parent_or_size(n, -1) {}int merge(int a, int b) {assert(0 <= a && a < _n);assert(0 <= b && b < _n);int x = leader(a), y = leader(b);if (x == y) return x;if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);parent_or_size[x] += parent_or_size[y];parent_or_size[y] = x;return x;}bool same(int a, int b) {assert(0 <= a && a < _n);assert(0 <= b && b < _n);return leader(a) == leader(b);}int leader(int a) {assert(0 <= a && a < _n);if (parent_or_size[a] < 0) return a;return parent_or_size[a] = leader(parent_or_size[a]);}int size(int a) {assert(0 <= a && a < _n);return -parent_or_size[leader(a)];}std::vector<std::vector<int>> groups() {std::vector<int> leader_buf(_n), group_size(_n);for (int i = 0; i < _n; i++) {leader_buf[i] = leader(i);group_size[leader_buf[i]]++;}std::vector<std::vector<int>> result(_n);for (int i = 0; i < _n; i++) {result[i].reserve(group_size[i]);}for (int i = 0; i < _n; i++) {result[leader_buf[i]].push_back(i);}result.erase(std::remove_if(result.begin(), result.end(),[&](const std::vector<int> &v) { return v.empty(); }),result.end());return result;}private:int _n;// root node: -1 * component size// otherwise: parentstd::vector<int> parent_or_size;};int main() {//CFS;int n, m, q;cin >> n >> m >> q;vector<string> s(n);rep(i, n) cin >> s[i];mti e(n);rep(i, m) {int u, v;cin >> u >> v;u--, v--;e[u].push_back(v);e[v].push_back(u);}dsu uf(n * 7);rep(i, n) {rep(j, 6) {if (s[i][j] == '1' && s[i][(j + 1) % 7] == '1') {uf.merge(7 * i + j, 7 * i + j + 1);}}if (s[i][0] == '1' && s[i][6] == '1') {uf.merge(7 * i, 7 * i + 6);}for (auto &x : e[i]) {rep(j, 7) {if (s[i][j] == '1' && s[x][j] == '1') {uf.merge(7 * i + j, 7 * x + j);}}}}rep(i, q) {int c, x, y;cin >> c >> x >> y;x--, y--;if (c == 1) {s[x][y] = '1';int k = (y + 1) % 7;if (s[x][k] == '1') {uf.merge(7 * x + y, 7 * x + k);}k = (y + 6) % 7;if (s[x][k] == '1') {uf.merge(7 * x + y, 7 * x + k);}for (auto &nx : e[x]) {if (s[x][y] == '1' && s[nx][y] == '1') {uf.merge(7 * x + y, 7 * nx + y);}}} else {cout << uf.size(7 * x) << endl;}}return 0;}