Submission #659054

# Submission time Handle Problem Language Result Execution time Memory
659054 2022-11-16T08:49:03 Z iloveroseanne Trener (COCI20_trener) C++14
110 / 110
83 ms 2796 KB
// Author: Ngo Ba Van
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
using ii=pair<ll,ll>;
const ll N=1e3+5,M=1e9+7;
ll n,res,dp[N][N],k;
map<string,ll>m[2];
string s;
void nhap()
{
    cin>>n>>k; int a=0,b=1;
    m[0][""]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=k;j++)
        {
            res=0;
            cin>>s; string t1,t2;
            t1=s.substr(0,s.size()-1);
            t2=s.substr(1,s.size()-1);
            if (m[a].count(t1)) res=(res+m[a][t1])%M;
            if (t1!=t2)
            {
                if (m[a].count(t2)) res=(res+m[a][t2])%M;
            }
            m[b][s]=(m[b][s]+res)%M;
        }
        swap(a,b);
        m[b].clear();
    }
    res=0;
    for (auto i:m[a])
    res=(res+i.se)%M;
    cout<<res%M;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "a"
//define task ""
int t=1;
//cin>>t;
while (t--)
nhap();
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
3 Correct 4 ms 372 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 356 KB Output is correct
7 Correct 4 ms 372 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 78 ms 2736 KB Output is correct
13 Correct 79 ms 2796 KB Output is correct
14 Correct 83 ms 2708 KB Output is correct
15 Correct 78 ms 2704 KB Output is correct
16 Correct 16 ms 2252 KB Output is correct
17 Correct 72 ms 2632 KB Output is correct
18 Correct 73 ms 2528 KB Output is correct
19 Correct 71 ms 2636 KB Output is correct
20 Correct 73 ms 2612 KB Output is correct
21 Correct 73 ms 2608 KB Output is correct
22 Correct 17 ms 2252 KB Output is correct