답안 #423089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423089 2021-06-10T17:16:57 Z doowey Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
403 ms 238360 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 10;
const int L = (int)2e6 + 100;

vector<int> LEF[L];
vector<int> RIG[L];
int lef[L][4];
int rig[L][4];

int main(){
    fastIO;
    //freopen("in.txt","r",stdin);
    for(int i = 0 ; i < L; i ++ ){
        for(int j = 0 ; j < 4; j ++ ){
            lef[i][j]=-1;
            rig[i][j]=-1;
        }
    }
    int ca = 0, cb = 0;
    int n, m;
    cin >> n >> m;
    string ss[n];
    for(int i = 0 ; i < n; i ++ ){
        cin >> ss[i];
    }
    sort(ss, ss + n);
    string s;
    int cur;
    map<char, int> match;
    match['A'] = 0;
    match['G'] = 1;
    match['C'] = 2;
    match['U'] = 3;
    int id;
    for(int i = 0; i < n; i ++ ){
        s = ss[i];
        cur = 0;
        for(auto x : s){
            id = match[x];
            if(lef[cur][id] == -1){
                ca ++ ;
                lef[cur][id] = ca;
            }
            cur = lef[cur][id];
            LEF[cur].push_back(i);
        }
        cur = 0;
        for(int j = s.size() - 1; j >= 0 ; j -- ){
            id = match[s[j]];
            if(rig[cur][id] == -1){
                cb ++ ;
                rig[cur][id] = cb;
            }
            cur = rig[cur][id];
            RIG[cur].push_back(i);
        }
    }
    string pi, qi;
    int lli = 0, rri = 0;
    map<pii, int> res;
    int cnt;
    int low, high;
    int i1, i2;
    for(int iq = 1; iq <= m ; iq ++ ){
        cin >> pi >> qi;
        reverse(qi.begin(), qi.end());
        lli = rri = 0;
        for(auto x : pi){
            id = match[x];
            if(lef[lli][id] == -1){
                lli = -1;
                break;
            }
            lli = lef[lli][id];
        }
        for(auto x : qi){
            id = match[x];
            if(rig[rri][id] == -1){
                rri = -1;
                break;
            }
            rri = rig[rri][id];
        }
        if(lli == -1 || rri == -1){
            cout << "0\n";
            continue;
        }
        low = LEF[lli][0];
        high = LEF[lli].back();
        i1 = lower_bound(RIG[rri].begin(), RIG[rri].end(), low) - RIG[rri].begin();
        i2 = lower_bound(RIG[rri].begin(), RIG[rri].end(), high + 1) - RIG[rri].begin();
        cout << i2 - i1 << "\n";
    }
    return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:72:9: warning: unused variable 'cnt' [-Wunused-variable]
   72 |     int cnt;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 156868 KB Output is correct
2 Correct 97 ms 156860 KB Output is correct
3 Correct 93 ms 156824 KB Output is correct
4 Correct 93 ms 156868 KB Output is correct
5 Correct 83 ms 156788 KB Output is correct
6 Correct 94 ms 156808 KB Output is correct
7 Correct 85 ms 156756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 403 ms 233140 KB Output is correct
2 Correct 344 ms 231872 KB Output is correct
3 Correct 371 ms 234708 KB Output is correct
4 Correct 315 ms 231376 KB Output is correct
5 Correct 353 ms 237204 KB Output is correct
6 Correct 341 ms 238360 KB Output is correct
7 Correct 180 ms 180656 KB Output is correct
8 Correct 372 ms 221636 KB Output is correct
9 Correct 303 ms 213340 KB Output is correct
10 Correct 297 ms 210328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 160212 KB Output is correct
2 Correct 122 ms 159368 KB Output is correct
3 Correct 110 ms 159800 KB Output is correct
4 Correct 108 ms 159640 KB Output is correct
5 Correct 132 ms 159300 KB Output is correct
6 Correct 112 ms 159664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 156868 KB Output is correct
2 Correct 97 ms 156860 KB Output is correct
3 Correct 93 ms 156824 KB Output is correct
4 Correct 93 ms 156868 KB Output is correct
5 Correct 83 ms 156788 KB Output is correct
6 Correct 94 ms 156808 KB Output is correct
7 Correct 85 ms 156756 KB Output is correct
8 Correct 403 ms 233140 KB Output is correct
9 Correct 344 ms 231872 KB Output is correct
10 Correct 371 ms 234708 KB Output is correct
11 Correct 315 ms 231376 KB Output is correct
12 Correct 353 ms 237204 KB Output is correct
13 Correct 341 ms 238360 KB Output is correct
14 Correct 180 ms 180656 KB Output is correct
15 Correct 372 ms 221636 KB Output is correct
16 Correct 303 ms 213340 KB Output is correct
17 Correct 297 ms 210328 KB Output is correct
18 Correct 117 ms 160212 KB Output is correct
19 Correct 122 ms 159368 KB Output is correct
20 Correct 110 ms 159800 KB Output is correct
21 Correct 108 ms 159640 KB Output is correct
22 Correct 132 ms 159300 KB Output is correct
23 Correct 112 ms 159664 KB Output is correct
24 Correct 360 ms 223888 KB Output is correct
25 Correct 352 ms 224100 KB Output is correct
26 Correct 341 ms 223328 KB Output is correct
27 Correct 328 ms 223028 KB Output is correct
28 Correct 317 ms 190764 KB Output is correct
29 Correct 200 ms 173024 KB Output is correct