結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-01-24 20:42:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 867 bytes |
| コンパイル時間 | 666 ms |
| コンパイル使用メモリ | 62,892 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 13:34:03 |
| 合計ジャッジ時間 | 1,680 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
bool p(string s) {
for(int i = 0; i < s.size(); i++) {
if(s[i] != s[s.size() - 1 - i]) return false;
}
return true;
}
bool b[101][101];
int dp[101];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
if(count(s.begin(), s.end(), s[0]) == n) {
cout << n - 1 << endl;
return 0;
}
for(int i = 0; i < n; i++) {
for(int j = 1; i + j - 1 < n; j++) {
if(i == 0 && j == n) continue;
b[i][j] = p(s.substr(i, j));
}
}
memset(dp, -1, sizeof dp);
dp[0] = 0;
for(int i = 0; i < n; i++) {
if(dp[i] == -1) continue;
for(int j = 1; i + j - 1 < n; j++) {
if(b[i][j]) {
dp[i + j] = max(dp[i + j], dp[i]);
dp[i + j] = max(dp[i + j], j);
}
}
}
cout << dp[n] << endl;
}
femto