Submission #71120

#TimeUsernameProblemLanguageResultExecution timeMemory
711203zp구간 성분 (KOI15_interval)C++14
30 / 100
1073 ms46064 KiB
#include<bits/stdc++.h>
using namespace std;
int A = 987654323;
int B = 1e9 + 9;
int pol[26];
set<int> sa[1509];
main(){
    pol[0] = 1;
    for(int i = 1; i < 26; i ++)
        pol[i] = (long long)pol[i - 1] * (long long)A % B;
    int n, m;
    string a, b;
    cin >> a >> b;
    n = a.size(), m = b.size();
    for(int i = 0; i < n; i++){
        long long H = 0;
        for(int j = i; j < n; j++){
            H += pol[a[j] - 'a'];
            if(H > B) H -= B;
            sa[j - i + 1].insert(H);
        }
    }
    int ans = 0;
    for(int i = 0; i < m; i++){
        long long H = 0;
        for(int j = i; j < m; j++){
            H += pol[b[j] - 'a'];
            if(H > B) H -= B;
            if(sa[j - i + 1].find(H) != sa[j - i + 1].end()){
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;


}

Compilation message (stderr)

interval.cpp:7:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...