Submission #58473

# Submission time Handle Problem Language Result Execution time Memory
58473 2018-07-18T00:36:03 Z andy627 구간 성분 (KOI15_interval) C++17
100 / 100
205 ms 748 KB
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#define LL long long
#define pli pair<LL,int>
#define ff first
#define ss second
#define MOD 1000000007
using namespace std;

char s1[1555],s2[1555];
LL mul[1555];
LL hash1[1555],hash2[1555];
vector<pli> res;

int main(){
    int len1,len2,len;

    scanf("%s %s",s1,s2);
    len1=strlen(s1); len2=strlen(s2);
    len=min(len1,len2);

    mul[0]=1;
    for(int i=1;i<26;i++) mul[i]=(mul[i-1]*len)%MOD;

    int ans=0;
    for(int i=0;i<len1;i++) hash1[i]=mul[s1[i]-'a'],res.push_back({hash1[i],1});
    for(int i=0;i<len2;i++) hash2[i]=mul[s2[i]-'a'],res.push_back({hash2[i],2});
    sort(res.begin(),res.end());

    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 j=len1-1;j>=i-1;j--) hash1[j]=(hash1[j-1]+mul[s1[j]-'a'])%MOD,res.push_back({hash1[j],1});
        for(int j=len2-1;j>=i-1;j--) hash2[j]=(hash2[j-1]+mul[s2[j]-'a'])%MOD,res.push_back({hash2[j],2});
        sort(res.begin(),res.end());

        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:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<res.size();i++){
                 ~^~~~~~~~~~~
interval.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=1;j<res.size();j++){
                     ~^~~~~~~~~~~
interval.cpp:20: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 3 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 4 ms 568 KB Output is correct
5 Correct 4 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 568 KB Output is correct
2 Correct 16 ms 568 KB Output is correct
3 Correct 17 ms 620 KB Output is correct
4 Correct 21 ms 620 KB Output is correct
5 Correct 21 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 684 KB Output is correct
2 Correct 84 ms 748 KB Output is correct
3 Correct 80 ms 748 KB Output is correct
4 Correct 74 ms 748 KB Output is correct
5 Correct 78 ms 748 KB Output is correct
6 Correct 78 ms 748 KB Output is correct
7 Correct 92 ms 748 KB Output is correct
8 Correct 78 ms 748 KB Output is correct
9 Correct 82 ms 748 KB Output is correct
10 Correct 77 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 748 KB Output is correct
2 Correct 198 ms 748 KB Output is correct
3 Correct 205 ms 748 KB Output is correct
4 Correct 182 ms 748 KB Output is correct
5 Correct 205 ms 748 KB Output is correct