답안 #1034425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034425 2024-07-25T13:43:06 Z doducanh Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
266 ms 452580 KB
#include <bits/stdc++.h>

using namespace std;
#define all(x) x.begin(),x.end()
const int maxn=2e5+7;
const int maxx=2e6+7;
string s[maxn];
int n,m;
struct trie
{
    int t[maxx][28];
    vector<int>who[maxx];
    int cnt;
    trie(){
        cnt=0;
    }
    void add(string &s,int i){
        int curr=0;
        for(char c:s){
            if(t[curr][c-'A'+1]==0)t[curr][c-'A'+1]=++cnt;
            curr=t[curr][c-'A'+1];
            who[curr].push_back(i);
        }
    }
    array<int,2>get(string &s){
        int curr=0;
        for(char c:s){
            if(t[curr][c-'A'+1]==0)return {-1,-1};
            curr=t[curr][c-'A'+1];
        }
        return array<int,2>{who[curr].front(),who[curr].back()};
    }
    int query(string &s,int l,int r){
        int curr=0;
        for(char c:s){
            if(t[curr][c-'A'+1]==0)return 0;
            curr=t[curr][c-'A'+1];
        }
        return (int)(upper_bound(all(who[curr]),r)-lower_bound(all(who[curr]),l));
    }
};
trie t,tn;
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    vector<string>s(n);
    for(string &s:s){
        cin>>s;
    }
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++){
        t.add(s[i],i);
        reverse(all(s[i]));
        tn.add(s[i],i);
    }
    for(int i=1;i<=m;i++){
        string p,q;
        cin>>p>>q;
        reverse(all(q));
        auto [L,R]=t.get(p);
        cout<<tn.query(q,L,R)<<"\n";
    }
    return 0;
}

Compilation message

selling_rna.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main()
      | ^~~~
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
selling_rna.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         auto [L,R]=t.get(p);
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 100432 KB Output is correct
2 Correct 43 ms 100436 KB Output is correct
3 Correct 44 ms 100680 KB Output is correct
4 Correct 42 ms 100696 KB Output is correct
5 Correct 45 ms 100524 KB Output is correct
6 Correct 42 ms 100436 KB Output is correct
7 Correct 44 ms 100436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 394836 KB Output is correct
2 Correct 262 ms 380244 KB Output is correct
3 Correct 229 ms 391400 KB Output is correct
4 Correct 224 ms 377564 KB Output is correct
5 Correct 266 ms 447316 KB Output is correct
6 Correct 266 ms 452580 KB Output is correct
7 Correct 86 ms 124752 KB Output is correct
8 Correct 264 ms 321832 KB Output is correct
9 Correct 225 ms 288076 KB Output is correct
10 Correct 182 ms 281172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 103976 KB Output is correct
2 Correct 53 ms 103504 KB Output is correct
3 Correct 58 ms 103760 KB Output is correct
4 Correct 52 ms 103260 KB Output is correct
5 Correct 57 ms 103504 KB Output is correct
6 Correct 55 ms 103764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 100432 KB Output is correct
2 Correct 43 ms 100436 KB Output is correct
3 Correct 44 ms 100680 KB Output is correct
4 Correct 42 ms 100696 KB Output is correct
5 Correct 45 ms 100524 KB Output is correct
6 Correct 42 ms 100436 KB Output is correct
7 Correct 44 ms 100436 KB Output is correct
8 Correct 254 ms 394836 KB Output is correct
9 Correct 262 ms 380244 KB Output is correct
10 Correct 229 ms 391400 KB Output is correct
11 Correct 224 ms 377564 KB Output is correct
12 Correct 266 ms 447316 KB Output is correct
13 Correct 266 ms 452580 KB Output is correct
14 Correct 86 ms 124752 KB Output is correct
15 Correct 264 ms 321832 KB Output is correct
16 Correct 225 ms 288076 KB Output is correct
17 Correct 182 ms 281172 KB Output is correct
18 Correct 64 ms 103976 KB Output is correct
19 Correct 53 ms 103504 KB Output is correct
20 Correct 58 ms 103760 KB Output is correct
21 Correct 52 ms 103260 KB Output is correct
22 Correct 57 ms 103504 KB Output is correct
23 Correct 55 ms 103764 KB Output is correct
24 Correct 235 ms 343580 KB Output is correct
25 Correct 233 ms 343940 KB Output is correct
26 Correct 235 ms 341244 KB Output is correct
27 Correct 245 ms 340568 KB Output is correct
28 Correct 155 ms 157396 KB Output is correct
29 Correct 97 ms 116924 KB Output is correct