# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
448365 | 2021-07-29T20:45:29 Z | nickmet2004 | 구간 성분 (KOI15_interval) | C++11 | 84 ms | 16460 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*A%B) % B; pol2[0] = 1; for(int i = 1; i < 26; i ++) pol2[i] = (long long)pol2[i - 1] * (long long)(C*C%D) % D; //for(int i = 1; i <= 26; ++i)cout << pol1[i] << " ";cout << endl; //for(int i = 1; i <= 26; ++i)cout << pol2[i] << " ";cout << endl; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Incorrect | 1 ms | 460 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 2672 KB | Output is correct |
2 | Incorrect | 13 ms | 2624 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 11024 KB | Output is correct |
2 | Correct | 78 ms | 10992 KB | Output is correct |
3 | Correct | 75 ms | 11056 KB | Output is correct |
4 | Correct | 84 ms | 10948 KB | Output is correct |
5 | Correct | 76 ms | 10956 KB | Output is correct |
6 | Incorrect | 76 ms | 11052 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 16460 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |