結果

問題 No.3710 Universal Tiles
コンテスト
ユーザー aotyam
提出日時 2026-09-12 09:52:56
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 28 ms / 2,000 ms
+ 389µs
コード長 3,262 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,743 ms
コンパイル使用メモリ 484,692 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-12 09:53:15
合計ジャッジ時間 10,398 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef ONLINE_JUDGE
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;
using mint2 = modint1000000007;
#define each(a, ...) for(auto& __VA_ARGS__ : a)
#define Each(a, ...) for(auto __VA_ARGS__ : a)
#define sz(a) (ll)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
template<class T, class U> inline bool chmax(T &a, U &&b) { if (a >= (T)b) return false; a = b; return true; }
template<class T, class U> inline bool chmin(T &a, U &&b) { if (a <= (T)b) return false; a = b; return true; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; }
template<class T> requires requires(T t) { begin(t); end(t); } && (!is_same_v<T, string>) istream &operator>>(istream &is, T &v) { for (auto &x : v) is >> x; return is; }
template<class... T> inline void in(T&... a) { (cin >> ... >> a); }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; }
template<class T> requires requires(T t) { begin(t); end(t); } && (!is_same_v<T, string>) ostream &operator<<(ostream &os, const T &v) { for (auto it = begin(v); it != end(v); it++) os << (it == begin(v) ? "" : " ") << *it; return os; }
void out() { cout << '\n'; }
template<class T, class... U> inline void out(T &&a, U&&... b) { cout << a; ((cout << ' ' << b), ...); cout << '\n'; }
template<class... T> inline void print(T&&... a) { (cout << ... << a); }
template<class T = string, class U = string> inline bool yn(bool a, T &&b = "Yes", U &&c = "No") { if (a) out(b); else out(c); return a; }
constexpr ll inf = LLONG_MAX >> 2;
constexpr array<pair<ll, ll>, 4> dxdy4 = {{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}};
constexpr array<pair<ll, ll>, 8> dxdy8 = {{{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}}};

 void rotate_matrix(vector<string> &A) {
    if (A.empty()) return;
    size_t W = A.size(), H = A.front().size();
    vector B(H,string(W,0));
    for (size_t i = 0; i < H; i++) {
        for (size_t j = 0; j < W; j++) {
            B[i][j] = A[j][H - 1 - i];
        }
    }
    A.swap(B);
}

void Main() {
    ll N,M;in(N,M);
    vector S(N,vector<string>(M));in(S);
    vector T(N,vector(4,vector<string>(M)));
    for(ll i=0;i<N;i++){
        T[i][0]=S[i];
        for(ll j=0;j<3;j++){
            T[i][j+1]=T[i][j];
            rotate_matrix(T[i][j+1]);
        }
    }
    ll ans=inf;
    auto dfs=[&](this auto dfs,ll i,vector<string>A)->void{
        if(i==N){
            ll ansi=0;
            each(A,Ai)ansi+=count(all(Ai),'#');
            chmin(ans,ansi);
            return;
        }
        for(ll j=0;j<4;j++){
            auto B=A;
            for(ll x=0;x<M;x++)for(ll y=0;y<M;y++)B[x][y]=(B[x][y]=='#'||T[i][j][x][y]=='#'?'#':'.');
            dfs(i+1,B);
        }
    };
    vector A0(M,string(M,'.'));
    dfs(0,A0);
    out(ans);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    Main();
    cout << flush;
    _Exit(EXIT_SUCCESS);
}
0