結果

問題 No.3428 Palindromic Path (Easy)
コンテスト
ユーザー t98slider
提出日時 2026-01-11 14:05:56
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 915 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,378 ms
コンパイル使用メモリ 337,520 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-11 14:06:00
合計ジャッジ時間 3,841 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> A(n);
    for(auto &&str : A) cin >> str;
    int b = 2 * (n - 1), ans = 0;
    string tmp(b + 1, '?');
    auto check = [&](){
        int l = 0, r = tmp.size() - 1;
        while(l < r){
            if(tmp[l] != tmp[r]) return false;
            l++, r--;
        }
        return true;
    };
    for(int comb = (1 << (n - 1)) - 1; comb < (1 << b); ){
        {
            int y = 0, x = 0;
            for(int i = 0; i < b; i++){
                tmp[i] = A[y][x];
                if(comb >> i & 1) x++;
                else y++;
            }
            tmp.back() = A[y][x];
            ans += check();
        }
        int x = comb & (-comb), y = comb + x;
        comb = ((comb & ~y) / x >> 1) | y;
    }
    cout << ans << '\n';
}
0