제출 #1221931

#제출 시각아이디문제언어결과실행 시간메모리
1221931Nika533Palindromic Partitions (CEOI17_palindromic)C++20
100 / 100
232 ms17124 KiB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define A 912938523528553253
#define B 983525235265326669	
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
const int N=1000005;
int n,m,T,k,p[N],h[N];
string s; 

void build_hash() {
	p[0]=1;
	for (int i=1; i<n; i++) {
		__int128 a=A,b=B,P=p[i-1],val;
		val=(P*a)%b; p[i]=val;
	}
	h[0]=s[0];
	for (int i=1; i<n; i++) {
		__int128 a=A,b=B,H=h[i-1],val;
		val=(H*a+s[i])%b; h[i]=val;
	}
}
int f(int l, int r) {
	if (l==0) return h[r];
	__int128 a=A,b=B,P=p[r-l+1],H_L=h[l-1],H_R=h[r],val;
	val=(H_R-(H_L*P)%b+b)%b; int ans=val; 
	return ans;
}

void test_case() {
	cin>>s; n=s.size();
	build_hash();
	int last=-1,cnt=0;
	for (int i=0; i<n/2; i++) {
		int l=last+1,r=i;
		int l1=n-r-1,r1=n-l-1;
		if (f(l,r)==f(l1,r1)) {
			last=i; cnt+=2;
		}
	}
	if (n%2==0 && last==n/2-1) cout<<cnt<<endl;
	else cout<<cnt+1<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1; cin>>T;
	while (T--) test_case();
}

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

palindromic.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
palindromic.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | 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...