답안 #58477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58477 2018-07-18T00:45:14 Z andy627 구간 성분 (KOI15_interval) C++17
30 / 100
172 ms 744 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 3000000019
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);
     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 4 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 524 KB Output is correct
2 Correct 15 ms 524 KB Output is correct
3 Correct 15 ms 572 KB Output is correct
4 Correct 11 ms 676 KB Output is correct
5 Correct 23 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 744 KB Output is correct
2 Correct 74 ms 744 KB Output is correct
3 Incorrect 75 ms 744 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 744 KB Output is correct
2 Incorrect 172 ms 744 KB Output isn't correct
3 Halted 0 ms 0 KB -