답안 #586371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586371 2022-06-30T07:56:56 Z Do_you_copy Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
11 ms 15956 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

using ll = long long;
using pii = pair <int, int>;

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

const ll Mod = 1000000007;
const ll Mod2 = 999999999989;
const int maxN = 1e6 + 2;
int n;
int base = 29;
ll pre[2][maxN], suf[2][maxN], power[2][maxN];
string s;

ll gethash(int l, int r, int t){
    return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
}

bool cmp(int l1, int r1, int l2, int r2){
    return gethash(l1, r1, 1) == gethash(l2, r2, 1)
    && gethash(l1, r1, 2) == gethash(l2, r2, 2);
}


void Init(){
    cin >> s;
    n = s.length();
    for (int i = 1; i <= n; ++i){
        pre[0][i] = pre[0][i - 1] * base + (s[i - 1] - 'a');
        pre[1][i] = pre[1][i - 1] * base + (s[i - 1] - 'a');
        pre[0][i] %= Mod;
        pre[1][i] %= Mod2;
    }
    ll ans = 0;
    int i = 1, j = n;
    while (i <= j){
        int l = i, r = j;
        while (!cmp(i, l, r, j)){
            ++l, --r;
        }
        if (l < r) ans += 2;
        else ++ans;
        i = l + 1, j = r - 1;
    }
    cout << ans << "\n";
}

int main(){
    if (fopen(taskname".txt", "r")){
        freopen(taskname".txt", "r", stdin);
    }
    faster
    power[0][0] = power[1][0] = 1;
    for (int i = 1; i <= 1e6 + 1; ++i){
        power[0][i] = power[0][i - 1] * base % Mod;
        power[1][i] = power[1][i - 1] * base % Mod2;
    }
    //freopen(taskname.inp, "r", stdin)
    //freopen(taskname.out, "w", stdout)
    int tt; cin >> tt; while (tt--)
    Init();
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(taskname".txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp: In function 'bool cmp(int, int, int, int)':
palindromic.cpp:29:17: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |            ~~~~~^
palindromic.cpp:25:4: note: while referencing 'pre'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |    ^~~
palindromic.cpp:29:29: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |                        ~~~~~^
palindromic.cpp:25:4: note: while referencing 'pre'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |    ^~~
palindromic.cpp:29:47: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |                                        ~~~~~~~^
palindromic.cpp:25:32: note: while referencing 'power'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |                                ^~~~~
palindromic.cpp:29:17: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |            ~~~~~^
palindromic.cpp:25:4: note: while referencing 'pre'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |    ^~~
palindromic.cpp:29:29: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |                        ~~~~~^
palindromic.cpp:25:4: note: while referencing 'pre'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |    ^~~
palindromic.cpp:29:47: warning: array subscript 2 is above array bounds of 'll [2][1000002]' {aka 'long long int [2][1000002]'} [-Warray-bounds]
   29 |     return pre[t][r] - pre[t][l - 1] * power[t][r - l + 1];
      |                                        ~~~~~~~^
palindromic.cpp:25:32: note: while referencing 'power'
   25 | ll pre[2][maxN], suf[2][maxN], power[2][maxN];
      |                                ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -