Submission #845506

# Submission time Handle Problem Language Result Execution time Memory
845506 2023-09-06T13:55:40 Z vjudge1 Trener (COCI20_trener) C++11
0 / 110
4 ms 856 KB
#include <bits/stdc++.h>
#define lg(a) (31 - __builtin_clz((a)))
#define endl ("\n")
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define st first
#define nd second
#define all(aa) aa.begin(), aa.end()
#define rall(aa) aa.rbegin(), aa.rend()
#define forn(i, n) for(int i=0;i<n;i++)
#define trav(e, x) for(auto& e:x)
#define until(n, v) (int) (lower_bound(v.begin(), v.end(), n)-v.begin()) //# of elements < n
#define after(n, v) (int) (v.end()-upper_bound(v.begin(), v.end(), n))   //# of elements > n
#define sameas(n, v) (int) (upper_bound(v.begin(), v.end(), n) - lower_bound(v.begin(), v.end(), n)) //# of elements ==n
typedef long long ll;
const ll MOD = 1e9+7;
using namespace std;
/*

*/

map<string, int> dp;
vector<set<string>> v;

ll d(string s){
    if(dp.count(s)) return dp[s];
    // cout<<s<<endl;
    if(v[s.size()-1].count(s)==0) return 0;
    string left, right;
    for(int i=0;i<s.size()-1;i++){
        left.pb(s[i]);
    }
    for(int i=1;i<s.size();i++){
        right.pb(s[i]);
    }
    if(left==right) return dp[s] = (((d(right)%MOD))%MOD);
    return dp[s] = (((d(left)%MOD) + (d(right)%MOD))%MOD);
}


void solve(){
    int n, k; cin>>n>>k;
    v.resize(n);
    for(int i=0;i<n*k;i++){
        string a; cin>>a;
        v[a.size()-1].insert(a);
        if(a.size()==1) dp[a]=1;
    }
    ll ans=0;
    for(auto e : v[n-1]){
        ans = (ans+ d(e))%MOD;
    }
    cout<<ans<<endl;

}

int main(){
	int test; 
    // cin >> test;
    test =1;
   	while (test--){
		solve();
    }
}



Compilation message

trener.cpp: In function 'll d(std::string)':
trener.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0;i<s.size()-1;i++){
      |                 ~^~~~~~~~~~~
trener.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=1;i<s.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -