답안 #453778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
453778 2021-08-04T18:47:45 Z nickmet2004 구간 성분 (KOI15_interval) C++11
61 / 100
1000 ms 116468 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 + 2;
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 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 12636 KB Output is correct
2 Correct 38 ms 8884 KB Output is correct
3 Correct 13 ms 716 KB Output is correct
4 Correct 6 ms 332 KB Output is correct
5 Correct 69 ms 13540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 460 ms 54668 KB Output is correct
2 Correct 476 ms 56168 KB Output is correct
3 Correct 475 ms 55848 KB Output is correct
4 Correct 469 ms 54748 KB Output is correct
5 Correct 487 ms 56208 KB Output is correct
6 Correct 452 ms 54888 KB Output is correct
7 Correct 501 ms 56120 KB Output is correct
8 Correct 486 ms 56364 KB Output is correct
9 Correct 469 ms 56292 KB Output is correct
10 Correct 501 ms 55988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 17484 KB Output is correct
2 Execution timed out 1102 ms 116468 KB Time limit exceeded
3 Halted 0 ms 0 KB -