Submission #845552

#TimeUsernameProblemLanguageResultExecution timeMemory
845552vjudge1Trener (COCI20_trener)C++17
0 / 110
1 ms600 KiB
#include <bits/stdc++.h> #define fast cin.tie(0)->sync_with_stdio(0); #define int long long #define inf ((int)1e18) #define N 200005 using namespace std; const int hbase = 127, hmod = 1610612741; int binpow(int x, int y, const int modulo) { int ret = 1; while(y) { if(y & 1) { ret *= x; ret %= modulo; } y /= 2; x *= x; x %= modulo; } return ret; } int hashing(string s) { // cout<<s<<"\n"; int ret = 0; for(int i = 0; i < s.size(); i++) { ret += binpow(hbase, i, hmod) * (s[i] - 97); ret %= hmod; } // cout<<ret<<"\n"; return ret; } int32_t main(){ fast int n, k; cin>>n>>k; vector<string> ss(n); map <int, int> dp; // öncekilerin hashleri ile dpleri for(int i = 0; i < n; i++) { map <int, int> tdp; for(int j = 0; j < k; j++) { cin>>ss[j]; tdp.insert( { hashing(ss[j]), 0ll } ); } if(!i) { // i 0 ise for(auto& it:tdp) { it.second = 1; } for(auto it:tdp) { dp.insert(it); } continue; } for(auto it:dp) { } for(int j = 0; j < k; j++) { int val = 0; string temp = ss[j]; temp.erase(temp.begin()); if( dp.count(hashing(temp)) ) val += dp[hashing(temp)]; string temp2 = ss[j]; temp2.pop_back(); if( temp != temp2 and dp.count(hashing(temp2)) ) val += dp[hashing(temp2)]; tdp[hashing(ss[j])] += val; } dp.clear(); for(auto it:tdp) { dp.insert(it); } } int ans = 0; for(auto it:dp) { ans += it.second; } cout<<ans<<"\n"; }

Compilation message (stderr)

trener.cpp: In function 'long long int hashing(std::string)':
trener.cpp:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
trener.cpp: In function 'int32_t main()':
trener.cpp:58:12: warning: variable 'it' set but not used [-Wunused-but-set-variable]
   58 |   for(auto it:dp) {
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...