답안 #450434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
450434 2021-08-02T21:35:51 Z nickmet2004 구간 성분 (KOI15_interval) C++11
100 / 100
179 ms 48716 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 2005;
int A = 987654323;
int B = 1e9 + 9;
int C = 985201597;
int D = 1e9 + 7;
string s , t;
int pw1[27] , pw2[27];
vector<pair<int , int>> a[N] , b[N];
main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> s >> t;
    int n = s.size() , m = t.size();
    pw1[0] = pw2[0] = 1;
    for(int i = 1; i < 26; ++i) pw1[i] = pw1[i - 1] * A*(i + 1) % B;
    for(int i = 1; i< 26; ++i) pw2[i] = pw2[i - 1] * C*(i + 1) % D;
    for(int i = 0; i < n; ++i){
        int x= 0 , y =0;
        for(int j = i; j < n; ++j){
            x += pw1[s[j] - 'a'];
            y += pw2[s[j] - 'a'];
            if(x>=B)x-=B;
            if(y>=D)y-=D;
            a[j - i + 1].emplace_back(x , y);
        }
    }
    for(int i = 0; i < m; ++i){
        int x= 0 , y =0;
        for(int j = i; j < m; ++j){
            x += pw1[t[j] - 'a'];
            y += pw2[t[j] - 'a'];
            if(x>=B)x-=B;
            if(y>=D)y-=D;
            b[j - i + 1].emplace_back(x , y);
        }
    }
    for(int i = min(n , m); ~i; --i){
        sort(a[i].begin() , a[i].end());
        sort(b[i].begin() , b[i].end());
        int k = 0;
        for(int j= 0; j <a[i].size(); ++j){
            while(a[i][j] > b[i][k] && k < b[i].size())++k;
            if(a[i][j] == b[i][k]){cout << i << endl; return 0;}
        }
    }cout << 0;



}

Compilation message

interval.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main (){
      | ^~~~
interval.cpp: In function 'int main()':
interval.cpp:45:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j= 0; j <a[i].size(); ++j){
      |                       ~~^~~~~~~~~~~~
interval.cpp:46:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             while(a[i][j] > b[i][k] && k < b[i].size())++k;
      |                                        ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4896 KB Output is correct
2 Correct 12 ms 4984 KB Output is correct
3 Correct 6 ms 5708 KB Output is correct
4 Correct 6 ms 5708 KB Output is correct
5 Correct 18 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 20980 KB Output is correct
2 Correct 76 ms 21020 KB Output is correct
3 Correct 76 ms 21028 KB Output is correct
4 Correct 84 ms 21028 KB Output is correct
5 Correct 76 ms 21024 KB Output is correct
6 Correct 81 ms 20940 KB Output is correct
7 Correct 77 ms 21032 KB Output is correct
8 Correct 75 ms 20964 KB Output is correct
9 Correct 76 ms 21024 KB Output is correct
10 Correct 76 ms 20940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 31376 KB Output is correct
2 Correct 173 ms 48708 KB Output is correct
3 Correct 170 ms 48492 KB Output is correct
4 Correct 51 ms 48580 KB Output is correct
5 Correct 179 ms 48716 KB Output is correct