# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
378108 | reymontada61 | Selling RNA Strands (JOI16_selling_rna) | C++14 | 1585 ms | 16600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, q;
const int MXN = 100005;
string arr[MXN];
vector<pair<string, int>> proc;
string pre, suf;
bool usep;
bool after(int x) {
if (usep) {
for (int i=0; i<min(pre.size(), arr[x].size()); i++) {
if (pre[i] < arr[x][i]) return true;
if (pre[i] > arr[x][i]) return false;
}
return arr[x].size() >= pre.size();
}
else {
for (int i=0; i<min(suf.size(), proc[x].first.size()); i++) {
if (suf[i] < proc[x].first[i]) return true;
if (suf[i] > proc[x].first[i]) return false;
}
return proc[x].first.size() >= suf.size();
}
}
int first() {
if (!after(n)) return n + 1;
int low = 1;
int high = n;
while (low < high) {
int mid = (low + high) / 2;
if (after(mid)) {
high = mid;
}
else {
low = mid + 1;
}
}
return low;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
for (int i=1; i<=n; i++) {
cin >> arr[i];
}
sort(arr+1, arr+n+1);
for (int i=1; i<=n; i++) {
string s = arr[i];
reverse(s.begin(), s.end());
proc.push_back({s, i});
}
proc.push_back({"", -1});
sort(proc.begin(), proc.end());
while (q--) {
cin >> pre >> suf;
reverse(suf.begin(), suf.end());
usep = true;
int pre_a = first();
pre += 'a';
int pre_b = first() - 1;
usep = false;
int suf_a = first();
suf += 'a';
int suf_b = first() - 1;
int ans = 0;
for (int x=suf_a; x<=suf_b; x++) {
if (pre_a <= proc[x].second && proc[x].second <= pre_b) ans++;
}
cout << ans << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |