답안 #253268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253268 2020-07-27T14:50:52 Z blacktulip Trener (COCI20_trener) C++17
110 / 110
321 ms 11140 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 1502;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,serc[52][li][5],dp[52][li];
int cev;
string s[52][li];
vector<int> v;

inline int mul(int x,int y){
	return (x%mod)*(y%mod)%mod;
}

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int f(int sira,int gecen){
	int cevv=0;
	if(sira>n)return 1;
	if(~dp[sira][gecen])return dp[sira][gecen];
	if(sira==1){
		for(int i=1;i<=k;i++){
			cevv=add(cevv,f(sira+1,i));
		}
	}
	else{
		for(int i=1;i<=k;i++){
			if(serc[sira-1][gecen][0]==serc[sira][i][1] || serc[sira-1][gecen][0]==serc[sira][i][2])cevv=add(cevv,f(sira+1,i));
		}
	}
	return dp[sira][gecen]=cevv;
}

main(void){
	fio();
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	FOR{
		for(int j=1;j<=k;j++)cin>>s[i][j];
	}
	FOR{
		for(int j=1;j<=k;j++){
			//~ int at=0;
			int carp=1;
			for(int jj=0;jj<i;jj++){
				serc[i][j][0]=add(serc[i][j][0],mul(carp,s[i][j][jj]-'a'));
				carp=mul(carp,37);
			}
			carp=1;
			for(int jj=0;jj<i-1;jj++){
				serc[i][j][1]=add(serc[i][j][1],mul(carp,s[i][j][jj]-'a'));
				carp=mul(carp,37);
			}
			carp=1;
			for(int jj=1;jj<i;jj++){
				serc[i][j][2]=add(serc[i][j][2],mul(carp,s[i][j][jj]-'a'));
				carp=mul(carp,37);
			}
		}
	}
	cout<<f(1,0)<<endl;
	return 0;
}

Compilation message

trener.cpp:56:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 17 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4096 KB Output is correct
2 Correct 8 ms 4096 KB Output is correct
3 Correct 11 ms 4096 KB Output is correct
4 Correct 9 ms 4096 KB Output is correct
5 Correct 8 ms 4160 KB Output is correct
6 Correct 8 ms 4096 KB Output is correct
7 Correct 8 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 17 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 9 ms 4096 KB Output is correct
6 Correct 8 ms 4096 KB Output is correct
7 Correct 11 ms 4096 KB Output is correct
8 Correct 9 ms 4096 KB Output is correct
9 Correct 8 ms 4160 KB Output is correct
10 Correct 8 ms 4096 KB Output is correct
11 Correct 8 ms 4096 KB Output is correct
12 Correct 209 ms 10956 KB Output is correct
13 Correct 208 ms 11000 KB Output is correct
14 Correct 200 ms 11000 KB Output is correct
15 Correct 204 ms 11128 KB Output is correct
16 Correct 301 ms 11000 KB Output is correct
17 Correct 227 ms 11076 KB Output is correct
18 Correct 230 ms 11140 KB Output is correct
19 Correct 226 ms 11000 KB Output is correct
20 Correct 230 ms 11004 KB Output is correct
21 Correct 230 ms 11072 KB Output is correct
22 Correct 321 ms 11000 KB Output is correct