結果

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

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <atcoder/modint>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int n;
string s[10];

bool check(string &s) {
	int l = 0, r = s.length() - 1;
	while (l < r) {
		if (s[l] != s[r]) return false;
		l++; r--;
	}
	return true;
}

int dfs(int y, int x, string t) {
	if (y == n - 1 && x == n - 1) {
		if (check(t)) return 1;
		return 0;
	}
	
	int ret = 0;
	if (x + 1 < n) { ret += dfs(y, x + 1, t + s[y][x + 1]); }
	if (y + 1 < n) { ret += dfs(y + 1, x, t + s[y + 1][x]); }
	return ret;
}

signed main() {
	int i;

	cin >> n;
	rep(i, n) cin >> s[i];

	string iniS;
	iniS += s[0][0];
	cout << dfs(0, 0, iniS) << endl;
	return 0;
}
0