結果

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

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<string> c(n);
  for (int i = 0; i < n; ++i) cin >> c[i];
  int ans = 0;
  string now = "";
  auto dfs = [&](auto f, int x, int y) -> void
  {
    if (x == n - 1 && y == n - 1)
    {
      now.push_back(c[x][y]);
      string tmp = now;
      reverse(tmp.begin(), tmp.end());
      ans += (tmp == now);
      now.pop_back();
      return;
    }
    now.push_back(c[x][y]);
    if (x + 1 < n) f(f, x + 1, y);
    if (y + 1 < n) f(f, x, y + 1);
    now.pop_back();
  };
  dfs(dfs, 0, 0);
  cout << ans << endl;
}
0