Submission #419013

#TimeUsernameProblemLanguageResultExecution timeMemory
419013cpp219Selling RNA Strands (JOI16_selling_rna)C++14
35 / 100
1589 ms433012 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e6 + 9; const ll mod = 1e9; typedef pair<ll,ll> LL; string s; ll n,Q; char Convert(char c){ if (c == 'A') return '0'; if (c == 'G') return '1'; if (c == 'C') return '2'; if (c == 'U') return '3'; } void oper(string &s){ for (ll j = 0;j < s.size();j++) s[j] = Convert(s[j]); } struct Trie{ Trie *child[5][5]; ll cnt = 0; Trie(){ cnt = 0; for (ll i = 0;i < 5;i++) for (ll j = 0;j < 5;j++) child[i][j] = NULL; } void Add(ll id,string &s){ cnt++; if (id == s.size()) return; ll sz = s.size(); ll x = s[id] - '0',y = s[sz - id - 1] - '0'; if (!child[x][y]) child[x][y] = new Trie; child[x][y] -> Add(id + 1,s); } ll Get(ll id,string &pre,string &suf){ /// pre.sz == suf.sz; if (id == pre.size()) return cnt; ll sz = suf.size(),ans = 0; ll x = pre[id] - '0',y = suf[sz - id - 1] - '0'; if (x == 4){ for (ll i = 0;i < 4;i++) if (child[i][y]) ans += child[i][y] -> Get(id + 1,pre,suf); } else if (y == 4){ for (ll i = 0;i < 4;i++) if (child[x][i]) ans += child[x][i] -> Get(id + 1,pre,suf); } else{ if (child[x][y]) ans += child[x][y] -> Get(id + 1,pre,suf); } return ans; } }; string p,q; int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } Trie Tree; cin>>n>>Q; for (ll i = 1;i <= n;i++){ cin>>s; oper(s); Tree.Add(0,s); } while(Q--){ cin>>p>>q; oper(p); oper(q); string now; while(p.size() < q.size()) p = p + '4'; while(q.size() + now.size() < p.size()) now += '4'; now += q; cout<<Tree.Get(0,p,now)<<"\n"; } }

Compilation message (stderr)

selling_rna.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
selling_rna.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
selling_rna.cpp: In function 'void oper(std::string&)':
selling_rna.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (ll j = 0;j < s.size();j++) s[j] = Convert(s[j]);
      |                   ~~^~~~~~~~~~
selling_rna.cpp: In member function 'void Trie::Add(int, std::string&)':
selling_rna.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if (id == s.size()) return;
      |             ~~~^~~~~~~~~~~
selling_rna.cpp: In member function 'int Trie::Get(int, std::string&, std::string&)':
selling_rna.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (id == pre.size()) return cnt;
      |             ~~~^~~~~~~~~~~~~
selling_rna.cpp: In function 'char Convert(char)':
selling_rna.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...