Submission #876906

# Submission time Handle Problem Language Result Execution time Memory
876906 2023-11-22T13:26:23 Z resfast Selling RNA Strands (JOI16_selling_rna) C++17
60 / 100
1500 ms 8800 KB
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

#define islam_zymchybekov void solve()
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define int long long

islam_zymchybekov{
    ios;
    int n, m;
    cin >> n >> m;

    if (n < 5001) {
        vector<string> v(n);
        for (int i = 0; i < n; ++i)
            cin >> v[i];

        for (int i = 0; i < m; ++i) {
            string s, s1;
            cin >> s >> s1;
            int ans = 0;
            int len_s = s.size();
            int len_s1 = s1.size();

            for (int j = 0; j < n; ++j) {
                if (v[j].size() >= max(len_s, len_s1)) {
                    if (v[j].substr(0, len_s) == s && v[j].substr(v[j].size() - len_s1) == s1) {
                        ++ans;
                    }
                }
            }
            cout << ans << '\n';
        }
    } else {
        unordered_map<string, int> mp;

        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            mp[s]++;
        }

        for (int i = 0; i < m; ++i) {
            string s, s1;
            cin >> s >> s1;
            int ans = 0;
            int len_s = s.size();
            int len_s1 = s1.size();

            for (auto &it : mp) {
                string curr = it.first;
                int len_curr = curr.size();

                if (len_curr >= max(len_s, len_s1)) {
                    if (curr.substr(0, len_s) == s && curr.substr(len_curr - len_s1) == s1) {
                        ans += it.second;
                    }
                }
            }
            cout << ans << '\n';
        }
    }
    cout << flush;
}

int32_t main() {
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}

Compilation message

selling_rna.cpp: In function 'void solve()':
selling_rna.cpp:31:33: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'const long long int' [-Wsign-compare]
   31 |                 if (v[j].size() >= max(len_s, len_s1)) {
      |                     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 6480 KB Output is correct
2 Correct 579 ms 6452 KB Output is correct
3 Correct 166 ms 6484 KB Output is correct
4 Correct 224 ms 6484 KB Output is correct
5 Correct 532 ms 4296 KB Output is correct
6 Correct 520 ms 4232 KB Output is correct
7 Correct 419 ms 7584 KB Output is correct
8 Correct 1116 ms 8560 KB Output is correct
9 Correct 932 ms 8800 KB Output is correct
10 Correct 1447 ms 5856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1116 KB Output is correct
2 Correct 753 ms 860 KB Output is correct
3 Correct 704 ms 1020 KB Output is correct
4 Correct 12 ms 860 KB Output is correct
5 Correct 553 ms 856 KB Output is correct
6 Correct 548 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 126 ms 6480 KB Output is correct
9 Correct 579 ms 6452 KB Output is correct
10 Correct 166 ms 6484 KB Output is correct
11 Correct 224 ms 6484 KB Output is correct
12 Correct 532 ms 4296 KB Output is correct
13 Correct 520 ms 4232 KB Output is correct
14 Correct 419 ms 7584 KB Output is correct
15 Correct 1116 ms 8560 KB Output is correct
16 Correct 932 ms 8800 KB Output is correct
17 Correct 1447 ms 5856 KB Output is correct
18 Correct 15 ms 1116 KB Output is correct
19 Correct 753 ms 860 KB Output is correct
20 Correct 704 ms 1020 KB Output is correct
21 Correct 12 ms 860 KB Output is correct
22 Correct 553 ms 856 KB Output is correct
23 Correct 548 ms 1228 KB Output is correct
24 Execution timed out 1526 ms 5188 KB Time limit exceeded
25 Halted 0 ms 0 KB -