제출 #1095043

#제출 시각아이디문제언어결과실행 시간메모리
1095043vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
184 ms24472 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int base = 31;
const int MOD = 1000000003;
const int maxn = 1000111;

using namespace std;

int POW[maxn], Hash[maxn], len;
string s;

int getHash(int i,int j) {
    return (Hash[j] - Hash[i - 1] * POW[j - i + 1] + MOD * MOD) % MOD;
}

void solve(){
	cin >> s;
	int n = s.size();
	s = ' ' + s;
    for (int i = 1; i <= n; i++)
        Hash[i] = (Hash[i - 1] * base + s[i] - 'a' + 1) % MOD;
	
	int l1 = 1, r1 = 1, l2 = n, r2 = n;
	int ans = 0;
	while(r1 <= r2){
		if(getHash(l1, r1) == getHash(l2, r2)){
			if(r1 < l2){
				ans += 2;
				l1 = r1 + 1;
				r1++;
				r2 = l2 - 1;
				l2--;
			} else {
				ans++;
				break;
			}
		} else {
			r1++;
			l2--;
		}
	}
	cout << ans << '\n';
}
main() {
    POW[0] = 1;
    for (int i = 1; i <= 1000000; i++)
        POW[i] = (POW[i - 1] * base) % MOD;

	int test; cin >> test;
	while(test--){
		solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

palindromic.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...