제출 #845275

#제출 시각아이디문제언어결과실행 시간메모리
845275vjudge1Trener (COCI20_trener)C++17
110 / 110
472 ms27176 KiB
#include <bits/stdc++.h> #define endl "\n" #define pb push_back #define int long long using namespace std; const int inf = 2e18 + 5; const int N = 5e3 + 5; const int mod = 1e9 + 7; int32_t main(){ //freopen("in.txt","r", stdin); int n, k; cin>>n>>k; vector<vector<string> > a(n, vector<string>(k)); map<string, vector<int> > mp; for(int i = 0; i < n; i++){ for(int j = 0; j < k; j++){ cin>>a[i][j]; mp[a[i][j]].pb(j); } } vector<vector<int> > dp(n+1, vector<int>(k)); for(int i = 0; i < k; i++){ dp[0][i] = 1; } for(int i = 0; i < n-1; i++){ for(int j = 0; j < k; j++){ string s1 = a[i+1][j].substr(0, a[i+1][j].size()-1); string s2 = a[i+1][j].substr(1, a[i+1][j].size()-1); for(auto itr: mp[s1]){ dp[i+1][j] = (dp[i+1][j] + dp[i][itr])%mod; //cout<<s1<<" "<<itr<<endl; } if(s1 == s2) continue; for(auto itr: mp[s2]){ dp[i+1][j] = (dp[i+1][j] + dp[i][itr])%mod; //cout<<s2<<" "<<itr<<endl; } } } int s = 0; for(int i = 0; i < k; i++){ s = (s + dp[n-1][i])%mod; } cout<<s<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...