Submission #709996

# Submission time Handle Problem Language Result Execution time Memory
709996 2023-03-15T02:35:37 Z willychan Trener (COCI20_trener) C++14
55 / 110
107 ms 5592 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds


const int MOD = 1e9+7;

int hsh(string &s,int l,int r){
	int p = 31;
	int ans=  0;
	for(int i=l;i<r;i++){
		ans=(1LL*ans*p)%MOD;
		ans+=(s[i]-'A');
		ans%=MOD;
	}
	return ans;
}

bool thesame(string s){
	char a = s[0];
	for(auto i : s){
		if(i!=a) return 0;
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;		
	int cnt[26];
	vector<vector<string> > arr(n+1);
	for(int i=1;i<=n;i++){
		for(int j=0;j<k;j++){
			string a;cin>>a;
			arr[i].push_back(a);
		}
	}
	int dp[k] = {0};
	for(int i=0;i<k;i++) dp[i]=1;
	map<int,int> mp;
	for(int i=n;i>=1;i--){
		if(i!=n){
			for(int j=0;j<k;j++){
				int whole = hsh(arr[i][j],0,i);
				dp[j] = mp[whole];
				if(thesame(arr[i][j])){
					dp[j]-=cnt[arr[i][j][0]-'a'];
				}
				dp[j]%=MOD;
			}
		}
		mp.clear();
		for(int i=0;i<26;i++) cnt[i]=0;
		for(int j=0;j<k;j++){
			if(thesame(arr[i][j])){
				cnt[arr[i][j][0]-'a']+=dp[j];
				cnt[arr[i][j][0]-'a']%=MOD;
			}
			int left = hsh(arr[i][j],0,i-1);
			int right = hsh(arr[i][j],1,i);
			mp[left]+=dp[j];
			mp[right]+=dp[j];
			mp[left]%=MOD;
			mp[right]%=MOD;
		}
	}
	int ans = 0;
	for(int i=0;i<k;i++){
		ans+=dp[i];
		ans%=MOD;
	}
	if(ans<0) ans+=MOD;
	cout<<ans<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 596 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 600 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 7 ms 596 KB Output is correct
6 Correct 6 ms 596 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 596 KB Output is correct
6 Correct 7 ms 708 KB Output is correct
7 Correct 7 ms 600 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 102 ms 5572 KB Output is correct
13 Correct 103 ms 5568 KB Output is correct
14 Correct 101 ms 5592 KB Output is correct
15 Correct 107 ms 5568 KB Output is correct
16 Correct 70 ms 5436 KB Output is correct
17 Incorrect 99 ms 5540 KB Output isn't correct
18 Halted 0 ms 0 KB -