답안 #43234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43234 2018-03-11T09:18:42 Z krauch Palindromic Partitions (CEOI17_palindromic) C++14
60 / 100
10000 ms 12032 KB
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair < ll, int > PLI;


#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

#define fname ""

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

int d[N], mn[N];
char a[N];

bool check(int l1, int r1, int l2, int r2) {
    forn(i, l1, r1) {
        if (a[i] != a[l2 + i - l1]) return 0;
    }
    return 1;
}

int main() {
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef krauch
        freopen("input.txt", "r", stdin);
    #else
        //freopen(fname".in", "r", stdin);
        //freopen(fname".out", "w", stdout);
    #endif

    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        int n = sz(s);
        forn(i, 1, n) {
            a[i] = s[i - 1];
        }

        if (n & 1) d[n / 2 + 1] = 1;
        else d[n / 2 + 1] = 0;
        mn[n / 2 + 1] = 0;
        for1(i, n / 2, 1) {
            mn[i] = 0;
            forn(j, 1, n / 2 - i + 1) {
                if (check(i, i + j - 1, n - i - j + 2, n - i + 1)) {
                    mn[i] = j;
                    break;
                }
            }
            if (mn[i]) d[i] = d[i + mn[i]] + 2;
            else d[i] = 1;
        }
        cout << d[1] << "\n";
    }

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 35 ms 940 KB Output is correct
11 Correct 4099 ms 1028 KB Output is correct
12 Correct 37 ms 1052 KB Output is correct
13 Correct 2 ms 1168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 35 ms 940 KB Output is correct
11 Correct 4099 ms 1028 KB Output is correct
12 Correct 37 ms 1052 KB Output is correct
13 Correct 2 ms 1168 KB Output is correct
14 Execution timed out 10042 ms 12032 KB Time limit exceeded
15 Halted 0 ms 0 KB -