답안 #233107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233107 2020-05-19T11:17:24 Z PeppaPig Lozinke (COCI17_lozinke) C++14
100 / 100
328 ms 13220 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 2e4+5;
const int P = 1e9+7;

int n, ans;
char S[N][15];
map<long, int> mp;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf(" %s", S[i] + 1);
        long hsh = 0;
        for(int j = 1; j <= strlen(S[i] + 1); j++)
            hsh = hsh * P + S[i][j];
        ++mp[hsh];
    }
    for(int i = 1; i <= n; i++) {
        int len = strlen(S[i] + 1);
        set<long> st;
        for(int j = 1; j <= len; j++) {
            long hsh = 0;
            for(int k = j; k <= len; k++) {
                hsh = hsh * P + S[i][k];
                if(st.find(hsh) == st.end()) {
                    ans += mp[hsh];
                    if(j == 1 && k == len) --ans;
                    st.emplace(hsh);
                }
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:19:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1; j <= strlen(S[i] + 1); j++)
                        ~~^~~~~~~~~~~~~~~~~~~
lozinke.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
lozinke.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", S[i] + 1);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 10 ms 640 KB Output is correct
6 Correct 13 ms 640 KB Output is correct
7 Correct 16 ms 1280 KB Output is correct
8 Correct 25 ms 1920 KB Output is correct
9 Correct 52 ms 1912 KB Output is correct
10 Correct 137 ms 6008 KB Output is correct
11 Correct 87 ms 3448 KB Output is correct
12 Correct 304 ms 13220 KB Output is correct
13 Correct 158 ms 2424 KB Output is correct
14 Correct 229 ms 11896 KB Output is correct
15 Correct 328 ms 13048 KB Output is correct
16 Correct 144 ms 896 KB Output is correct
17 Correct 26 ms 768 KB Output is correct
18 Correct 21 ms 768 KB Output is correct
19 Correct 173 ms 6776 KB Output is correct
20 Correct 73 ms 896 KB Output is correct