Submission #44671

# Submission time Handle Problem Language Result Execution time Memory
44671 2018-04-04T17:11:40 Z choikiwon Selling RNA Strands (JOI16_selling_rna) C++17
10 / 100
1500 ms 177128 KB
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

int po[1000010];

int N, M;
string S[100010], P[100010], Q[100010];
vector<int> Len;
unordered_map<int, int> Cnt[1000010];
vector<int> psum[100010];

int calc(int s, int l, int r) {
    return (psum[s][r] + mod - (l? 1LL * psum[s][l - 1] * po[r - l + 1] % mod : 0)) % mod;
}

void getStr(string &s) {
    while(1) {
        char c = getchar();
        if(c == ' ' || c == '\n') break;
        s.push_back(c);
    }
}

int main() {
    po[0] = 1;
    for(int i = 1; i < 1000010; i++) {
        po[i] = 1LL * po[i - 1] * 128 % mod;
    }

    scanf("%d %d", &N, &M);

    getchar();
    for(int i = 0; i < N; i++) {
        getStr(S[i]);
    }

    for(int i = 0; i < M; i++) {
        getStr(P[i]);
        getStr(Q[i]);
    }

    for(int i = 0; i < M; i++) {
        Len.push_back(P[i].size() + Q[i].size());
    }
    sort(Len.begin(), Len.end());
    Len.resize(unique(Len.begin(), Len.end()) - Len.begin());

    for(int i = 0; i < N; i++) {
        psum[i].resize(2 * S[i].size());
        for(int j = 0; j < 2 * S[i].size(); j++) {
            psum[i][j] = S[i][j % (S[i].size())];
            if(j) {
                psum[i][j] += 1LL * psum[i][j - 1] * 128 % mod;
                psum[i][j] %= mod;
            }
        }

        for(int j = 0; j < Len.size(); j++) {
            for(int k = 0; k < S[i].size(); k++) {
                if(k + Len[j] <= S[i].size()) continue;
                Cnt[ (int)S[i].size() - k ][ calc(i, k, k + Len[j] - 1) ]++;
            }
        }
    }

    for(int i = 0; i < M; i++) {
        int hash_val = 0;
        for(int j = 0; j < Q[i].size(); j++) {
            hash_val = 1LL * hash_val * 128 % mod;
            hash_val += Q[i][j];
            hash_val %= mod;
        }
        for(int j = 0; j < P[i].size(); j++) {
            hash_val = 1LL * hash_val * 128 % mod;
            hash_val += P[i][j];
            hash_val %= mod;
        }

        printf("%d\n", Cnt[ Q[i].size() ][ hash_val ]);
    }
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:52:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < 2 * S[i].size(); j++) {
                        ~~^~~~~~~~~~~~~~~~~
selling_rna.cpp:60:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < Len.size(); j++) {
                        ~~^~~~~~~~~~~~
selling_rna.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < S[i].size(); k++) {
                            ~~^~~~~~~~~~~~~
selling_rna.cpp:62:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(k + Len[j] <= S[i].size()) continue;
                    ~~~~~~~~~~~^~~~~~~~~~~~~~
selling_rna.cpp:70:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < Q[i].size(); j++) {
                        ~~^~~~~~~~~~~~~
selling_rna.cpp:75:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < P[i].size(); j++) {
                        ~~^~~~~~~~~~~~~
selling_rna.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 71 ms 70776 KB Output is correct
2 Correct 86 ms 70884 KB Output is correct
3 Correct 71 ms 70996 KB Output is correct
4 Correct 76 ms 71108 KB Output is correct
5 Correct 77 ms 71236 KB Output is correct
6 Correct 67 ms 71276 KB Output is correct
7 Correct 76 ms 71276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1583 ms 177128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 177128 KB Output is correct
2 Incorrect 181 ms 177128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 70776 KB Output is correct
2 Correct 86 ms 70884 KB Output is correct
3 Correct 71 ms 70996 KB Output is correct
4 Correct 76 ms 71108 KB Output is correct
5 Correct 77 ms 71236 KB Output is correct
6 Correct 67 ms 71276 KB Output is correct
7 Correct 76 ms 71276 KB Output is correct
8 Execution timed out 1583 ms 177128 KB Time limit exceeded
9 Halted 0 ms 0 KB -