Submission #845545

#TimeUsernameProblemLanguageResultExecution timeMemory
845545vjudge1Trener (COCI20_trener)C++17
55 / 110
2021 ms7256 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define pb push_back #define endl '\n' #define fi first #define se second #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define CDIV(a,b) (((a)+(b)-(1))/(b)) const ll inf = 1e17 + 5; const ll mod = 1e9 + 7; const ll N = 1e3 + 30; ll mod_(ll a, ll b) { if(a >= 0)return a % b; a += (-a/b + 1) * b; return a % b; } void solve() { ll n, k; cin >> n >> k; vector<vector<string> >v(n, vector<string>(k)); for(ll i = 0; i < n; ++i) { for(ll j = 0; j < k; ++j) cin >> v[i][j]; } vector<vector<ll> >dp(n, vector<ll>(k)); for(ll i = k - 1; i >= 0; --i)dp[n - 1][i] = 1; for(ll i = n - 1; i >= 1; --i) { for(ll j = 0; j < k; ++j) { for(ll z = 0; z < k; ++z) { if(v[i - 1][z] == string{v[i][j].begin(), v[i][j].end() - 1}) { dp[i - 1][z] += dp[i][j]; if(dp[i - 1][z] >= mod)dp[i - 1][z] %= mod; } else if(v[i - 1][z] == string{v[i][j].begin() + 1, v[i][j].end()}) { dp[i - 1][z] += dp[i][j]; if(dp[i - 1][z] >= mod)dp[i - 1][z] %= mod; } } } } ll ans = 0; for(ll i = 0; i < k; ++i) ans = (ans + dp[0][i]) % mod; cout << ans << endl; } int main() { fio; //ll t; cin >> t; while(t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...