Submission #725727

# Submission time Handle Problem Language Result Execution time Memory
725727 2023-04-18T01:04:07 Z Cookie Selling RNA Strands (JOI16_selling_rna) C++14
0 / 100
236 ms 197464 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 1e5, mxm = 1e5;
int n, m, ans = 0;
string s[mxn + 1], t[mxn + 1];
int to[1005];
struct Node1{
    Node1 *nxt[4];
    int l = n + 1, r = -1;
    Node1(){
        for(int i = 0; i < 4; i++)nxt[i] = NULL;
    }
};
struct Node2{
    Node2 *nxt[4];
    vt<int>pos;
    Node2(){
        forr(i, 0, 4)nxt[i] = NULL;
    }
};
Node1 *root = new Node1();
Node2 *root2 = new Node2();

void add1(string s, int id){
    Node1 *nd = root;
    for(int i = 0; i < s.size(); i++){
        int c = to[s[i]];
        if(nd->nxt[c] == NULL){
            nd->nxt[c] = new Node1();
        }
        nd->nxt[c]->l = min(nd->nxt[c]->l, id); nd->nxt[c]->r = max(nd->nxt[c]->r, id);
        nd = nd->nxt[c];
    }
}
void add2(string s, int id){
    Node2 *nd = root2;
    for(int i = 0; i < s.size(); i++){
        int c = to[s[i]];
        if(nd->nxt[c] == NULL){
            nd->nxt[c] = new Node2();
        }
        nd->nxt[c]->pos.pb(id);
        nd = nd->nxt[c];
    }
}
pii get1(string s){
    Node1 *nd = root;
    for(int i = 0; i < s.size(); i++){
        int c = to[s[i]];
        if(nd->nxt[c] == NULL)return(make_pair(-1, -1));
        nd = nd->nxt[c];
    }
    return(make_pair(nd->l, nd->r));
    
}
int get2(string s, int l, int r){
    Node2 *nd = root2;
    for(int i = 0; i < s.size(); i++){
        int c = to[s[i]];
        if(nd->nxt[c] == NULL){
            return(0);
        }
        nd = nd->nxt[c];
    }
    vt<int>v = nd->pos;
    return(upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l));
}
signed main(){
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    forr(i, 0, n)cin >> s[i];
    to['A'] = 0; to['U'] = 1; to['C'] = 2; to['G'] = 3;
    sort(s, s + n);
    for(int i = 0; i < n; i++){
        
        add1(s[i], i);
        reverse(s[i].begin(), s[i].end());
        add2(s[i], i);
    }
    forr(i, 0, m){
        string p, q; cin >> p >> q;
        auto [l, r] = get1(p);
        
        cout << get2(q, l, r) << "\n";
        
    }
    return(0);
}

Compilation message

selling_rna.cpp: In function 'void add1(std::string, int)':
selling_rna.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
selling_rna.cpp:43:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |         int c = to[s[i]];
      |                        ^
selling_rna.cpp: In function 'void add2(std::string, int)':
selling_rna.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
selling_rna.cpp:54:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   54 |         int c = to[s[i]];
      |                        ^
selling_rna.cpp: In function 'std::pair<int, int> get1(std::string)':
selling_rna.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
selling_rna.cpp:65:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   65 |         int c = to[s[i]];
      |                        ^
selling_rna.cpp: In function 'int get2(std::string, int, int)':
selling_rna.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
selling_rna.cpp:75:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   75 |         int c = to[s[i]];
      |                        ^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:99:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   99 |         auto [l, r] = get1(p);
      |              ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 197464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 143 ms 7872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6592 KB Output isn't correct
2 Halted 0 ms 0 KB -