답안 #521519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521519 2022-02-02T10:22:22 Z tengiz05 Selling RNA Strands (JOI16_selling_rna) C++17
35 / 100
1500 ms 87748 KB
#include <bits/stdc++.h>

using i64 = long long;
constexpr i64 P = 1E9 + 7, M = 5;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<std::string> s(n);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }
    
    std::sort(s.begin(), s.end());
    
    std::vector<std::tuple<int, int, int>> Q;
    
    for (int i = 0; i < m; i++) {
        std::string p, q;
        std::cin >> p >> q;
        int l = std::lower_bound(s.begin(), s.end(), p) - s.begin();
        int r = std::upper_bound(s.begin(), s.end(), p + 'Z') - s.begin();
        i64 H = 0;
        for (char c : q) {
            H *= M;
            H += std::string("AGCU").find(c) + 1;
            H %= P;
        }
        Q.emplace_back(l, -H, i);
        Q.emplace_back(r, H, i);
    }
    
    std::sort(Q.begin(), Q.end());
    
    std::vector<int> ans(m);
    
    std::map<int, int> cnt;
    int j = 0;
    for (int i = 0; i < n; i++) {
        int p, H, id;
        while (j < int(Q.size())) {
            std::tie(p, H, id) = Q[j];
            if (p != i) {
                break;
            }
            if (H < 0) {
                ans[id] -= cnt[-H];
            } else {
                ans[id] += cnt[H];
            }
            j++;
        }
        i64 h = 0, pw = 1;
        for (int j = int(s[i].size()) - 1; j >= 0; j--) {
            h = (h + pw * (std::string("AGCU").find(s[i][j]) + 1)) % P;
            pw *= M;
            cnt[h]++;
        }
    }
    while (j < int(Q.size())) {
        int p, H, id;
        std::tie(p, H, id) = Q[j];
        if (H < 0) {
            ans[id] -= cnt[-H];
        } else {
            ans[id] += cnt[H];
        }
        j++;
    }
    
    for (int i = 0; i < m; i++) {
        std::cout << ans[i] << "\n";
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1581 ms 87748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 3896 KB Output is correct
2 Correct 32 ms 2740 KB Output is correct
3 Correct 49 ms 3612 KB Output is correct
4 Correct 31 ms 3388 KB Output is correct
5 Correct 33 ms 2536 KB Output is correct
6 Correct 43 ms 3600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Execution timed out 1581 ms 87748 KB Time limit exceeded
9 Halted 0 ms 0 KB -