제출 #310739

#제출 시각아이디문제언어결과실행 시간메모리
310739ly20Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, MOD = 1e9 + 7, P = 29;
string s;
int t;
long long hs[MAXN], pot[MAXN];
long long val(int i, int j) {
    long long resp = hs[i] - (hs[j + 1] * pot[j - i + 1]) % MOD;
    resp += MOD;
    resp %= MOD;
    return resp;
}
int main() {
    scanf("%d", &t);
    while(t--) {
        cin >> s;
        int n = s.size();
        pot[0] = 1;
        for(int i = 1; i <= n; i++) {
            pot[i] = pot[i - 1] * P;
            pot[i] %= MOD;
        }
        hs[n] = 0;
        for(int i = n - 1; i >= 0; i--) {
            hs[i] = hs[i + 1] * P + (s[i] - 'a');
            hs[i] %= MOD;
        }
        int ini1 = 0, fim1 = 0, ini2 = n - 1, fim2 = n - 1;
        int resp = 0;
        while(fim1 < fim2) {
            long long vl1 = val(ini1, fim1), vl2 = val(ini2, fim2);
            if(vl1 == vl2) {
                resp += 2;
                ini1 = fim1 + 1; fim1 = ini1;
                ini2 = fim2 - 1; fim2 = ini2;
            }
            else {
                fim1++; fim2--;
            }
        }
        if(ini1 <= ini2) resp++;
        printf("%d\n", resp);
    }
    return 0;
}

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

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