Submission #112165

# Submission time Handle Problem Language Result Execution time Memory
112165 2019-05-17T16:24:50 Z Frankenween Marko (COCI15_marko) C++17
50 / 50
7 ms 896 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define ull unsigned long long
#define pll pair<ll, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define ld long double
const ll mod1 = (ll)1e9 + 7;
const ll mod2 = (ll)1e9 + 9;
const ll BASE = 47;
const ll inf = (ll)1e18;
const long double e = 2.718281828459;
const long double pi = 3.141592653;
const ld EPS = 1e-9;


using namespace std;


template <class T>
istream& operator>>(istream &in, vector<T> &arr) {
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};


ll get(char c) {
    if (c <= 'c') {
        return 2;
    }
    if (c <= 'f') {
        return 3;
    }
    if (c <= 'i') {
        return 4;
    }
    if (c <= 'l') {
        return 5;
    }
    if (c <= 'o') {
        return 6;
    }
    if (c <= 's') {
        return 7;
    }
    if (c <= 'v') {
        return 8;
    }
    return 9;
}


void solve() {
    ll n;
    cin >> n;
    map<ll, ll> h;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        ll hash = 0;
        for (auto c : s) {
            hash = (hash * BASE + get(c)) % mod1;
        }
        h[hash]++;
    }
    string s;
    cin >> s;
    ll cnt = 0;
    for (auto c : s) {
        cnt = (cnt * BASE + c - '0') % mod1;
    }
    cout << h[cnt];
}


int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout.precision(30);
    ll seed = time(0);
    //cerr << "Seed: " << seed << "\n";
    srand(seed);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 7 ms 896 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 5 ms 768 KB Output is correct