답안 #1038836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038836 2024-07-30T08:11:59 Z vjudge1 Selling RNA Strands (JOI16_selling_rna) C++17
35 / 100
844 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1e5+7;
struct tri
{
    struct node
    {
        bitset<mxn> cnt; ll child[4];
        node() 
        {
            cnt = 0;
            for (ll i = 0; i < 4; i++) child[i] = 0;
        }
    };
    vector<node> trie = {node()};
    void add(string& x, ll id)
    {
        ll u = 0;
        for (ll i = 0; i < x.size(); i++)
        {
            if (!trie[u].child[x[i]-'A']) {trie.pb(node()); trie[u].child[x[i]-'A'] = trie.size()-1;}
            u = trie[u].child[x[i]-'A'];
        }
        trie[u].cnt[id] = 1;
    } 
    bitset<mxn> get(string& x)
    {
        ll u = 0;
        bitset<mxn> ans;
        for (ll i = 0; i < x.size(); i++)
        {
            if (!trie[u].child[x[i]-'A']) return ans;
            u = trie[u].child[x[i]-'A'];
        }
        return trie[u].cnt;
    }
    void build(ll u) 
    {
        for (ll i = 0; i < 4; i++) if (trie[u].child[i]) 
        {
            build(trie[u].child[i]);
            trie[u].cnt ^= trie[trie[u].child[i]].cnt;
        }
    }
} tri1, tri2;
char trans(char x) 
{
    if (x == 'A') return 'A';
    if (x == 'U') return 'B';
    if (x == 'G') return 'C';
    return 'D';
}
ll n, m;
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n >> m;
    for (ll i = 1; i <= n; i++) 
    {
        string s; cin >> s;
        for (char& j : s) j = trans(j); 
        tri1.add(s,i);
        reverse(s.begin(),s.end());
        tri2.add(s,i);
    }
    tri1.build(0); tri2.build(0); 
    for (ll i = 1; i <= m; i++)
    {
        string a, b; cin >> a >> b;
        for (char& j : a) j = trans(j);
        for (char& j : b) j = trans(j);
        reverse(b.begin(),b.end());
        bitset<mxn> aa = tri1.get(a), bb = tri2.get(b);
        // cerr << aa[3] << ' ' << bb[3] << '\n';
        aa &= bb;
        cout << aa.count() << '\n';
    }
}

Compilation message

selling_rna.cpp: In member function 'void tri::add(std::string&, ll)':
selling_rna.cpp:25:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (ll i = 0; i < x.size(); i++)
      |                        ~~^~~~~~~~~~
selling_rna.cpp: In member function 'std::bitset<100007> tri::get(std::string&)':
selling_rna.cpp:36:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (ll i = 0; i < x.size(); i++)
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3628 KB Output is correct
2 Correct 3 ms 3940 KB Output is correct
3 Correct 4 ms 5368 KB Output is correct
4 Correct 3 ms 3144 KB Output is correct
5 Correct 3 ms 3608 KB Output is correct
6 Correct 3 ms 3016 KB Output is correct
7 Correct 4 ms 3688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 844 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 1512 KB Output is correct
2 Correct 266 ms 121900 KB Output is correct
3 Correct 248 ms 68552 KB Output is correct
4 Correct 163 ms 1368 KB Output is correct
5 Correct 228 ms 72796 KB Output is correct
6 Correct 279 ms 69240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3628 KB Output is correct
2 Correct 3 ms 3940 KB Output is correct
3 Correct 4 ms 5368 KB Output is correct
4 Correct 3 ms 3144 KB Output is correct
5 Correct 3 ms 3608 KB Output is correct
6 Correct 3 ms 3016 KB Output is correct
7 Correct 4 ms 3688 KB Output is correct
8 Runtime error 844 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -