답안 #165732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165732 2019-11-28T12:05:03 Z Sensei Lozinke (COCI17_lozinke) C++17
50 / 100
1000 ms 3448 KB
    #include <bits/stdc++.h>
     
    using namespace std;
     
    const long long P = 53;
    const long long MOD = 1e9 + 7;
     
    const int MAXN = 2e4;
     
    long long add (long long x, long long y) {
    	return ((x % MOD) + (y % MOD)) % MOD;
    }
     
    long long mul (long long x, long long y) {
    	return ((x % MOD) * (y % MOD)) % MOD;
    }
     
    map<long long, set<int> > m;
    string st[MAXN + 7];
     
    int main () {
    	int N;
    	cin >> N;
     
    	for (int i = 1; i <= N; i++) {
    		cin >> st[i];
    	}
     
    	for (int i = 1; i <= N; i++) {
    		long long hash = 0;
     
    		for (int j = 0; j < st[i].size(); j++) {
    			hash = mul(hash, P);
    			hash = add(hash, st[i][j] - 'a' + 1);
    		}
     
    		m[hash].insert(i);
    	}
     
    	long long ans = 0;
     
    	for (int i = 1; i <= N; i++) {
    		vector<bool> s(N + 1, false);
     
    		for (int ss = 0; ss < st[i].size(); ss++) {
    			long long hash = 0;
     
    			for (int j = ss; j < st[i].size(); j++) {
    				if (ss == 0 && j + 1 == st[i].size()) {
    					break;
    				}
     
    				hash = mul(hash, P);
    				hash = add(hash, st[i][j] - 'a' + 1);
     
    				if (m.find(hash) != m.end()) {
    					for (int id : m[hash]) {
    						if (id != i) {
    							s[id] = true;
    						}
    					}
    				}
    			}
    		}

    		for (int j = 1; j <= N; j++) {
    			if (i != j) {
    				ans += s[j];
    			}
    		}
    	}
     
    	long long ans2 = 0;
     
    	for (int i = 1; i <= N; i++) {
    		long long hash = 0;
     
    		for (int j = 0; j < st[i].size(); j++) {
    			hash = mul(hash, P);
    			hash = add(hash, st[i][j] - 'a' + 1);
    		}
     
    		ans2 += m[hash].size() - 1;
    	}
     
    	ans += ans2;
     
    	cout << ans << "\n";
     
    	return 0;
    }

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:32:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < st[i].size(); j++) {
                       ~~^~~~~~~~~~~~~~
lozinke.cpp:45:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int ss = 0; ss < st[i].size(); ss++) {
                        ~~~^~~~~~~~~~~~~~
lozinke.cpp:48:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
        for (int j = ss; j < st[i].size(); j++) {
                         ~~^~~~~~~~~~~~~~
lozinke.cpp:49:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ss == 0 && j + 1 == st[i].size()) {
                        ~~~~~~^~~~~~~~~~~~~~~
lozinke.cpp:78:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < st[i].size(); j++) {
                       ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 888 KB Output is correct
2 Correct 2 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 10 ms 1144 KB Output is correct
6 Correct 13 ms 1144 KB Output is correct
7 Correct 24 ms 1144 KB Output is correct
8 Correct 19 ms 1144 KB Output is correct
9 Correct 638 ms 1912 KB Output is correct
10 Correct 316 ms 2040 KB Output is correct
11 Execution timed out 1070 ms 2552 KB Time limit exceeded
12 Incorrect 705 ms 2552 KB Output isn't correct
13 Execution timed out 1085 ms 3064 KB Time limit exceeded
14 Execution timed out 1082 ms 3448 KB Time limit exceeded
15 Execution timed out 1079 ms 3192 KB Time limit exceeded
16 Execution timed out 1063 ms 2040 KB Time limit exceeded
17 Execution timed out 1079 ms 1912 KB Time limit exceeded
18 Execution timed out 1037 ms 1912 KB Time limit exceeded
19 Execution timed out 1088 ms 3064 KB Time limit exceeded
20 Execution timed out 1081 ms 2040 KB Time limit exceeded