답안 #881474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881474 2023-12-01T09:27:48 Z vjudge1 Trener (COCI20_trener) C++17
110 / 110
410 ms 9808 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
//~ #define int long long
using namespace std;
 
typedef tuple<int, int, int> iii;
typedef long long ll;
const int mod = 1e9+7;
//~ const int mod =998244353;
 
int n, k;
string s[55][1505];
int a[55][1505][5], ans[55][1505], pw[1505];
int32_t main(){
	fast;
	int n, k;
	cin>>n>>k;
	pw[0]= 1;
	for(int i=1;i<=n;i++){
		pw[i]=pw[i-1]*29%mod;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			cin>>s[i][j];
			for(int l=0;l<i;l++){
				a[i][j][0]+=(s[i][j][l]-'a'+1)*pw[l]%mod;
				a[i][j][0]%=mod;
			}
			for(int l=0;l<i-1;l++){
				a[i][j][1]+=(s[i][j][l]-'a'+1)*pw[l]%mod;
				a[i][j][1]%=mod;
			}
			for(int l=1;l<i;l++){
				a[i][j][2]+=(s[i][j][l]-'a'+1)*pw[l-1]%mod;
				a[i][j][2]%=mod;
			}
		}
	}
	for(int i=1;i<=k;i++)ans[1][i]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				if(a[i][j][1]==a[i-1][l][0]){
					ans[i][j]+=ans[i-1][l];
					ans[i][j]%=mod;
					//~ cout<<" :: "<<l<<" k ";
				}
				else if(a[i][j][2]==a[i-1][l][0]){
					ans[i][j]+=ans[i-1][l];
					ans[i][j]%=mod;
					//~ cout<<" :: "<<l<<" k2 ";
				}
			}
			//~ cout<<" ^ "<<ans[i][j]<<" ^ ";
		}
		//~ cout<<endl;
	}
	//~ cout<<endl;	
	int ANS=0;
	for(int i=1;i<=k;i++){
		ANS+=ans[n][i];
		ANS%=mod;
	}
	cout<<ANS<<endl;
}//a
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 5 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 3 ms 5200 KB Output is correct
7 Correct 5 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 5 ms 5212 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 5 ms 5212 KB Output is correct
12 Correct 89 ms 9548 KB Output is correct
13 Correct 90 ms 9560 KB Output is correct
14 Correct 89 ms 9552 KB Output is correct
15 Correct 94 ms 9540 KB Output is correct
16 Correct 402 ms 9632 KB Output is correct
17 Correct 98 ms 9564 KB Output is correct
18 Correct 111 ms 9632 KB Output is correct
19 Correct 100 ms 9556 KB Output is correct
20 Correct 98 ms 9552 KB Output is correct
21 Correct 98 ms 9552 KB Output is correct
22 Correct 410 ms 9808 KB Output is correct