답안 #422041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422041 2021-06-09T15:43:26 Z cpp219 회문 (APIO14_palindrome) C++14
100 / 100
102 ms 104112 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e5 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

struct node{
    ll nxt[26];
    ll len;
    ll sufflink;
    ll num; vector<ll> g;
};
ll ans = 1;
ll now;
ll suff;

node tree[N];

void Init(){
    now = 2; suff = 2;
    tree[1].len = -1; tree[1].sufflink = 1; tree[1].g.push_back(2);
    tree[2].len = 0; tree[2].sufflink = 1;
}
string s;
void Add(ll pos){
    ll c = s[pos] - 'a';
    ll cur = suff,curlen = 0;
    while(1){
        curlen = tree[cur].len;
        if (pos - 1 - curlen >= 0 && s[pos] == s[pos - 1 - curlen]) break;
        cur = tree[cur].sufflink;
    }

    if (tree[cur].nxt[c]){
        suff = tree[cur].nxt[c];
        tree[suff].num++;
        return;
    }

    now++; suff = now;
    tree[now].len = tree[cur].len + 2;
    tree[cur].nxt[c] = now; tree[now].num = 1;
    if (tree[now].len == 1){
        tree[now].sufflink = 2;
        tree[2].g.push_back(now);
        return;
    }

    while(1){
        cur = tree[cur].sufflink;
        curlen = tree[cur].len;
        if (pos - 1 - curlen >= 0 && s[pos] == s[pos - 1 - curlen]) break;
    }
    tree[now].sufflink = tree[cur].nxt[c];
    tree[tree[now].sufflink].g.push_back(now);

}

void DFS(ll u){
    for (auto i : tree[u].g){
        DFS(i);
        tree[u].num += tree[i].num;
    }
    ans = max(ans,tree[u].num * tree[u].len);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>s; Init();
    for (ll i = 0;i < s.size();i++) Add(i);
    DFS(1);
    cout<<ans;
}

Compilation message

palindrome.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
palindrome.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
palindrome.cpp: In function 'int main()':
palindrome.cpp:84:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (ll i = 0;i < s.size();i++) Add(i);
      |                   ~~^~~~~~~~~~
palindrome.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 75456 KB Output is correct
2 Correct 33 ms 75460 KB Output is correct
3 Correct 34 ms 75340 KB Output is correct
4 Correct 32 ms 75340 KB Output is correct
5 Correct 32 ms 75456 KB Output is correct
6 Correct 33 ms 75376 KB Output is correct
7 Correct 32 ms 75420 KB Output is correct
8 Correct 37 ms 75384 KB Output is correct
9 Correct 35 ms 75452 KB Output is correct
10 Correct 34 ms 75468 KB Output is correct
11 Correct 33 ms 75380 KB Output is correct
12 Correct 36 ms 75372 KB Output is correct
13 Correct 32 ms 75400 KB Output is correct
14 Correct 33 ms 75340 KB Output is correct
15 Correct 33 ms 75416 KB Output is correct
16 Correct 37 ms 75368 KB Output is correct
17 Correct 33 ms 75332 KB Output is correct
18 Correct 38 ms 75444 KB Output is correct
19 Correct 34 ms 75416 KB Output is correct
20 Correct 34 ms 75412 KB Output is correct
21 Correct 34 ms 75416 KB Output is correct
22 Correct 32 ms 75348 KB Output is correct
23 Correct 32 ms 75340 KB Output is correct
24 Correct 33 ms 75412 KB Output is correct
25 Correct 34 ms 75392 KB Output is correct
26 Correct 39 ms 75448 KB Output is correct
27 Correct 33 ms 75460 KB Output is correct
28 Correct 33 ms 75396 KB Output is correct
29 Correct 34 ms 75332 KB Output is correct
30 Correct 37 ms 75372 KB Output is correct
31 Correct 38 ms 75356 KB Output is correct
32 Correct 39 ms 75392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 75460 KB Output is correct
2 Correct 38 ms 75384 KB Output is correct
3 Correct 34 ms 75456 KB Output is correct
4 Correct 34 ms 75404 KB Output is correct
5 Correct 33 ms 75456 KB Output is correct
6 Correct 33 ms 75452 KB Output is correct
7 Correct 34 ms 75336 KB Output is correct
8 Correct 34 ms 75504 KB Output is correct
9 Correct 33 ms 75348 KB Output is correct
10 Correct 39 ms 75448 KB Output is correct
11 Correct 33 ms 75352 KB Output is correct
12 Correct 40 ms 75452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 75968 KB Output is correct
2 Correct 34 ms 75980 KB Output is correct
3 Correct 35 ms 76348 KB Output is correct
4 Correct 36 ms 76324 KB Output is correct
5 Correct 35 ms 75572 KB Output is correct
6 Correct 33 ms 75788 KB Output is correct
7 Correct 34 ms 75900 KB Output is correct
8 Correct 33 ms 75468 KB Output is correct
9 Correct 34 ms 75472 KB Output is correct
10 Correct 35 ms 75596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 81876 KB Output is correct
2 Correct 46 ms 80460 KB Output is correct
3 Correct 55 ms 85036 KB Output is correct
4 Correct 47 ms 82768 KB Output is correct
5 Correct 55 ms 77136 KB Output is correct
6 Correct 49 ms 78020 KB Output is correct
7 Correct 45 ms 79032 KB Output is correct
8 Correct 36 ms 75700 KB Output is correct
9 Correct 37 ms 77740 KB Output is correct
10 Correct 47 ms 76876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 94736 KB Output is correct
2 Correct 75 ms 88060 KB Output is correct
3 Correct 75 ms 104112 KB Output is correct
4 Correct 84 ms 92232 KB Output is correct
5 Correct 102 ms 81336 KB Output is correct
6 Correct 69 ms 87584 KB Output is correct
7 Correct 74 ms 85252 KB Output is correct
8 Correct 38 ms 76352 KB Output is correct
9 Correct 43 ms 76332 KB Output is correct
10 Correct 90 ms 80204 KB Output is correct
11 Correct 71 ms 88468 KB Output is correct
12 Correct 40 ms 78556 KB Output is correct