結果

問題 No.1727 [Cherry 3rd Tune] Stray
ユーザー 👑 tatyamtatyam
提出日時 2021-10-19 08:32:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 6,000 ms
コード長 1,259 bytes
コンパイル時間 3,866 ms
コンパイル使用メモリ 276,364 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-16 13:50:02
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 32 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct UnionFind{
    vector<int> data;
    UnionFind(int n): data(n, -1){}
    bool unite(int a, int b){
        a = root(a); b = root(b);
        if(a == b) return 0;
        if(data[a] > data[b]) swap(a, b);
        data[a] += data[b];
        data[b] = a;
        return 1;
    }
    bool find(int a, int b){ return root(a) == root(b); }
    int root(int a){ return data[a] < 0 ? a : data[a] = root(data[a]); }
    int size(int a){ return -data[root(a)]; }
    int operator[](int a){ return root(a); }
};
int main(){
    int N;
    cin >> N >> N;
    const int mx = 1 << N * 2;
    UnionFind uf(mx);
    auto rotate = [N, mask1 = 1, mask2 = (1 << N) - 2, mask3 = ((1 << N) - 2) << (N - 1), mask4 = mx >> 1](int x){
        const int a = x & mask1, b = x & mask2, c = x & mask3, d = x & mask4;
        return c << 1 | d >> (N - 1) | a << (N - 1) | b >> 1;
    };
    auto reverse = [N, mask1 = (1 << N) - 1, mask2 = ((1 << N) - 1) << N](int x){
        const int a = x & mask1, b = x & mask2;
        return b >> N | a << N;
    };
    int ans = mx;
    for(int i = 0; i < mx; i++) if(uf.unite(i, rotate(i))) ans--;
    for(int i = 0; i < mx; i++) if(uf.unite(i, reverse(i))) ans--;
    cout << ans << endl;
}
0