結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-01-24 20:24:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 815 bytes |
| コンパイル時間 | 763 ms |
| コンパイル使用メモリ | 62,524 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 13:14:23 |
| 合計ジャッジ時間 | 1,843 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 4 |
ソースコード
#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(n == 2 && s[0] == s[1]) {
cout << 1 << endl;
return 0;
}
for(int i = 0; i < n; i++) {
for(int j = 1; i + j - 1 < n; j++) {
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