Submission #332616

# Submission time Handle Problem Language Result Execution time Memory
332616 2020-12-03T01:34:22 Z casperwang Selling RNA Strands (JOI16_selling_rna) C++14
0 / 100
1500 ms 54460 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

const int MAXN = 100000;
const int BLOCK = 1000;
const int MOD = 998244353;
const int K = 1311;
int n, m;
string s[MAXN];
vector <int> pre_hash[MAXN];
vector <int> suf_hash[MAXN];
string p, q;
int now, ans;

bool pre(int a, int b, int len) {
  return pre_hash[a][len-1] == b;
}

bool suf(int a, int b, int len) {
  return suf_hash[a][len-1] == b;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s+n);
  for (int i = 0; i < n; i++) {
    int h = 0;
    for (int j = 0; j < s[i].size(); j++) {
      h = (h * K + s[i][j]) % MOD;
      pre_hash[i].pb(h);
    }
    h = 0;
    for (int j = s[i].size()-1; j >= 0; j--) {
      h = (h * K + s[i][j]) % MOD;
      suf_hash[i].pb(h);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p >> q;
    int hp = 0;
    for (int j = 0; j < p.size(); j++)
      hp = (hp * K + p[j]) % MOD;
    int hq = 0;
    for (int j = q.size()-1; j >= 0; j--)
      hq = (hq * K + q[j]) % MOD;
    now = lower_bound(s, s+n, p) - s;
    ans = 0;
    while (now < n && pre(now, hp, p.size())) {
      if (suf(now, hq, q.size())) ans++;
      now++;
    }
    cout << ans << "\n";
  }
  return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int j = 0; j < s[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
selling_rna.cpp:47:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int j = 0; j < p.size(); j++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Incorrect 6 ms 8172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 50156 KB Output is correct
2 Correct 361 ms 54460 KB Output is correct
3 Incorrect 155 ms 52716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 11528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8172 KB Output is correct
2 Incorrect 6 ms 8172 KB Output isn't correct
3 Halted 0 ms 0 KB -