Submission #57107

# Submission time Handle Problem Language Result Execution time Memory
57107 2018-07-14T03:28:07 Z 조민규(#2115) Selling RNA Strands (JOI16_selling_rna) C++11
100 / 100
543 ms 160916 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int f(char x)
{
    if(x == 'A')
        return 0;
    if(x == 'G')
        return 1;
    if(x == 'C')
        return 2;
    return 3;
}

struct ent1
{
    int a[4];
    vector<int> fin1, fin2;
};

struct ent2
{
    int a[4];
    int cnt;
};

vector<ent1> m1(1);
vector<ent2> m2(1);
string s[100010];
string p[100010];
string q[100010];

int pos[100010];
int res[100010];

void dfs(int c)
{
    for(int &a : m1[c].fin2)
        res[a] = -m2[pos[a]].cnt;

    for(int &a : m1[c].fin1)
    {
        reverse(s[a].begin(), s[a].end());

        int c2 = 0;
        for(char &x : s[a])
        {
            int t = f(x);
            if(!m2[c2].a[t])
                break;

            c2 = m2[c2].a[t];
            m2[c2].cnt++;
        }
    }

    for(int i = 0; i < 4; i++)
        if(m1[c].a[i])
            dfs(m1[c].a[i]);

    for(int &a : m1[c].fin2)
        res[a] += m2[pos[a]].cnt;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, m, i, j;
    cin >> n >> m;
    for(i = 0; i < n; i++)
        cin >> s[i];
    for(i = 0; i < m; i++)
        cin >> p[i] >> q[i];

    for(i = 0; i < n; i++)
    {
        int c = 0;
        for(char &x : s[i])
        {
            int t = f(x);
            if(!m1[c].a[t])
            {
                m1[c].a[t] = m1.size();
                m1.resize(m1.size() + 1);
            }
            c = m1[c].a[t];
        }
        m1[c].fin1.push_back(i);
    }
    for(i = 0; i < m; i++)
    {
        int c = 0;
        for(char &x : p[i])
        {
            int t = f(x);
            if(!m1[c].a[t])
            {
                m1[c].a[t] = m1.size();
                m1.resize(m1.size() + 1);
            }
            c = m1[c].a[t];
        }
        m1[c].fin2.push_back(i);
    }

    for(i = 0; i < m; i++)
    {
        reverse(q[i].begin(), q[i].end());

        int c = 0;
        for(char &x : q[i])
        {
            int t = f(x);
            if(!m2[c].a[t])
            {
                m2[c].a[t] = m2.size();
                m2.resize(m2.size() + 1);
            }
            c = m2[c].a[t];
        }
        pos[i] = c;
    }

    dfs(0);

    for(i = 0; i < m; i++)
        printf("%d\n", res[i]);
    return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:86:18: warning: unused variable 'j' [-Wunused-variable]
     int n, m, i, j;
                  ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 12 ms 9816 KB Output is correct
3 Correct 12 ms 10004 KB Output is correct
4 Correct 12 ms 10004 KB Output is correct
5 Correct 9 ms 10004 KB Output is correct
6 Correct 13 ms 10004 KB Output is correct
7 Correct 12 ms 10004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 20464 KB Output is correct
2 Correct 207 ms 24396 KB Output is correct
3 Correct 531 ms 157932 KB Output is correct
4 Correct 543 ms 158040 KB Output is correct
5 Correct 473 ms 158040 KB Output is correct
6 Correct 450 ms 158040 KB Output is correct
7 Correct 287 ms 158040 KB Output is correct
8 Correct 484 ms 158040 KB Output is correct
9 Correct 397 ms 158040 KB Output is correct
10 Correct 270 ms 158040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 158040 KB Output is correct
2 Correct 48 ms 158040 KB Output is correct
3 Correct 62 ms 158040 KB Output is correct
4 Correct 46 ms 158040 KB Output is correct
5 Correct 52 ms 158040 KB Output is correct
6 Correct 57 ms 158040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 12 ms 9816 KB Output is correct
3 Correct 12 ms 10004 KB Output is correct
4 Correct 12 ms 10004 KB Output is correct
5 Correct 9 ms 10004 KB Output is correct
6 Correct 13 ms 10004 KB Output is correct
7 Correct 12 ms 10004 KB Output is correct
8 Correct 304 ms 20464 KB Output is correct
9 Correct 207 ms 24396 KB Output is correct
10 Correct 531 ms 157932 KB Output is correct
11 Correct 543 ms 158040 KB Output is correct
12 Correct 473 ms 158040 KB Output is correct
13 Correct 450 ms 158040 KB Output is correct
14 Correct 287 ms 158040 KB Output is correct
15 Correct 484 ms 158040 KB Output is correct
16 Correct 397 ms 158040 KB Output is correct
17 Correct 270 ms 158040 KB Output is correct
18 Correct 50 ms 158040 KB Output is correct
19 Correct 48 ms 158040 KB Output is correct
20 Correct 62 ms 158040 KB Output is correct
21 Correct 46 ms 158040 KB Output is correct
22 Correct 52 ms 158040 KB Output is correct
23 Correct 57 ms 158040 KB Output is correct
24 Correct 223 ms 158040 KB Output is correct
25 Correct 247 ms 158040 KB Output is correct
26 Correct 210 ms 158040 KB Output is correct
27 Correct 497 ms 160916 KB Output is correct
28 Correct 310 ms 160916 KB Output is correct
29 Correct 232 ms 160916 KB Output is correct