結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll myceil(ll a, ll b) {return (a+b-1)/b;}

template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

#define debug(var) do { cout << #var << " :\n"; view(var); } while(0)
template<typename T>void view(const T& e) {cout << e;}
template<typename T1, typename T2>void view(const pair<T1, T2>& p) {cout << "{" << p.first << ", " << p.second << "}";}
template<typename T>void view(const vc<T>& v) {for (const auto& e : v) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const vv<T>& vv) {for (const auto& v : vv) {view(v);} cout << endl;}
template<typename T>void view(const set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const multiset<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const unordered_set<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T>void view(const unordered_multiset<T>& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;}
template<typename T1, typename T2>void view(const map<T1, T2>& mp){for (const auto& e : mp) {view(e);cout << " ";} cout << endl;}


# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")

#include <atcoder/all>
using namespace atcoder;



void solve() {
    int n;
    cin >> n;
    vector<vector<char>> v(n,vector<char> (n));
    rep(i,n) rep(j,n) cin >> v[i][j];

    vector<int> dir;
    rep(i,n-1) {
        dir.push_back(0);
        dir.push_back(1);
    }
    sort(all(dir));

    ll ans = 0;

    do {
        string s = "";
        int x = 0;
        int y = 0;
        rep(i,2*n-1) {
            s.push_back(v[x][y]);
            if (dir[i]) x++;
            else y++;
        }

        string t = s;
        reverse(all(t));
        if (s == t) ans++;
    } while (next_permutation(all(dir)));

    cout << ans%998244353 << endl;
    return;
}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int t = 1;
    // cin >> t;
    rep(i,t)  solve();

	return 0;
}

0