結果

問題 No.588 空白と回文
ユーザー newlife171128newlife171128
提出日時 2017-12-24 21:53:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 70,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 18:03:44
合計ジャッジ時間 6,431 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 636 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 634 ms
4,376 KB
testcase_12 AC 620 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 517 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 704 ms
4,376 KB
testcase_21 AC 732 ms
4,376 KB
testcase_22 AC 703 ms
4,380 KB
testcase_23 AC 448 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>

using namespace std;
string s;

int func(int start,int end){

	vector<char> p;

	for(int i=start; i<=end; i++){
		p.push_back(s[i]);
	}
	int count=0;

	for(int i=0; i<p.size();i++){
		if(p[i] == p[p.size()-1-i]){
			count++;
		}
	}
	return count;

}

int main() {

	cin >> s;

	int left_side = 0;
	int right_side = 0;
	int ans = 1;
	bool judge=false;
/*	cout << s.length() << endl;*/
	for (int k = 0; k < s.length() - 3; k++) {
		for (int i = 1; i < s.length() - 1-k; i++) {
			judge =false;
			left_side = i;
			right_side = i+k;
			int tmp = func(left_side,right_side);
			while (left_side != 0 && right_side != s.length() - 1) {
				if (s[--left_side] == s[++right_side]) {
					tmp += 2;
					judge =true;
				}
			}
			if(judge)
			ans = max(ans, tmp);
		}
	}
	if (ans == 1) {
		cout << ans << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}
0