Submission #856969

# Submission time Handle Problem Language Result Execution time Memory
856969 2023-10-05T02:53:16 Z TS_2392 Selling RNA Strands (JOI16_selling_rna) C++14
0 / 100
160 ms 206736 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], alphabet = "ACGT";
void add_str(string & s, int j, int t, bool r = 0){
    int v = 1;
    for (int i = 0; i < sz(s); i++){
        char u = s[r ? sz(s) - 1 - i : i];
        int c = alphabet.find(u);
        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 r = 0){
    int v = 1;
    for (int i = 0; i < sz(s); i++) {
        char u = s[r ? sz(s) - 1 - i : i];
        int c = alphabet.find(u);
        v = trie[t][c][v];
        if (!v) 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 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:44:12: note: in expansion of macro 'fileIO'
   44 |     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:44:12: note: in expansion of macro 'fileIO'
   44 |     SPEED; fileIO("rna");
      |            ^~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 112220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 206736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 113232 KB Output is correct
2 Correct 40 ms 113308 KB Output is correct
3 Correct 41 ms 113308 KB Output is correct
4 Correct 38 ms 112984 KB Output is correct
5 Incorrect 38 ms 113244 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 112220 KB Output isn't correct
2 Halted 0 ms 0 KB -