Submission #37312

#TimeUsernameProblemLanguageResultExecution timeMemory
37312wasylLozinke (COCI17_lozinke)C++11
85 / 100
89 ms8992 KiB
#include <vector> #include <iostream> #include <algorithm> #define d(...) __VA_ARGS__ #define all(x) (x).begin(), (x).end() #define eb(...) emplace_back(__VA_ARGS__) using namespace std;using ll=long long; template<class t>using V = vector< t >; const int p = 29; const int mod = 1e9 + 7; int n; V< int > hasze; V< string > pass; void parse ( string& s ) { V< int > tmp; for ( int i = 0; i < s.size(); ++i ) { int hasz = 0; for ( int k = i; k < s.size(); ++k ) { hasz = ( (ll)hasz * p + s[k] - 'a' + 1 ) % mod; tmp.eb( hasz ); } } sort( all( tmp ) ); tmp.resize( unique( all( tmp ) ) - tmp.begin() ); for ( int h : tmp ) hasze.eb( h ); } int count ( string& s ) { int hasz = 0; for ( char c : s ) hasz = ( (ll)hasz * p + c - 'a' + 1 ) % mod; return upper_bound( all( hasze ), hasz ) - lower_bound( all( hasze ), hasz ); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; pass.resize( n ); for ( auto& i : pass ) cin >> i; for ( auto& i : pass ) parse( i ); sort( all( hasze ) ); hasze.eb( mod ); int res = 0; for ( auto& i : pass ) res += count( i ) - 1; cout << res << '\n'; }

Compilation message (stderr)

lozinke.cpp: In function 'void parse(std::__cxx11::string&)':
lozinke.cpp:20:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < s.size(); ++i )
                     ^
lozinke.cpp:23:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for ( int k = i; k < s.size(); ++k )
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...