# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
68408 | KLPP | Selling RNA Strands (JOI16_selling_rna) | C++14 | 1565 ms | 25416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define MOD 1000000009
#define BASE 257
typedef long long int lld;
bool cmp(string a, string b){
for(int i=0;i<a.size() && i<b.size();i++){
if(a.at(i)<b.at(i))return true;
if(a.at(i)>b.at(i))return false;
}
if(a.length()<=b.length())return true;
return false;
}
bool cmp2(string a, string b){
for(int i=0;i<a.size() && i<b.size();i++){
if(a.at(i)<b.at(i))return true;
if(a.at(i)>b.at(i))return false;
}
if(a.length()>b.length())return true;
return false;
}
int main(){
int n,m;
cin>>n>>m;
string arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
vector<lld> hashes[n];
for(int i=0;i<n;i++){
lld v=1;
lld h=0;
for(int j=arr[i].size()-1;j>-1;j--){
h+=v*arr[i].at(j);
h%=MOD;
v*=BASE;
v%=MOD;
hashes[i].push_back(h);
}
}
while(m--){
string p,q;
cin>>p>>q;
lld hashq=0;
lld v=1;
for(int i=q.size()-1;i>-1;i--){
hashq+=v*q.at(i);
v*=BASE;
v%=MOD;
}
int lo,hi;
lo=-1;
hi=n;
int pos=0;
while(hi-lo>1){
int mid=(hi+lo)/2;
if(cmp(p,arr[mid]))hi=mid;
else lo=mid;
}
int comeco=hi;
lo=comeco-1;
hi=n;
while(hi-lo>1){
int mid=(hi+lo)/2;
if(cmp2(p,arr[mid]))hi=mid;
else lo=mid;
}
int fim=lo;
int cnt=0;
//cout<<comeco<<" "<<fim<<endl;
//cout<<hashq<<endl;
for(int i=comeco;i<=fim;i++){
if(hashes[i].size()>=q.length() && hashes[i][q.length()-1]==hashq){
cnt++;
}
}cout<<cnt<<endl;
}
return 0;
}
컴파일 시 표준 에러 (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... |