답안 #1017405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017405 2024-07-09T07:46:32 Z cnn008 Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
0 ms 348 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define ll long long

const int N=1e6+5;
const int mod=1e9+7;
const int base=31;

int n,ans,h[N],pw[N];
string s;
int get(int l, int r){
	return (h[r]-(h[l-1]*pw[r-l+1])%mod+mod)%mod;
}
void sol(){
	ans=0;
	cin>>s;
	n=(int)s.size();
	s=' '+s;
	pw[0]=1;
	for(int i=1; i<=n; i++) pw[i]=(pw[i-1]*base)%mod;
	for(int i=1; i<=n; i++) h[i]=(h[i-1]*base+s[i]-'a')%mod;
	int l=1,r=n;
	while(l<=r){
		int _l=l,_r=r,f=0;
		while(_l<_r){
			if(get(l,_l++)==get(_r--,r)){
				cebug(s,l,_l,_r,r);
				ans+=2;
				f=1;
				break;
			}
		}
		if(!f){
			ans++;
			break;
		}
		l=_l;
		r=_r;
	}
	cout<<ans<<"\n";
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    int tt=1;
    cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}

Compilation message

palindromic.cpp: In function 'void sol()':
palindromic.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define cebug(...) "Arya"
      |                    ^~~~~~
palindromic.cpp:34:5: note: in expansion of macro 'cebug'
   34 |     cebug(s,l,_l,_r,r);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -