답안 #1088198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088198 2024-09-14T05:56:26 Z coldbr3w Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
577 ms 371796 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<long long, long long>;
 
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()
 
const ll N = 2e6 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 520;
const ll base = 35711;
struct Trie{
    struct node{
        ll c[4];
        ll l, r;
        vector<ll>range;
    }; node x[N];
    ll cur;
    Trie() : cur(0){
        memset(x[0].c, -1, sizeof(x[0].c));
        x[0].l = inf;
        x[0].r = -inf;
    }
    ll init(){
        cur++;
        memset(x[cur].c, -1, sizeof(x[cur].c));
        x[cur].l = inf, x[cur].r = -inf;
        return cur;
    }  
    void add(string s, ll idx){
        ll pos = 0;
        for(auto f : s){
            ll c = f - 'A';
            if(x[pos].c[c] == -1) x[pos].c[c] = init();
            pos = x[pos].c[c];
            x[pos].range.pb(idx);
            x[pos].l = min(idx, x[pos].l);
            x[pos].r = max(idx, x[pos].r);
        }
    }
    pll find_range(string s){
        ll pos = 0;
        for(auto f : s){
            ll c = f - 'A';
            pos = x[pos].c[c];
            if(pos == -1) return {inf, -inf};
        }
        return {x[pos].l, x[pos].r};
    }
    vector<ll>dfs(string s){
        ll pos = 0;
        vector<ll>tmp;
        for(auto f : s){
            ll c = f - 'A';
            pos = x[pos].c[c];
            if(pos == -1) return tmp;
        }
        return x[pos].range;
    }
};
string cnv(string s){
    string ans = s;
    for(int i = 0; i < ans.size();i++){
        if(ans[i] == 'C') ans[i] = 'B';
        else if(ans[i] == 'G') ans[i] = 'C';
        else if(ans[i] == 'U') ans[i] = 'D'; 
    }
    return ans;
}
Trie rev, tr;
void to_nho_cau(){
    ll n,m; cin >> n >> m;
    vector<string>v;
    for(int i = 1; i <= n;i++){
        string s; cin >> s;
        s = cnv(s);
        v.pb(s);
    }
    sort(all(v));
    for(int i = 0; i < v.size();i++){
        tr.add(v[i], i);
        string t = v[i]; reverse(all(t));
        rev.add(t, i);
    }
    while(m--){
        string p,q; cin >> p >> q;
        p = cnv(p), q = cnv(q);    
        reverse(all(q));
        pll cur = tr.find_range(p);
        ll l = cur.F, r = cur.S;
        vector<ll>res = rev.dfs(q);
        if(!res.size() || l > r){
            cout << 0 << '\n';
            continue;
        }
        ll high = upper_bound(all(res), r) - res.begin();
        ll low = lower_bound(all(res), l) - res.begin();
        cout << high - low << '\n';
    }
}
 
signed main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;   
    //cin >> t;
    while(t--) to_nho_cau();
}

Compilation message

selling_rna.cpp: In function 'std::string cnv(std::string)':
selling_rna.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0; i < ans.size();i++){
      |                    ~~^~~~~~~~~~~~
selling_rna.cpp: In function 'void to_nho_cau()':
selling_rna.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int i = 0; i < v.size();i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 282192 KB Output is correct
2 Correct 121 ms 282196 KB Output is correct
3 Correct 103 ms 282192 KB Output is correct
4 Correct 108 ms 282192 KB Output is correct
5 Correct 108 ms 282412 KB Output is correct
6 Correct 108 ms 282064 KB Output is correct
7 Correct 130 ms 282256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 371796 KB Output is correct
2 Correct 265 ms 366904 KB Output is correct
3 Correct 259 ms 369744 KB Output is correct
4 Correct 274 ms 366196 KB Output is correct
5 Correct 266 ms 362780 KB Output is correct
6 Correct 253 ms 363992 KB Output is correct
7 Correct 180 ms 320848 KB Output is correct
8 Correct 280 ms 360396 KB Output is correct
9 Correct 303 ms 352964 KB Output is correct
10 Correct 230 ms 349392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 287172 KB Output is correct
2 Correct 144 ms 285828 KB Output is correct
3 Correct 163 ms 285932 KB Output is correct
4 Correct 216 ms 285896 KB Output is correct
5 Correct 577 ms 285908 KB Output is correct
6 Correct 425 ms 286180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 282192 KB Output is correct
2 Correct 121 ms 282196 KB Output is correct
3 Correct 103 ms 282192 KB Output is correct
4 Correct 108 ms 282192 KB Output is correct
5 Correct 108 ms 282412 KB Output is correct
6 Correct 108 ms 282064 KB Output is correct
7 Correct 130 ms 282256 KB Output is correct
8 Correct 253 ms 371796 KB Output is correct
9 Correct 265 ms 366904 KB Output is correct
10 Correct 259 ms 369744 KB Output is correct
11 Correct 274 ms 366196 KB Output is correct
12 Correct 266 ms 362780 KB Output is correct
13 Correct 253 ms 363992 KB Output is correct
14 Correct 180 ms 320848 KB Output is correct
15 Correct 280 ms 360396 KB Output is correct
16 Correct 303 ms 352964 KB Output is correct
17 Correct 230 ms 349392 KB Output is correct
18 Correct 378 ms 287172 KB Output is correct
19 Correct 144 ms 285828 KB Output is correct
20 Correct 163 ms 285932 KB Output is correct
21 Correct 216 ms 285896 KB Output is correct
22 Correct 577 ms 285908 KB Output is correct
23 Correct 425 ms 286180 KB Output is correct
24 Correct 324 ms 359368 KB Output is correct
25 Correct 284 ms 359884 KB Output is correct
26 Correct 258 ms 358852 KB Output is correct
27 Correct 296 ms 358420 KB Output is correct
28 Correct 571 ms 335028 KB Output is correct
29 Correct 260 ms 307900 KB Output is correct