답안 #545823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545823 2022-04-05T14:05:50 Z Ai7081 Palindromic Partitions (CEOI17_palindromic) C++17
15 / 100
4 ms 2260 KB
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9+7;
const int key = 31;

int t, out, l, r, now, po[500005];
string s;
stack<char> st;
bool ok;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    po[0] = 1;
    for (int i=1; i<=500000; i++) po[i] = (po[i-1] * key) % mod;
    cin >> t;
    while (t--) {
        cin >> s;
        ok = false;
        out = l = r = now = 0;
        for (int i=0; i<s.size()/2; i++) {
            l *= key, l += (s[i]-'a'), l %= mod;
            r += (s[s.size()-1-i]-'a')*po[now], r %= mod;
            if (l == r) now = l = r = 0, out += 2;
            else now++;
        }
        (s.size()%2 || now) ? cout << out+1 << endl : cout << out << endl;
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int i=0; i<s.size()/2; i++) {
      |                       ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2260 KB Output is correct
4 Correct 4 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2260 KB Output is correct
4 Correct 4 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Incorrect 3 ms 2260 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2260 KB Output is correct
4 Correct 4 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Incorrect 3 ms 2260 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2260 KB Output is correct
4 Correct 4 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Incorrect 3 ms 2260 KB Output isn't correct
7 Halted 0 ms 0 KB -