답안 #396533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396533 2021-04-30T07:17:18 Z Sundavar Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
630 ms 344412 KB
#include <bits/stdc++.h>

using namespace std;
int get(char c){
    if(c == 'A') return 1;
    if(c == 'G') return 2;
    if(c == 'C') return 3;
    return 0;
}
struct node{
    vector<int> to;
    vector<int> veg, pont;
    int cnt = 0;
    node(){
        to.resize(4, -1);
    }
};
vector<node> trie(1), rev(1);
int add(vector<node>& t, string s, int id, bool normal = true){
    int poz = 0;
    for(char& c: s){
        if(t[poz].to[get(c)] == -1){
            t[poz].to[get(c)] = t.size();
            t.push_back(node());
        }
        t[poz = t[poz].to[get(c)]].cnt++;
    }
    if(normal) t[poz].veg.push_back(id);
    else t[poz].pont.push_back(id);
    return poz;
}
vector<int> poz;
vector<int> ans;
vector<string> p,q, revs;
void walk(int curr){
    for(int& a : trie[curr].pont)
        ans[a] -= rev[poz[a]].cnt;
    for(int& a : trie[curr].veg)
        add(rev, revs[a], a);
    for(int& to : trie[curr].to){
        if(to == -1) continue;
        walk(to);
    }
    for(int& a : trie[curr].pont)
        ans[a] += rev[poz[a]].cnt;
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin>>s[i];
        add(trie, s[i], i);
        revs.push_back(s[i]), reverse(revs[i].begin(), revs[i].end());
    }
    poz.resize(m), ans.resize(m);
    p.resize(m), q.resize(m);
    for(int i = 0; i < m; i++){
        cin>>p[i]>>q[i];
        reverse(q[i].begin(), q[i].end());
        add(trie, p[i], i, false);
        poz[i] = add(rev, q[i], i, false);
    }
    walk(0);
    for(int& a : ans)
        cout<<a<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 223444 KB Output is correct
2 Correct 368 ms 212220 KB Output is correct
3 Correct 443 ms 220816 KB Output is correct
4 Correct 436 ms 210344 KB Output is correct
5 Correct 568 ms 342196 KB Output is correct
6 Correct 630 ms 344412 KB Output is correct
7 Correct 82 ms 8760 KB Output is correct
8 Correct 355 ms 207012 KB Output is correct
9 Correct 316 ms 193252 KB Output is correct
10 Correct 273 ms 194268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 8280 KB Output is correct
2 Correct 24 ms 6032 KB Output is correct
3 Correct 29 ms 7064 KB Output is correct
4 Correct 22 ms 5532 KB Output is correct
5 Correct 23 ms 5612 KB Output is correct
6 Correct 29 ms 6928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 379 ms 223444 KB Output is correct
9 Correct 368 ms 212220 KB Output is correct
10 Correct 443 ms 220816 KB Output is correct
11 Correct 436 ms 210344 KB Output is correct
12 Correct 568 ms 342196 KB Output is correct
13 Correct 630 ms 344412 KB Output is correct
14 Correct 82 ms 8760 KB Output is correct
15 Correct 355 ms 207012 KB Output is correct
16 Correct 316 ms 193252 KB Output is correct
17 Correct 273 ms 194268 KB Output is correct
18 Correct 30 ms 8280 KB Output is correct
19 Correct 24 ms 6032 KB Output is correct
20 Correct 29 ms 7064 KB Output is correct
21 Correct 22 ms 5532 KB Output is correct
22 Correct 23 ms 5612 KB Output is correct
23 Correct 29 ms 6928 KB Output is correct
24 Correct 363 ms 207420 KB Output is correct
25 Correct 383 ms 210216 KB Output is correct
26 Correct 379 ms 206432 KB Output is correct
27 Correct 401 ms 200184 KB Output is correct
28 Correct 196 ms 48696 KB Output is correct
29 Correct 97 ms 15960 KB Output is correct