結果

問題 No.3410 Happiest Art
コンテスト
ユーザー The Forsaking
提出日時 2025-12-25 22:25:02
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 3,327 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,174 ms
コンパイル使用メモリ 204,108 KB
実行使用メモリ 70,092 KB
最終ジャッジ日時 2025-12-25 22:25:16
合計ジャッジ時間 13,455 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%d%d%d%d", &n, &m, &x, &y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%d", w + i);
      |         ~~~~~^~~~~~~~~~~~~
main.cpp:45:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |             scanf("%s", s[i][j] + 1);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
int n, m, w[N];


ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
bool isprime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}

int findPrime(int n) {
    while (!isprime(n)) n++;
    return n;
}

typedef array<ll, 2> hash;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int P = findPrime(rng() % 900000000 + 100000000);
ll p[N], h[N];
void init() {
    p[0] = 1;
    for (int i = 1; i < N; i++) p[i] = p[i - 1] * 131 % P;
}

char s[101][102][102], e[10001];
int x, y;
ll h2;

int main() {
    init();
    scanf("%d%d%d%d", &n, &m, &x, &y);
    map<int, int> ma;
    for (int i = 1; i < n + 1; i++) {
        scanf("%d", w + i);
        for (int j = 1; j < x + 1; j++) {
            scanf("%s", s[i][j] + 1);
            for (int k = 1; k < y + 1; k++) h[i] = (h[i] * 131 + s[i][j][k]) % P;
        }
        ma[h[i]] += i <= m ? 1 : -1;
        if (w[i]) {
            for (int j = 1; j < x + 1; j++)
                for (int k = 1; k < y + 1; k++) {
                    ll t = (h[i] + ((s[i][j][k] ^ '#' ^ '.') - s[i][j][k]) * p[x * y - (j - 1) * y - k] % P + P) % P;
                    ma[t] += i <= m ? 1 : -1;
                }
        }
    }
    int res = x * y > 20 || ma.size() != qmi(2, x * y, MOD) ? 0 : -n, t = -1;
    for (auto [a, b] : ma) res = max(res, b);
    printf("%d\n", res);
    for (auto [a, b] : ma)
        if (b == res)
            t = a;
    if (t != -1) {
        for (int i = 1; i < n + 1; i++) {
            if (h[i] == t) {
                for (int j = 1; j < x + 1; j++) puts(s[i][j] + 1);
                return 0;
            }
            if (w[i]) {
                for (int j = 1; j < x + 1; j++)
                    for (int k = 1; k < y + 1; k++) {
                        ll g = (h[i] + ((s[i][j][k] ^ '#' ^ '.') - s[i][j][k]) * p[x * y - (j - 1) * y - k] % P + P) % P;
                        if (t == g) {
                            for (int l = 1; l < x + 1; l++) {
                                for (int o = 1; o < y + 1; o++) putchar(j == l && k == o ? s[i][l][o] ^ '.' ^ '#' : s[i][l][o]);
                                puts("");
                            }
                            return 0;
                        }
                    }
            }
        }
    } else {
        for (int i = 1; i < x * y + 1; i++) h2 = (h2 * 131 + (e[i] = '.')) % P;
        while (1) {
            if (!ma.count(h2)) {
                for (int i = 1; i < x + 1; i++) {
                    for (int j = 1; j < y + 1; j++) putchar(e[(i - 1) * y + j]);
                    puts("");
                }
                return 0;
            }
            for (int i = x * y; i; i--) {
                h2 = (h2 - e[i] * p[x * y - i] % P + P) % P;
                if (e[i] == '.') {
                    e[i] = '#';
                    h2 = (h2 + e[i] * p[x * y - i]) % P;
                    break;
                } else e[i] = '.';
                h2 = (h2 + e[i] * p[x * y - i]) % P;
            }
        }
    }
    return 0;
}
0