Submission #845611

# Submission time Handle Problem Language Result Execution time Memory
845611 2023-09-06T14:28:21 Z vjudge1 Trener (COCI20_trener) C++17
110 / 110
186 ms 2936 KB
#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, ansmod = 1000000007;

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(k);
	map <int, int> dp; // öncekilerin hashleri ile dpleri
	for(int i = 0; i < n; i++) {
		if(!i) { // i 0 ise
			for(int j = 0; j < k; j++) {
				cin>>ss[j];
				if(!dp.count(hashing(ss[j])))
					dp.insert( { hashing(ss[j]), 1ll } );
				else
					dp[hashing(ss[j])]++;
			}
			continue;
		}

		map <int, int> tdp;
		for(int j = 0; j < k; j++) {
			cin>>ss[j];
			tdp.insert( { hashing(ss[j]), 0ll } );
		}

		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 + tdp[hashing(ss[j])]) % ansmod;
		}

		dp.clear();
		for(auto it:tdp) {
			dp.insert(it);
		}
	}
	int ans = 0;
	for(auto it:dp) {
		ans = (ans + it.second) % ansmod;
	}
	cout<<ans<<"\n";
}

Compilation message

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++) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 344 KB Output is correct
2 Correct 12 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 15 ms 600 KB Output is correct
6 Correct 15 ms 604 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 14 ms 344 KB Output is correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 12 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 15 ms 600 KB Output is correct
10 Correct 15 ms 604 KB Output is correct
11 Correct 11 ms 344 KB Output is correct
12 Correct 181 ms 2564 KB Output is correct
13 Correct 184 ms 2936 KB Output is correct
14 Correct 180 ms 2644 KB Output is correct
15 Correct 186 ms 2696 KB Output is correct
16 Correct 122 ms 2580 KB Output is correct
17 Correct 182 ms 2624 KB Output is correct
18 Correct 183 ms 2640 KB Output is correct
19 Correct 179 ms 2640 KB Output is correct
20 Correct 184 ms 2532 KB Output is correct
21 Correct 179 ms 2564 KB Output is correct
22 Correct 123 ms 2456 KB Output is correct