답안 #321241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321241 2020-11-11T16:39:36 Z tjdgus4384 구간 성분 (KOI15_interval) C++14
77 / 100
182 ms 492 KB
#include<bits/stdc++.h>
using namespace std;
string s1, s2;
long long p[]={1553543355441,6835413543356,341238467843,5846878493734,255654493854,4385646055553,29333247254,56842665466513,6562454444132,33264680204,97185465094454,8937264644356,85143166465423,78565446465415,98746146556215,8547654654856,841537879874131,7293864657254,9814378779242,74464658844594,24495564314761,186549524066569,39665654465873,481654731322,41565458484,13646542908};
set<long long> s;

int main(){
    cin >> s1 >> s2;
    for(int i = s1.size();i > 0;i--){
        if(i > s2.size()) continue;
        long long sum = 0;
        for(int j = 0;j < i;j++) sum += p[s1[j]-'a'];
        s.insert(sum);
        for(int j = i;j < s1.size();j++){
            sum -= p[s1[j-i]-'a'];
            sum += p[s1[j]-'a'];
            s.insert(sum);
        }

        sum = 0;
        for(int j = 0;j < i;j++) sum += p[s2[j]-'a'];
        if(s.count(sum)) {printf("%d", i); return 0;}
        for(int j = i;j < s1.size();j++){
            sum -= p[s2[j-i]-'a'];
            sum += p[s2[j]-'a'];
            if(s.count(sum)) {printf("%d", i); return 0;}
        }
        s.clear();
    }
    printf("0");
    return 0;
}

Compilation message

interval.cpp: In function 'int main()':
interval.cpp:10:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         if(i > s2.size()) continue;
      |            ~~^~~~~~~~~~~
interval.cpp:14:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for(int j = i;j < s1.size();j++){
      |                       ~~^~~~~~~~~~~
interval.cpp:23:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int j = i;j < s1.size();j++){
      |                       ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 396 KB Output is correct
2 Incorrect 10 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 408 KB Output is correct
2 Correct 76 ms 384 KB Output is correct
3 Correct 75 ms 364 KB Output is correct
4 Correct 87 ms 364 KB Output is correct
5 Correct 77 ms 364 KB Output is correct
6 Correct 77 ms 364 KB Output is correct
7 Correct 74 ms 364 KB Output is correct
8 Correct 83 ms 364 KB Output is correct
9 Correct 82 ms 364 KB Output is correct
10 Correct 80 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 364 KB Output is correct
2 Correct 170 ms 364 KB Output is correct
3 Correct 144 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 182 ms 364 KB Output is correct