제출 #71141

#제출 시각아이디문제언어결과실행 시간메모리
711413zp구간 성분 (KOI15_interval)C++14
100 / 100
268 ms25892 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 % B; pol2[0] = 1; for(int i = 1; i < 26; i ++) pol2[i] = (long long)pol2[i - 1] * (long long)C % D; 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; }

컴파일 시 표준 에러 (stderr) 메시지

interval.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
interval.cpp: In function 'int main()':
interval.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0 ;i < sa[k].size(); i++)
                        ~~^~~~~~~~~~~~~~
interval.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             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...