Submission #735060

# Submission time Handle Problem Language Result Execution time Memory
735060 2023-05-03T12:49:31 Z MisterReaper Trener (COCI20_trener) C++17
0 / 110
9 ms 1748 KB
// author: MisterReaper (Ahmet Alp Orakci)
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MOD = 1e9 + 7;

#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    #include "debug.h"
    #define OPEN freopen(".in", "r", stdin); freopen(".out", "w", stdout);
    #define TIME cerr << "\n" << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds ";
#else
    #define debug(...) void(23)
    #define OPEN void(0000)
    #define TIME void(232323233)
#endif

void solve()
{
    int n, k; cin >> n >> k;
    vector <vector <string>> arr(n +1, vector <string> (k +1));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= k; j++) cin >> arr[i][j];
    }

    map <string, int> mp;
    sort(arr[1].begin(), arr[1].end());
    arr[1].erase(unique(arr[1].begin(), arr[1].end()), arr[1].end());
    k = arr[1].size();
    for(int i = 1; i < k; i++) mp[arr[1][i]]++;

    for(int i = 2; i <= n; i++)
    {
        sort(arr[i].begin(), arr[i].end());
        arr[i].erase(unique(arr[i].begin(), arr[i].end()), arr[i].end());
        k = arr[i].size();
        for(int j = 1; j < k; j++)
        {
            string f, s = arr[i][j]; 
            for(int l = 2; l <= i; l++) f += arr[i][j][l -1];
            s.pop_back();

            mp[arr[i][j]] += mp[f] + (f != s ? mp[s] : 0);
            mp[arr[i][j]] %= MOD;
            debug(arr[i][j], mp[arr[i][j]]);
        }
    }

    int ans = 0;
    k = arr[n].size();
    for(int i = 1; i < k; i++)
    {
        ans += mp[arr[n][i]];
        ans %= MOD;
    }

    cout << ans << "\n";
    
    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

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

    TIME;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -