답안 #564938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564938 2022-05-20T03:46:54 Z ac2hu 회문 (APIO14_palindrome) C++14
47 / 100
1000 ms 5444 KB
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else 
#define deb(x...)
#endif
using namespace std;
const int C = 26;
struct node{
    node* child[C];
    int cnt = 0;
    int dist = 0;
};
node* make_node(int d){
    node* temp = new node;
    for(int i = 0;i<C;i++){
        temp->child[i] = NULL;
    }
    temp->cnt = 0;
    temp->dist = d;
    return temp;
}
string s;
int ans = 0;
node* root1 = make_node(-1);
node* root2 = make_node(0);
auto is_pali(int l,int r){
    if(l > r)return true;
    if(s[l] != s[r])return false;
    return is_pali(l + 1, r - 1);
}
void add1(int l,int r){
    node* trav = root1;
    for(int i = l;i<=r;i++){
        int c = s[i] - 'a';
        if(!trav->child[c])
            trav->child[c] = make_node(trav->dist + 2);
        trav = trav->child[c];
        ++trav->cnt;
        ans = max(ans, trav->cnt*trav->dist);
    }
}
void add2(int l,int r){
    node* trav = root2;
    for(int i = l;i<=r;i++){
        int c = s[i] - 'a';
        if(!trav->child[c])
            trav->child[c] = make_node(trav->dist + 2);
        trav = trav->child[c];
        ++trav->cnt;
        ans = max(ans, trav->cnt*trav->dist);
    }
}
signed main(){
    cin >> s;
    int n = s.size();
    for(int i = 0;i<n;i++){
        auto check = [&](int mid)->bool{
            if(i - mid < 0)return false;
            if(i + mid > n - 1)return false;
            return is_pali(i - mid, i + mid);
        };
        int l = 0,r = n;
        while(l<r){
            int mid = (l + r + 1)/2;
            if(check(mid)){
                l = mid;
            }
            else
                r = mid - 1;
        }
        add1(i,i + l);
        if(i > 0 && s[i] == s[i - 1]){
            l = 0,r = n - 1;
            while(l < r){
                int mid = (l + r + 1)/2;
                if(i - 1 - mid >= 0 && i + mid < n && is_pali(i - 1 - mid, i + mid)){
                    l = mid;
                }
                else
                    r = mid - 1;
            }
            add2(i,i + l);
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 6 ms 520 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 6 ms 492 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 445 ms 2480 KB Output is correct
2 Correct 238 ms 2440 KB Output is correct
3 Correct 572 ms 2388 KB Output is correct
4 Correct 383 ms 2588 KB Output is correct
5 Correct 3 ms 2516 KB Output is correct
6 Correct 14 ms 2392 KB Output is correct
7 Correct 68 ms 2472 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 5172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 5444 KB Time limit exceeded
2 Halted 0 ms 0 KB -