답안 #866753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866753 2023-10-27T02:18:18 Z tradz Selling RNA Strands (JOI16_selling_rna) C++14
35 / 100
230 ms 356432 KB
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for (int i = a; i <= b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define TASK ""
#define fi first
#define se second
#define iii pair<ii, int>
const int N = 1e6 + 7;
const int oo = 1e18;

typedef pair<int, int> ii;
int n, m, tim[3];
string s[100010];
struct data {
    int child[27], in, ou;
};
vector<int> c[N];
data a[N], b[N];

void update(int w) {
    string sa = s[w];
    int u = 0;
    for (int i = 0; i < sa.size(); i++) {
        if (a[u].child[sa[i] - 'A' + 1] == 0) {
            a[u].child[sa[i] - 'A' + 1] = ++tim[1];
            a[tim[1]].in = w;
        }
        u = a[u].child[sa[i] - 'A' + 1];
        a[u].ou = w;
    }
    u = 0;
    for (int i = sa.size() - 1; i >= 0; i--) {
        if (b[u].child[sa[i] - 'A' + 1] == 0) {
            b[u].child[sa[i] - 'A' + 1] = ++tim[2];
        }
        u = b[u].child[sa[i] - 'A' + 1];

        c[u].push_back(w);
    }
}

void get(string sa, string sb) {
    int u = 0, ua = 0;
    for (int i = 0; i < sa.size(); i++) {
        if (a[u].child[sa[i] - 'A' + 1]== 0) {
            cout << "0\n";
            return;
        }
        u = a[u].child[sa[i] - 'A' + 1];
    }

    for (int i = sb.size() - 1; i >= 0; i--) {
        if (b[ua].child[sb[i] - 'A' + 1] == 0) {
            cout << "0\n";
            return;
        }
        ua = b[ua].child[sb[i] - 'A' + 1];
    }

    c[ua].push_back(1000000);
    int w = lower_bound(c[ua].begin(), c[ua].end(), a[u].in) - c[ua].begin();
    int wa = upper_bound(c[ua].begin(), c[ua].end(), a[u].ou) - c[ua].begin();
    wa--;

    if (w > wa) {
        cout << "0\n";
        return;
    }
    cout << wa - w + 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> m;

    For(i, 1, n) {
        cin >> s[i];
    }

    sort(s + 1, s + n + 1);

    For(i, 1, n) {
        update(i);
    }

    For(i, 1, m) {
        cin >> s[1] >> s[2];
        get(s[1], s[2]);
    }

    return 0;
}

Compilation message

selling_rna.cpp:11:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   11 | const int oo = 1e18;
      |                ^~~~
selling_rna.cpp: In function 'void update(int)':
selling_rna.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < sa.size(); i++) {
      |                     ~~^~~~~~~~~~~
selling_rna.cpp: In function 'void get(std::string, std::string)':
selling_rna.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < sa.size(); i++) {
      |                     ~~^~~~~~~~~~~
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 27996 KB Output is correct
2 Correct 6 ms 28188 KB Output is correct
3 Correct 6 ms 27996 KB Output is correct
4 Correct 6 ms 28132 KB Output is correct
5 Correct 6 ms 27996 KB Output is correct
6 Correct 6 ms 27996 KB Output is correct
7 Correct 6 ms 28188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 230 ms 356432 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 29132 KB Output is correct
2 Correct 24 ms 29532 KB Output is correct
3 Correct 25 ms 29276 KB Output is correct
4 Correct 19 ms 29020 KB Output is correct
5 Correct 23 ms 29560 KB Output is correct
6 Correct 27 ms 29408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 27996 KB Output is correct
2 Correct 6 ms 28188 KB Output is correct
3 Correct 6 ms 27996 KB Output is correct
4 Correct 6 ms 28132 KB Output is correct
5 Correct 6 ms 27996 KB Output is correct
6 Correct 6 ms 27996 KB Output is correct
7 Correct 6 ms 28188 KB Output is correct
8 Runtime error 230 ms 356432 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -