# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58479 |
2018-07-18T01:22:04 Z |
andy627 |
구간 성분 (KOI15_interval) |
C++17 |
|
273 ms |
884 KB |
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#define LL long long
#define pll pair<LL,LL>
#define plli pair<pll,int>
#define ff first
#define ss second
using namespace std;
char s1[1555],s2[1555];
LL MOD[2]={(LL)1e9+7,(LL)1e9+9};
LL mul[2][1555];
LL hash1[2][1555],hash2[2][1555];
vector<plli> res;
int main(){
int len1,len2,len;
scanf("%s %s",s1,s2);
len1=strlen(s1); len2=strlen(s2);
len=min(len1,len2);
mul[0][0]=mul[1][0]=1;
for(int t=0;t<2;t++)
for(int i=1;i<26;i++) mul[t][i]=(mul[t][i-1]*len)%MOD[t];
int ans=0;
for(int t=0;t<2;t++){
for(int i=0;i<len1;i++) hash1[t][i]=mul[t][s1[i]-'a'];
for(int i=0;i<len2;i++) hash2[t][i]=mul[t][s2[i]-'a'];
}
for(int i=0;i<len1;i++) res.push_back({{hash1[0][i],hash1[1][i]},1});
for(int i=0;i<len2;i++) res.push_back({{hash2[0][i],hash2[1][i]},2});
sort(res.begin(),res.end());
// printf("1\n");
// for(int i=0;i<res.size();i++) printf("%10lld %10lld %d\n",res[i].ff.ff,res[i].ff.ss,res[i].ss);
// printf("\n\n\n");
for(int i=1;i<res.size();i++){
if(res[i-1].ff==res[i].ff && res[i-1].ss+res[i].ss==3) ans=1;
}
for(int i=1;i<len;i++){
res.clear();
for(int t=0;t<2;t++){
for(int j=len1-1;j>=i-1;j--) hash1[t][j]=(hash1[t][j-1]+mul[t][s1[j]-'a'])%MOD[t];
for(int j=len2-1;j>=i-1;j--) hash2[t][j]=(hash2[t][j-1]+mul[t][s2[j]-'a'])%MOD[t];
}
for(int j=i-1;j<len1;j++) res.push_back({{hash1[0][j],hash1[1][j]},1});
for(int j=i-1;j<len2;j++) res.push_back({{hash2[0][j],hash2[1][j]},2});
sort(res.begin(),res.end());
// printf("%d\n",i+1);
// for(int i=0;i<res.size();i++) printf("%10lld %10lld %d\n",res[i].ff.ff,res[i].ff.ss,res[i].ss);
// printf("\n\n\n");
for(int j=1;j<res.size();j++){
if(res[j-1].ff==res[j].ff && res[j-1].ss+res[j].ss==3) ans=i+1;
}
}
printf("%d",ans);
return 0;
}
Compilation message
interval.cpp: In function 'int main()':
interval.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<res.size();i++){
~^~~~~~~~~~~
interval.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<res.size();j++){
~^~~~~~~~~~~
interval.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s %s",s1,s2);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
484 KB |
Output is correct |
2 |
Correct |
21 ms |
536 KB |
Output is correct |
3 |
Correct |
23 ms |
536 KB |
Output is correct |
4 |
Correct |
31 ms |
584 KB |
Output is correct |
5 |
Correct |
29 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
712 KB |
Output is correct |
2 |
Correct |
109 ms |
712 KB |
Output is correct |
3 |
Correct |
108 ms |
840 KB |
Output is correct |
4 |
Correct |
111 ms |
844 KB |
Output is correct |
5 |
Correct |
110 ms |
844 KB |
Output is correct |
6 |
Correct |
94 ms |
844 KB |
Output is correct |
7 |
Correct |
104 ms |
844 KB |
Output is correct |
8 |
Correct |
102 ms |
844 KB |
Output is correct |
9 |
Correct |
106 ms |
844 KB |
Output is correct |
10 |
Correct |
114 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
844 KB |
Output is correct |
2 |
Correct |
273 ms |
884 KB |
Output is correct |
3 |
Correct |
248 ms |
884 KB |
Output is correct |
4 |
Correct |
221 ms |
884 KB |
Output is correct |
5 |
Correct |
234 ms |
884 KB |
Output is correct |