結果

問題 No.588 空白と回文
コンテスト
ユーザー hirakich1048576
提出日時 2016-05-07 20:26:38
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 954 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 216 ms
コンパイル使用メモリ 38,772 KB
最終ジャッジ日時 2026-02-23 21:15:01
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// A is for "Ant"

#include <stdio.h>

#define S_MAX 1000

char s[S_MAX + 1];

int max(int a, int b){
	return (a > b) ? a : b;
}

int odd(){
	char *first, *last;
	char *center;
	int answer = 0;
	for (center = s; *center; center++) {
		int maybe_ans = -1;
		first = last = center;
		while (first - s >= 0 && *last) {
			if (*first == *last)
				maybe_ans += 2;
			first--;
			last++;
		}
		if (maybe_ans > answer) {
			answer = maybe_ans;
		}
	}
	return answer;
}

int even(){
	char *first, *last;
	char *centeright;
	int answer = 0;
	for (centeright = s + 1; *centeright; centeright++) {
		int maybe_ans = 0;
		first = centeright - 1, last = centeright;
		while (first - s >= 0 && *last) {
			if (*first == *last)
				maybe_ans += 2;
			first--;
			last++;
		}
		if (maybe_ans > answer) {
			answer = maybe_ans;
		}
	}
	return answer;
}

int solve(){
	return max(even(), odd());
}

int main(void){
	scanf("%s", s);
	printf("%d\n", solve());
	return 0;
}
0