답안 #845534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845534 2023-09-06T14:01:55 Z vjudge1 Trener (COCI20_trener) C++17
0 / 110
5 ms 1372 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
const int mod = 1e9 + 7;
inline long long get(string const& s) {
    const int p = 29;
    const int m = 1e9 + 7;
    long long hash_value = 0;
    long long p_pow = 1;
    for (char c : s) {
        hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
        p_pow = (p_pow * p) % m;
    }
    return hash_value;
}
void solve(){
	int n,k;cin >> n >> k;
	string v[n+1][k];
	map < int , int > mpa;
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<k;j++){
			cin >> v[i][j];
		}
	}
	for(int i = 0;i<k;i++)mpa[get(v[1][i])]++;
	for(int i = 2;i<=n;i++){
		for(int j = 0;j<k;j++){
			string s1 = string(v[i][j].begin() , v[i][j].end()-1) , s2 = string(v[i][j].begin()+1 , v[i][j].end());
			int myhash = get(v[i][j]);
			int childhash0 = get(s1);
			int childhash1 = get(s2);
			if(childhash0 == childhash1){
				mpa[myhash] = (mpa[myhash] + mpa[childhash0]) % mod;
			}
			else{
				mpa[myhash] = (mpa[myhash] + mpa[childhash0] + mpa[childhash1]) % mod;
			}	
		}
	}
	int ans = 0;
	for(int i = 0;i<k;i++)ans = (ans + mpa[get(v[n][i])]) % mod;
	cout << ans << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 5 ms 1368 KB Output is correct
4 Incorrect 3 ms 860 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -