Submission #253268

#TimeUsernameProblemLanguageResultExecution timeMemory
253268blacktulipTrener (COCI20_trener)C++17
110 / 110
321 ms11140 KiB
#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 (stderr)

trener.cpp:56:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...