Submission #71141

# Submission time Handle Problem Language Result Execution time Memory
71141 2018-08-24T07:17:30 Z 3zp 구간 성분 (KOI15_interval) C++14
100 / 100
268 ms 25892 KB
#include<bits/stdc++.h>
using namespace std;
int A = 987654323;
int B = 1e9 + 9;
int C = 985201597;
int D = 660353359;
int pol1[26];
int pol2[26];
vector<pair<int,int> > sa[1509];
vector<pair<int,int> > sb[1509];
main(){
    pol1[0] = 1;
    for(int i = 1; i < 26; i ++)
        pol1[i] = (long long)pol1[i - 1] * (long long)A % B;
    pol2[0] = 1;
    for(int i = 1; i < 26; i ++)
        pol2[i] = (long long)pol2[i - 1] * (long long)C % D;
    int n, m;
    string a, b;
    cin >> a >> b;
    n = a.size(), m = b.size();
    for(int i = 0; i < n; i++){
        int H1 = 0, H2 = 0;
        for(int j = i; j < n; j++){
            H1 += pol1[a[j] - 'a'];
            H2 += pol2[a[j] - 'a'];
            if(H1 >= B) H1 -= B;
            if(H2 >= D) H2 -= D;
            sa[j - i + 1].push_back({H1,H2});
        }
    }
    int ans = 0;
     for(int i = 0; i < m; i++){
        int H1 = 0, H2 = 0;
        for(int j = i; j < m; j++){
            H1 += pol1[b[j] - 'a'];
            H2 += pol2[b[j] - 'a'];
            if(H1 >= B) H1 -= B;
            if(H2 >= D) H2 -= D;
            sb[j - i + 1].push_back({H1,H2});
            }
        }
    for(int k = min(m,n); k >=0; k--){
        sort(sa[k].begin(), sa[k].end());
        sort(sb[k].begin(), sb[k].end());
        int j = 0;
        for(int i = 0 ;i < sa[k].size(); i++)
        {
            while(j < sb[k].size() && sb[k][j] < sa[k][i]) j++;
            if(sb[k][j] == sa[k][i]){
                cout<<k<<endl;
                return 0;
            }

        }
    }
    cout << ans << endl;


}

Compilation message

interval.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
interval.cpp: In function 'int main()':
interval.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0 ;i < sa[k].size(); i++)
                        ~~^~~~~~~~~~~~~~
interval.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(j < sb[k].size() && sb[k][j] < sa[k][i]) j++;
                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 3 ms 564 KB Output is correct
5 Correct 4 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2848 KB Output is correct
2 Correct 22 ms 2848 KB Output is correct
3 Correct 10 ms 3308 KB Output is correct
4 Correct 10 ms 3308 KB Output is correct
5 Correct 22 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 11372 KB Output is correct
2 Correct 102 ms 11372 KB Output is correct
3 Correct 101 ms 11372 KB Output is correct
4 Correct 92 ms 11372 KB Output is correct
5 Correct 100 ms 11372 KB Output is correct
6 Correct 111 ms 11372 KB Output is correct
7 Correct 109 ms 11372 KB Output is correct
8 Correct 136 ms 11372 KB Output is correct
9 Correct 92 ms 11388 KB Output is correct
10 Correct 108 ms 11388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 16684 KB Output is correct
2 Correct 219 ms 25824 KB Output is correct
3 Correct 233 ms 25824 KB Output is correct
4 Correct 93 ms 25824 KB Output is correct
5 Correct 268 ms 25892 KB Output is correct