結果

問題 No.3710 Universal Tiles
コンテスト
ユーザー t98slider
提出日時 2026-09-11 21:40:05
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 69µs
コード長 1,230 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,176 ms
コンパイル使用メモリ 339,788 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-11 21:40:20
合計ジャッジ時間 4,152 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

vector<string> rotatem90(vector<string> a){
    int h = a.size(), w = a[0].size();
    vector<string> ret(h, string(w, '?'));
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            ret[x][h - 1 - y] = a[y][x];
        }
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<array<__int128, 4>> a(n);
    for(int i = 0; i < n; i++){
        vector<string> A(m);
        for(auto &&s : A) cin >> s;
        for(int j = 0; j < 4; j++){
            __int128 S = 0;
            for(int y = 0; y < m; y++){
                for(int x = 0; x < m; x++){
                    if(A[y][x] == '#') a[i][j] |= __int128(1) << (y * m + x);
                }
            }
            A = rotatem90(A);
        }
    }
    int ans = m * m;
    for(int S = 0; S < (1 << (2 * n)); S++){
        __int128 U = 0;
        for(int j = 0; j < n; j++){
            U |= a[j][(S >> (2 * j)) & 3];
        }
        ans = min(ans, (int)(__builtin_popcountll(U & 0xFFFF'FFFF'FFFF'FFFFULL) 
                        + __builtin_popcountll((U >> 64) & 0xFFFF'FFFF'FFFF'FFFFULL)));
    }
    cout << ans << '\n';
}
0