제출 #77681

#제출 시각아이디문제언어결과실행 시간메모리
77681updown1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
660 ms31900 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, K)
#define ffa ffi ffj
#define s <<" "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=1000000, INF=1000000000000000000, MOD=1000000007;;
///500,000,000
int T, N, mul= 41, hsh1[MAXN], inv[MAXN], p[MAXN];
string a;

int see(int st, int en) {
    if (st == 0) return hsh1[en];
    return (((hsh1[en]-hsh1[st-1]+MOD)%MOD)*inv[st])%MOD;
}
int mI(int x, int y) {
    if (y == 0) return 1;
    int p = mI(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}


main() {
    //ifstream cin("test.in");
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> T;
    p[0] = 1; For (i, 1, MAXN) p[i] = (p[i-1]*mul)%MOD;
    For (i, 0, MAXN) inv[i] = mI(p[i], MOD-2);
    For (t, 0, T) {
        cin >> a; N = a.length();
        hsh1[0]=a[0]-'a'+1; For (i, 1, N) hsh1[i] = (hsh1[i-1]+ (a[i]-'a'+1)*p[i])%MOD;
        int out = 0;
        int st = 0;
        ffi {
            if (see(st, i) == see(N-i-1, N-st-1)) {
                //w<< st s i<<e;
                out++;
                st = i+1;
            }

        }
        w<<out<<e;
    }
}

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

palindromic.cpp:34:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 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...