제출 #156886

#제출 시각아이디문제언어결과실행 시간메모리
156886junodeveloperPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
77 ms11052 KiB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=(ll)1e17-3;
int t,n;
char s[1000010];
int main() {
	scanf("%d",&t);
	int i,j;
	while(t--) {
		scanf("%s",s);
		n=strlen(s);
		j=n;
		ll hl=0,hr=0,pw=1,cnt=0;
		for(i=0;i<n/2;i++) {
			hl=(26*hl+s[i]-'a')%mod;
			hr=(hr+(s[n-i-1]-'a')*pw%mod)%mod;
			if(hl==hr) {
				cnt+=2;
				j=i;
				hl=hr=0; pw=1;
			} else pw=26*pw%mod;
		}
		if(n%2||j!=n/2-1) cnt++;
		printf("%lld\n",cnt);
	}
	return 0;
}

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

palindromic.cpp: In function 'int main()':
palindromic.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&t);
  ~~~~~^~~~~~~~~
palindromic.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s);
   ~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...