이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T>
bool chmax(T &v, T val) { return v < val ? (v = val, true) : false; }
template<class T>
bool chmin(T &v, T val) { return val < v ? (v = val, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = "), kout(args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 100010, MAX_M = 5000;
int n, m, enc[256];
string w[MAX_M], p[MAX_M], q[MAX_M];
struct trie {
trie* nxt[4]{};
bitset<MAX_M> ok;
void rev_insert(const string &w, int id) {
trie* now = this;
for (int i = (int)w.size() - 1;i >= 0;--i) {
auto &pt = now->nxt[ enc[ w[i] ] ];
if (!pt) pt = new trie;
now = pt;
pt->ok[ id ] = true;
}
}
bitset<MAX_M> rev_qry(const string &w) {
trie *now = this;
for (int i = (int)w.size() - 1;i >= 0;--i) {
auto &pt = now->nxt[ enc[ w[i] ] ];
if (!pt) return bitset<MAX_M>() ;
now = pt;
}
return now->ok;
}
void insert(const string &w, int id) {
trie* now = this;
for (int i = 0;i < w.size();++i) {
auto &pt = now->nxt[ enc[ w[i] ] ];
if (!pt) pt = new trie;
now = pt;
pt->ok[ id ] = true;
}
}
bitset<MAX_M> qry(const string &w) {
trie *now = this;
for (int i = 0;i < w.size();++i) {
auto &pt = now->nxt[ enc[ w[i] ] ];
if (!pt) return bitset<MAX_M>() ;
now = pt;
}
return now->ok;
}
}ac, ca;
void solve() {
for (int i = 0;i < n;++i) {
ac.insert(w[i], i);
ca.rev_insert(w[i], i);
}
for (int i = 0;i < m;++i) {
cout << ( ac.qry(p[i]) & ca.rev_qry(q[i]) ).count() << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
enc['A'] = 0, enc['G'] = 1, enc['C'] = 2, enc['U'] = 3;
cin >> n >> m;
for (int i = 0;i < n;++i)
cin >> w[i];
for (int i = 0;i < m;++i)
cin >> p[i] >> q[i];
if (n > 5000) return 1;
solve();
return 0;
for (int i = 0;i < m;++i) {
int res = 0;
for (int j = 0;j < n;++j) {
if (max(p[i].size(), q[i].size()) > w[j].size()) continue;
res += p[i] == w[j].substr(0, p[i].size()) &&
q[i] == w[j].substr(w[j].size() - q[i].size());
}
cout << res << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
selling_rna.cpp: In member function 'void trie::rev_insert(const string&, int)':
selling_rna.cpp:33:35: warning: array subscript has type 'char' [-Wchar-subscripts]
33 | auto &pt = now->nxt[ enc[ w[i] ] ];
| ^
selling_rna.cpp: In member function 'std::bitset<5000> trie::rev_qry(const string&)':
selling_rna.cpp:42:35: warning: array subscript has type 'char' [-Wchar-subscripts]
42 | auto &pt = now->nxt[ enc[ w[i] ] ];
| ^
selling_rna.cpp: In member function 'void trie::insert(const string&, int)':
selling_rna.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0;i < w.size();++i) {
| ~~^~~~~~~~~~
selling_rna.cpp:51:35: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | auto &pt = now->nxt[ enc[ w[i] ] ];
| ^
selling_rna.cpp: In member function 'std::bitset<5000> trie::qry(const string&)':
selling_rna.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0;i < w.size();++i) {
| ~~^~~~~~~~~~
selling_rna.cpp:60:35: warning: array subscript has type 'char' [-Wchar-subscripts]
60 | auto &pt = now->nxt[ enc[ w[i] ] ];
| ^
# | 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... |