Submission #448364

#TimeUsernameProblemLanguageResultExecution timeMemory
448364nickmet2004구간 성분 (KOI15_interval)C++11
0 / 100
76 ms16328 KiB
#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; pol2[0] = 1; for(int i = 1; i < 26; i ++) pol2[i] = (long long)pol2[i - 1] * (long long)(C*C) % 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 (stderr)

interval.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
interval.cpp: In function 'int main()':
interval.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i = 0 ;i < sa[k].size(); i++)
      |                        ~~^~~~~~~~~~~~~~
interval.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             while(j < sb[k].size() && sb[k][j] < sa[k][i]) j++;
      |                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...