結果

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

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec vector
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back 
#define eb emplace_back

using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
const ll mod = 998244353;
using mint = modint998244353;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
// using Graph = vector<vector<pair<int,ll>>>;
using Graph = vector<vector<int>>;

bool is_palindrome(string s){
  int n = s.size();
  rep(i,n)
    if(s[i] != s[n-1-i])
      return false;

  return true;
}

int main(){
  // input
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];

  // solve
  int M = 2*N-2, ans = 0;
  rep(bt,1<<M){
    if(__builtin_popcount(bt) != N-1) continue;
    
    string tmp;
    int x = 0, y = 0;
    tmp += S[x][y];
    rep(i,M){
      (bt & (1<<i) ? x : y) += 1;
      tmp += S[x][y];
    }

    if(is_palindrome(tmp)) ans++;
  }

  // output
  cout << ans << endl;
}
0