Submission #321242

# Submission time Handle Problem Language Result Execution time Memory
321242 2020-11-11T16:40:47 Z tjdgus4384 구간 성분 (KOI15_interval) C++14
38 / 100
165 ms 508 KB
#include<bits/stdc++.h>
using namespace std;
string s1, s2;
long long p[30] = {614313243, 43029480, 52309234, 2347048024, 2345082354, 42039843, 70249523,123523561, 134141563, 273736614, 245774235, 945583495, 1509845718, 149315734, 1235751910, 132479822, 21234190349, 3241409824, 210497384, 1903784134, 17504353, 789845354, 39074583, 15790824, 143570154, 13475980452, 23470981234, 2019874312, 1908734134, 19378443};
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++){
      |                       ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 364 KB Output is correct
2 Incorrect 11 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 508 KB Output is correct
2 Correct 77 ms 364 KB Output is correct
3 Correct 76 ms 364 KB Output is correct
4 Correct 80 ms 364 KB Output is correct
5 Correct 77 ms 364 KB Output is correct
6 Correct 81 ms 364 KB Output is correct
7 Correct 74 ms 364 KB Output is correct
8 Correct 80 ms 384 KB Output is correct
9 Correct 77 ms 364 KB Output is correct
10 Correct 80 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 364 KB Output is correct
2 Incorrect 165 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -