제출 #1123482

#제출 시각아이디문제언어결과실행 시간메모리
1123482gdragonSelling RNA Strands (JOI16_selling_rna)C++20
35 / 100
1136 ms74368 KiB
#include <bits/stdc++.h> using namespace std; #define TASK "long" #define fi first #define se second #define ll long long #define pb push_back #define ALL(x) (x).begin(), (x).end() #define GETBIT(mask, i) ((mask) >> (i) & 1) #define MASK(i) ((1LL) << (i)) #define SZ(x) ((int)(x).size()) #define mp make_pair #define CNTBIT(mask) __builtin_popcount(mask) template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;}; template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;}; typedef pair<int, int> ii; const int N = 1e5 + 5; const int inf = 1e9 + 7; const long long INF = (long long)1e18 + 7; // const int mod = 1e9 + 7; // void add(int &x, int y) {x += y; if (x >= mod) x -= mod;} // void sub(int &x, int y) {x -= y; if (x < 0) x += mod;} // int mul(int x, int y) {return 1LL * x * y % mod;} // -----------------------------------------// const pair<int, int> mod = {1e9 + 7, 1e9 + 9}; const pair<int, int> base = {311, 31}; pair<int, int> operator + (const ii &x, const ii &y) { return {(x.fi + y.fi) % mod.fi, (x.se + y.se) % mod.se}; } pair<int, int> operator - (const ii &x, const ii &y) { return {(x.fi - y.fi + mod.fi) % mod.fi, (x.se - y.se + mod.se) % mod.se}; } pair<int, int> operator * (const ii &x, const ii &y) { return {1LL * x.fi * y.fi % mod.fi, 1LL * x.se * y.se % mod.se}; } pair<int, int> pw[N]; struct Data { string s; int n; vector<pair<int, int>> hs; void init(const string &t) { s = t; n = SZ(s); s = ' ' + s; hs.assign(n + 2, {0, 0}); for(int i = 1; i <= n; i++) { int c = s[i] - 'A' + 1; hs[i] = hs[i - 1] * base + mp(c, c); } } pair<int, int> getHash(int l, int r) { return hs[r] - hs[l - 1] * pw[r - l + 1]; } bool operator < (Data other) { int l = 1, r = min(n, other.n), pos = 0; while(l <= r) { int mid = (l + r) >> 1; if (getHash(1, mid) == other.getHash(1, mid)) { pos = mid; l = mid + 1; } else r = mid - 1; } if (pos == min(n, other.n)) return n < other.n; return s[pos + 1] < other.s[pos + 1]; } }; int n, q; Data a[N]; pair<pair<Data, Data>, int> queries[N]; void read() { cin >> n >> q; for(int i = 1; i <= n; i++) { string s; cin >> s; a[i].init(s); } for(int i = 1; i <= q; i++) { string s1, s2; cin >> s1 >> s2; queries[i].fi.fi.init(s1); queries[i].fi.se.init(s2); queries[i].se = i; } } void sub2() { for(int iter = 1; iter <= q; iter++) { int ans = 0; int n1 = queries[iter].fi.fi.n; int n2 = queries[iter].fi.se.n; pair<int, int> val1 = queries[iter].fi.fi.hs[n1]; pair<int, int> val2 = queries[iter].fi.se.hs[n2]; // cerr << val1.fi << ' ' << val1.se << endl; for(int i = 1; i <= n; i++) { if (max(n1, n2) <= a[i].n) { if (a[i].getHash(1, n1) == val1 && a[i].getHash(a[i].n - n2 + 1, a[i].n) == val2) ++ans; } } cout << ans << endl; } } void solve() { if (max(n, q) <= 5000) sub2(); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } pw[0] = {1, 1}; for(int i = 1; i < N; i++) pw[i] = pw[i - 1] * base; int test = 1; // cin >> test; while(test--) { read(); solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(TASK".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...