이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3+4;
const int mod = 1e9+7;
map<string,int> cnt,dp;
int n,k,ans;
int P(int a,int b){ return 1ll*a*b%mod;}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++) for (int j=0; j<k; j++){
string s,t1,t2; cin >> s;
if (i == 1) dp[s] = 1;
else { t1 = s.substr(0, i-1), t2 = s.substr(1, i-1);
if (dp.count(t1)) dp[s] = (dp[s] + P(dp[t1], cnt[t1]))%mod;
if (t1 != t2 && dp.count(t2)) dp[s] = (dp[s] + P(dp[t2], cnt[t2]))%mod;
}
cnt[s]++;
if (i == n) ans = (ans + dp[s])%mod;
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |