結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector Grid(n, vector<char>(n));
  rep(i, n) rep(j, n) cin >> Grid[i][j];
  int ans = 0;
  rep(bit, 1 << (2 * n - 2)) {
    if (popcount(ull(bit)) != n - 1) continue;
    string s = { Grid[0][0] };
    pair<int, int> pos = { 0, 0 };
    rep(i, 2 * n - 2) {
      if (bit & (1 << i))
        pos.first++;
      else
        pos.second++;
      s += Grid[pos.first][pos.second];
    }
    assert(pos == make_pair(n - 1, n - 1));
    string t = s;
    reverse(t.begin(), t.end());
    // cerr << s << ' ' << t << '\n';
    if (s == t) ++ans;
  }
  cout << ans << '\n';
  return 0;
}
0