Submission #914703

#TimeUsernameProblemLanguageResultExecution timeMemory
914703racsosabeLozinke (COCI17_lozinke)C++14
100 / 100
12 ms9564 KiB
#include<bits/stdc++.h> using namespace::std; const int N = 20000 + 5; const int L = 12; const int SUML = 20000 * 10 + 5; const int E = 26; int n; int len[N]; char s[N][L]; int nodes = 1; int frec[SUML]; bool vis[SUML]; int trie[E][SUML]; void insert(int id) { int pos = 0; for(int i = 0; i < len[id]; i++) { int c = s[id][i] - 'a'; if(trie[c][pos] == 0) trie[c][pos] = nodes++; pos = trie[c][pos]; } frec[pos] += 1; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%s", s[i]); len[i] = strlen(s[i]); insert(i); } long long res = 0; for(int id = 1; id <= n; id++) { for(int i = 0; i < len[id]; i++) { int pos = 0; for(int j = i; j < len[id]; j++) { int c = s[id][j] - 'a'; if(trie[c][pos] == 0) break; pos = trie[c][pos]; if(not vis[pos]) { res += frec[pos]; vis[pos] = true; } } } for(int i = 0; i < len[id]; i++) { int pos = 0; for(int j = i; j < len[id]; j++) { int c = s[id][j] - 'a'; if(trie[c][pos] == 0) break; pos = trie[c][pos]; vis[pos] = false; } } res -= 1; } printf("%lld\n", res); return 0; }

Compilation message (stderr)

lozinke.cpp: In function 'int main()':
lozinke.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
lozinke.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%s", s[i]);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...