답안 #856975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856975 2023-10-05T03:01:58 Z TS_2392 Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
150 ms 205820 KB
#include <bits/stdc++.h>

using namespace std;

#define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define SPEED         ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a)        a.begin(), a.end()
#define lwb           lower_bound
#define upb           upper_bound
#define sz(a)         (int) a.size()
#define eb            emplace_back

const int N = 2e6 + 10;
vector <int> through[N];
int trie[2][4][N], L[N], R[N];
int n, m, trie_sz[2];
string s[N];
int trans(char c){
	if(c == 'A') return 0;
	if(c == 'U') return 1;
	if(c == 'G') return 2;
	if(c == 'C') return 3;
}
void add_str(string & s, int j, int t, bool is_reverse = 0){
    int v = 1;
    for (int i = 0; i < sz(s); i++){
        int c = trans(s[is_reverse ? sz(s) - 1 - i : i]);
        if (!trie[t][c][v]) trie[t][c][v] = trie_sz[t]++;
        v = trie[t][c][v];
        if (t == 0){
            if (L[v] == 0) L[v] = j;
            R[v] = max(R[v], j);
        }
        else through[v].eb(j);
    }
}
int query(string & s, int t, bool is_reverse = 0){
    int v = 1;
    for (int i = 0; i < sz(s); i++) {
        int c = trans(s[is_reverse ? sz(s) - 1 - i : i]);
        v = trie[t][c][v];
        if (v == 0) return 0;
    }
    return v;
}

int main(){
    SPEED; fileIO("rna");
    cin >> n >> m;
    trie_sz[0] = trie_sz[1] = 2;
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s, s + n);
    for (int i = 0; i < n; i++){
        add_str(s[i], i + 1, 0);
        add_str(s[i], i + 1, 1, 1);
    }
    for (int i = 0; i < m; i++){
        string s, t; cin >> s >> t;
        int I = query(s, 0), I2 = query(t, 1, 1);
        int p1 = lwb(all(through[I2]), L[I]) - through[I2].begin();
        int p2 = upb(all(through[I2]), R[I]) - through[I2].begin();
        cout << max(0, p2 - p1) << '\n';
    }
    return 0;
}

Compilation message

selling_rna.cpp: In function 'int trans(char)':
selling_rna.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
   23 | }
      | ^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:5:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:48:12: note: in expansion of macro 'fileIO'
   48 |     SPEED; fileIO("rna");
      |            ^~~~~~
selling_rna.cpp:5:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileIO(name)  if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:48:12: note: in expansion of macro 'fileIO'
   48 |     SPEED; fileIO("rna");
      |            ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 112476 KB Output is correct
2 Correct 26 ms 112476 KB Output is correct
3 Correct 24 ms 112328 KB Output is correct
4 Correct 23 ms 112472 KB Output is correct
5 Correct 23 ms 112476 KB Output is correct
6 Correct 27 ms 112472 KB Output is correct
7 Correct 24 ms 112472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 205820 KB Output is correct
2 Correct 146 ms 201408 KB Output is correct
3 Correct 76 ms 169956 KB Output is correct
4 Correct 75 ms 167508 KB Output is correct
5 Correct 126 ms 198228 KB Output is correct
6 Correct 139 ms 199500 KB Output is correct
7 Correct 50 ms 122460 KB Output is correct
8 Correct 121 ms 156752 KB Output is correct
9 Correct 105 ms 157520 KB Output is correct
10 Correct 91 ms 155984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 113232 KB Output is correct
2 Correct 36 ms 113244 KB Output is correct
3 Correct 43 ms 113232 KB Output is correct
4 Correct 38 ms 112976 KB Output is correct
5 Correct 36 ms 113236 KB Output is correct
6 Correct 40 ms 113244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 112476 KB Output is correct
2 Correct 26 ms 112476 KB Output is correct
3 Correct 24 ms 112328 KB Output is correct
4 Correct 23 ms 112472 KB Output is correct
5 Correct 23 ms 112476 KB Output is correct
6 Correct 27 ms 112472 KB Output is correct
7 Correct 24 ms 112472 KB Output is correct
8 Correct 141 ms 205820 KB Output is correct
9 Correct 146 ms 201408 KB Output is correct
10 Correct 76 ms 169956 KB Output is correct
11 Correct 75 ms 167508 KB Output is correct
12 Correct 126 ms 198228 KB Output is correct
13 Correct 139 ms 199500 KB Output is correct
14 Correct 50 ms 122460 KB Output is correct
15 Correct 121 ms 156752 KB Output is correct
16 Correct 105 ms 157520 KB Output is correct
17 Correct 91 ms 155984 KB Output is correct
18 Correct 39 ms 113232 KB Output is correct
19 Correct 36 ms 113244 KB Output is correct
20 Correct 43 ms 113232 KB Output is correct
21 Correct 38 ms 112976 KB Output is correct
22 Correct 36 ms 113236 KB Output is correct
23 Correct 40 ms 113244 KB Output is correct
24 Correct 146 ms 190088 KB Output is correct
25 Correct 150 ms 190308 KB Output is correct
26 Correct 137 ms 189172 KB Output is correct
27 Correct 81 ms 160848 KB Output is correct
28 Correct 146 ms 133464 KB Output is correct
29 Correct 87 ms 117616 KB Output is correct