Submission #291766

# Submission time Handle Problem Language Result Execution time Memory
291766 2020-09-05T18:42:30 Z penguinhacker Trener (COCI20_trener) C++17
0 / 110
8 ms 2944 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int MOD=1e9+7, P=37;
int getHash(string s) {
	ll pp=1, hsh=0;
	for (char c : s) {
		hsh=(hsh+(c-'a'+1)*pp)%MOD;
		pp=pp*P%MOD;
	}
	return hsh;
}

int n, k;
string name[50][1500];
unordered_map<int, int> dp, last;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;
	for (int i=0; i<n; ++i) for (int j=0; j<k; ++j) cin >> name[i][j];
	for (int i=0; i<k; ++i) dp[getHash(name[0][i])]=1;
	for (int i=1; i<n; ++i) { //current string is of length i+1
		swap(dp, last);
		dp.clear();
		for (int j=0; j<k; ++j) {
			int cur=getHash(name[i][j]);
			int hsh=getHash(name[i][j].substr(0, i));
			auto it=last.find(hsh);
			if (it!=last.end()) dp[cur]+=it->second;
			int hsh2=getHash(name[i][j].substr(1));
			if (hsh!=hsh2) {
				hsh=hsh2;
				it=last.find(hsh);
				if (it!=last.end()) dp[cur]+=it->second;
			}
		}
		//for (auto& x : dp) {cout << x.first << " " << x.second << "\n";}
		for (auto& x : dp) if (x.second>=MOD) x.second-=MOD;
		//cout << "\n\n";
	}
	int ans=0;
	for (auto& x : dp) ans=(ans+x.second)%MOD;
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 2944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -