Submission #233064

# Submission time Handle Problem Language Result Execution time Memory
233064 2020-05-19T05:55:04 Z triple_fault Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
684 ms 343684 KB
/* May 18 2020 */

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <random>
#include <iostream>
#include <string>

#define ll long long
#define ri string::reverse_iterator

using namespace std;

ll n, m;

struct trie {
    map<char, trie*> children;
    vector<ll> indexes;

    void insert(ri l, ri r, ll idx) {
        indexes.push_back(idx);
        if (l == r) return;

        char c = *l;
        if (children.find(c) == children.end()) 
            children[c] = new trie();
        children[c]->insert(next(l), r, idx);
    }

    ll cnt(ri l, ri r, ll tl, ll tr) {
        if (l == r) 
            return lower_bound(indexes.begin(), indexes.end(), tr) - 
                lower_bound(indexes.begin(), indexes.end(), tl);
        char c = *l;
        if (children.find(c) == children.end()) return 0;
        return children[c]->cnt(next(l), r, tl, tr);
    }
} main_trie;

int main(void) {
    scanf("%lld %lld", &n, &m);
    vector<string> vals(n);
    for (ll i = 0; i < n; ++i) cin >> vals[i];
    sort(vals.begin(), vals.end());

    for (ll i = 0; i < n; ++i)
        main_trie.insert(vals[i].rbegin(), vals[i].rend(), i);

    while (m --) {
        string x, y; cin >> x >> y;
        ll l = lower_bound(vals.begin(), vals.end(), x) - vals.begin();
        ++x.back();
        ll r = lower_bound(vals.begin(), vals.end(), x) - vals.begin();
        printf("%lld\n", main_trie.cnt(y.rbegin(), y.rend(), l, r));
    }
    return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 565 ms 343684 KB Output is correct
2 Correct 551 ms 327580 KB Output is correct
3 Correct 315 ms 29564 KB Output is correct
4 Correct 321 ms 29048 KB Output is correct
5 Correct 393 ms 214520 KB Output is correct
6 Correct 396 ms 217720 KB Output is correct
7 Correct 382 ms 24184 KB Output is correct
8 Correct 571 ms 143864 KB Output is correct
9 Correct 538 ms 125304 KB Output is correct
10 Correct 345 ms 118264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 4204 KB Output is correct
2 Correct 116 ms 3704 KB Output is correct
3 Correct 142 ms 3956 KB Output is correct
4 Correct 121 ms 3312 KB Output is correct
5 Correct 121 ms 3188 KB Output is correct
6 Correct 153 ms 3568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 565 ms 343684 KB Output is correct
9 Correct 551 ms 327580 KB Output is correct
10 Correct 315 ms 29564 KB Output is correct
11 Correct 321 ms 29048 KB Output is correct
12 Correct 393 ms 214520 KB Output is correct
13 Correct 396 ms 217720 KB Output is correct
14 Correct 382 ms 24184 KB Output is correct
15 Correct 571 ms 143864 KB Output is correct
16 Correct 538 ms 125304 KB Output is correct
17 Correct 345 ms 118264 KB Output is correct
18 Correct 173 ms 4204 KB Output is correct
19 Correct 116 ms 3704 KB Output is correct
20 Correct 142 ms 3956 KB Output is correct
21 Correct 121 ms 3312 KB Output is correct
22 Correct 121 ms 3188 KB Output is correct
23 Correct 153 ms 3568 KB Output is correct
24 Correct 594 ms 285056 KB Output is correct
25 Correct 677 ms 285304 KB Output is correct
26 Correct 551 ms 281720 KB Output is correct
27 Correct 391 ms 28664 KB Output is correct
28 Correct 684 ms 65772 KB Output is correct
29 Correct 510 ms 17380 KB Output is correct