답안 #845544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845544 2023-09-06T14:04:27 Z vjudge1 Trener (COCI20_trener) C++11
0 / 110
7 ms 1664 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, ll> dp;
map<string, int> cnt;
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] = ((cnt[left]%MOD)*((d(right)%MOD))%MOD);
    return dp[s] = (((cnt[left]%MOD)*(d(left)%MOD) + (cnt[right]%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;
        cnt[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:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0;i<s.size()-1;i++){
      |                 ~^~~~~~~~~~~
trener.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=1;i<s.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1628 KB Output is correct
2 Correct 7 ms 1664 KB Output is correct
3 Correct 7 ms 1624 KB Output is correct
4 Incorrect 5 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -