# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1170603 | InvMOD | Palindromic Partitions (CEOI17_palindromic) | C++20 | 0 ms | 320 KiB |
#include<bits/stdc++.h>
using namespace std;
#define sz(v) (int)(v).size()
const int MOD = 1e9 + 5277, base = 31;
void solve()
{
string s; cin >> s;
s = " " + s; int n = sz(s) - 1;
vector<int> hsh(sz(s)), pw(sz(s), 1);
for(int i = 1; i < sz(s); i++){
hsh[i] = hsh[i - 1] * base % MOD + (s[i] - 'a' + 1);
pw[i] = pw[i - 1] * base % MOD;
}
auto get_hash = [&](int l, int r) -> int{
return (hsh[r] - (hsh[l - 1] * pw[r - l + 1] % MOD) + MOD) % MOD;
};
vector<int> dp(sz(s) / 2 + 1, 0);
for(int i = 1; i <= sz(s) / 2; i++){
for(int j = 1; j <= i; j++){
if(get_hash(j, i) == get_hash(n - i + 1, n - j + 1)){
dp[i] = max(dp[i], dp[j - 1] + 1);
}
}
}
int answer = 1;
for(int i = 1; i <= sz(s) / 2; i++){
answer = max(answer, dp[i] * 2 + (i != (sz(s)) / 2 ? 1 : -1));
}
cout << answer << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
int tc; cin >> tc;
while(tc--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |