Submission #423088

# Submission time Handle Problem Language Result Execution time Memory
423088 2021-06-10T17:15:50 Z doowey Skyscraper (JOI16_skyscraper) C++14
0 / 100
251 ms 317944 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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:72:9: warning: unused variable 'cnt' [-Wunused-variable]
   72 |     int cnt;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 251 ms 317868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 237 ms 317944 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 251 ms 317868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -