結果
問題 |
No.2716 Falcon Method
|
ユーザー |
![]() |
提出日時 | 2024-04-05 22:07:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 210 ms / 2,000 ms |
コード長 | 1,848 bytes |
コンパイル時間 | 2,236 ms |
コンパイル使用メモリ | 196,640 KB |
最終ジャッジ日時 | 2025-02-20 21:24:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i<n;i++) #define foa(e, v) for(auto&& e : v) using ll = long long; const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60); #define dout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; string s; cin >> s; vector<ll> vr, vd; rep(i, n) { if(s[i] == 'R') vr.pb(i); else vd.pb(i); } rep(_, q) { ll h, w, p; cin >> h >> w >> p; ll ans = INF; int id = -1; if((int)vr.size()) { ll idx = lower_bound(all(vr), p) - vr.begin(); if((ll)vr.size() - idx >= w) { ans = min(ans, vr[idx + w - 1] + 1); } else { w -= (ll)vr.size() - idx; ll num = w / (ll)vr.size(); ll r = w % (ll)vr.size(); if(r == 0) { ans = min(ans, n + (num - 1) * n + vr.back() + 1); } else { ans = min(ans, n + num * n + vr[r - 1] + 1); } } } if((int)vd.size()) { ll idx = lower_bound(all(vd), p) - vd.begin(); if((ll)vd.size() - idx >= h) { ans = min(ans, vd[idx + h - 1] + 1); } else { h -= (ll)vd.size() - idx; ll num = h / (ll)vd.size(); ll r = h % (ll)vd.size(); if(r == 0) { ans = min(ans, n + (num - 1) * n + vd.back() + 1); } else { ans = min(ans, n + num * n + vd[r - 1] + 1); } } } cout << ans % n << endl; } return 0; }