답안 #453779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
453779 2021-08-04T18:48:28 Z nickmet2004 구간 성분 (KOI15_interval) C++11
61 / 100
1000 ms 116504 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 2005;
int A = 37;
int B = 1e9 + 9;
int C = 31;
int D = 1e9 + 7;
string s , t;
int pw1[27] , pw2[27];
struct Hash{
    size_t operator() (const pair<int , int> &x) const{
        return ((long long)x.first) ^ (((long long)x.second) << 32);
    }
};
unordered_map<pair<int , int>, int , Hash> H;
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);
           H[{x, y}]= 1;
        }
    }
    int ans = 0;
    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;
            if(H[{x , y}])ans = max(ans , j - i + 1);
        }
    }
    cout << ans;



}

Compilation message

interval.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 12444 KB Output is correct
2 Correct 38 ms 8928 KB Output is correct
3 Correct 14 ms 712 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 68 ms 13540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 454 ms 54704 KB Output is correct
2 Correct 479 ms 56272 KB Output is correct
3 Correct 458 ms 55776 KB Output is correct
4 Correct 450 ms 54780 KB Output is correct
5 Correct 462 ms 56148 KB Output is correct
6 Correct 451 ms 55032 KB Output is correct
7 Correct 472 ms 56092 KB Output is correct
8 Correct 457 ms 56292 KB Output is correct
9 Correct 459 ms 56344 KB Output is correct
10 Correct 462 ms 56032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 17436 KB Output is correct
2 Execution timed out 1091 ms 116504 KB Time limit exceeded
3 Halted 0 ms 0 KB -