September Cook-Off 2012 RRECIPE : Recipe Reconstruction

問題概要

?の混じった文字列が与えられる。回文になるように?にアルファベットを埋める方法が何通りあるか求める問題。

解法

対応する2箇所を比べる。

acceptされたコード

const int MAX_L = int(1e6);
char buf[MAX_L + 2];

void init() {
	scanf(" %s ", buf);
}

int solve() {
	const int L = strlen(buf);
	int64 ans = 1;
	for (int i = 0; i <= L - 1 - i; ++i) {
		if (buf[i] == buf[L-1-i]) {
			if (buf[i] == '?') {
				ans = ans * 26 % MOD;
			}
		}
		else if (!(buf[i] == '?' || buf[L-1-i] == '?')){
			return 0;
		}
	}
	return ans;
}