Submission #1279901

#TimeUsernameProblemLanguageResultExecution timeMemory
1279901nhmktuSelling RNA Strands (JOI16_selling_rna)C++17
0 / 100
356 ms557744 KiB
#include <bits/stdc++.h> #define ll long long #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define pi pair<int,int> #define pii pair<int,pi> #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define sz(a) (int) a.size() #define endl '\n' #define data "data" using namespace std; const ll linf = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7, N = 1e5; void add(int &a, int b) { a += b; if(a>=MOD) a-=MOD; if(a<0) a += MOD; } int modulo(int x) { if(x<=1) return 1; return (MOD - MOD/x) * modulo(MOD/x) % MOD; } int mul(int a, int b) { return (1ll *a%MOD * b%MOD) % MOD; } int n, m; vector<string> Vs; void inp(void) { cin >> n >> m; FOR(i, 1, n) { string s; cin >> s; Vs.pb(s); } sort(all(Vs)); } struct Trie { Trie *child[26]; int l, r; vector<int> idx; Trie() { l = r = - 1; idx = {}; memset(child, NULL, sizeof(child)); } }; Trie *root1; Trie *root2; void Insert(Trie *root, string s, int id, bool f) { Trie *p = root; FOR(i, 0, sz(s) -1) { int c = s[i] - 'A'; if(p -> child[ c ] == NULL) p -> child[c] = new Trie(); p = p -> child[c]; if(f) { if(p -> l == -1) p -> l = id; else p -> l = min(p -> l, id); if(p -> r == -1) p -> r = id; else p -> r = max(p -> r, id); } else (p -> idx).pb(id); } } pi Get1(string s) { Trie *p = root1; FOR(i, 0, sz(s) -1) { int c = s[i] - 'A'; if(p -> child[c] == NULL) return {-1, -1}; p = p -> child[c]; } return {p -> l, p -> r}; } int Get2(string s, int L, int R) { Trie *p = root2; FOR(i, 0, sz(s) -1) { int c = s[i] - 'A'; if(p -> child[c] == NULL) return 0; p = p -> child[c]; } vector<int> :: iterator p1 = lower_bound(all(p -> idx), L); vector<int> :: iterator p2 = upper_bound(all(p -> idx), R); return p2 - p1; } void solve(void) { root1 = new Trie(); root2 = new Trie(); FOR(i, 0, sz(Vs) -1) Insert(root1, Vs[i], i, 1); FOR(i, 0, sz(Vs) -1) { string s = Vs[i]; reverse(all(s)); Insert(root2, s, i, 0); } FOR(i, 1, m) { string pre, suf; cin >> pre >> suf; pi ret = Get1(pre); int L = ret.fi, R = ret.se; if(L == -1 && R == -1) cout << "0\n"; else cout << Get2(suf, L, R) << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(data".inp", "r")) { freopen(data".inp","r",stdin); freopen(data".out","w",stdout); } inp(); solve(); return 0; }

Compilation message (stderr)

selling_rna.cpp: In constructor 'Trie::Trie()':
selling_rna.cpp:65:23: warning: passing NULL to non-pointer argument 2 of 'void* memset(void*, int, size_t)' [-Wconversion-null]
   65 |         memset(child, NULL, sizeof(child));
      |                       ^~~~
In file included from /usr/include/features.h:502,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:679,
                 from /usr/include/c++/13/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:33,
                 from selling_rna.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:57:1: note:   declared here
   57 | __NTH (memset (void *__dest, int __ch, size_t __len))
      | ^~~~~
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:152:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  152 |         freopen(data".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:153:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  153 |         freopen(data".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...