Submission #332608

#TimeUsernameProblemLanguageResultExecution timeMemory
332608casperwangSelling RNA Strands (JOI16_selling_rna)C++14
10 / 100
1589 ms6088 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100000;
const int BLOCK = 1000;
int n, m;
string s[MAXN];
string p, q;
int now, ans;

bool pre(string a, string b) {
  if (a.size() < b.size()) return 0;
  for (int i = 0; i < b.size(); i++)
    if (a[i] != b[i]) return 0;
  return 1;
}

bool suf(string a, string b) {
  if (a.size() < b.size()) return 0;
  for (int i = 0; i < b.size(); i++)
    if (a[a.size()-1-i] != b[b.size()-1-i]) return 0;
  return 1;
}

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 < m; i++) {
    cin >> p >> q;
    now = lower_bound(s, s+n, p) - s;
    ans = 0;
    while (now < n && pre(s[now], p)) {
      if (suf(s[now], q)) ans++;
      now++;
    }
    cout << ans << "\n";
  }
  return 0;
}

Compilation message (stderr)

selling_rna.cpp: In function 'bool pre(std::string, std::string)':
selling_rna.cpp:13:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for (int i = 0; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
selling_rna.cpp: In function 'bool suf(std::string, std::string)':
selling_rna.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...