답안 #845494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845494 2023-09-06T13:52:21 Z vjudge1 Trener (COCI20_trener) C++17
55 / 110
105 ms 18588 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;
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve(){
	int n,k;cin >> n >> k;
	string v[n+1][k];
	unordered_map < int , vector < int > , custom_hash > mpa;
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<k;j++){
			cin >> v[i][j];
			mpa[get(v[i][j])].push_back(j);
		}

	}
	int dp[n+1][k];
	memset(dp , 0 , sizeof(dp));
	for(int i = 0;i<k;i++)dp[1][i] = 1;
	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());
			vector < int > ind1 = mpa[get(s1)];
			vector < int > ind2 = mpa[get(s2)];
			for(auto itr : ind2)ind1.push_back(itr);
			sort(ind1.begin(),ind1.end());
			ind1.resize(unique(ind1.begin() , ind1.end()) - ind1.begin());
			for(auto itr : ind1){
				dp[i][j] = (dp[i][j] + dp[i-1][itr]) % mod;
			}
		}
	}
	int ans = 0;
	for(int i = 0;i<k;i++)ans = (ans + dp[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 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1628 KB Output is correct
2 Correct 5 ms 1624 KB Output is correct
3 Correct 5 ms 1628 KB Output is correct
4 Correct 26 ms 888 KB Output is correct
5 Correct 5 ms 1368 KB Output is correct
6 Correct 5 ms 1620 KB Output is correct
7 Correct 18 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 5 ms 1628 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 5 ms 1628 KB Output is correct
8 Correct 26 ms 888 KB Output is correct
9 Correct 5 ms 1368 KB Output is correct
10 Correct 5 ms 1620 KB Output is correct
11 Correct 18 ms 856 KB Output is correct
12 Correct 105 ms 18376 KB Output is correct
13 Incorrect 103 ms 18588 KB Output isn't correct
14 Halted 0 ms 0 KB -