結果
問題 | No.2716 Falcon Method |
ユーザー |
|
提出日時 | 2024-04-05 21:38:09 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 1,428 bytes |
コンパイル時間 | 2,040 ms |
コンパイル使用メモリ | 204,124 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 01:52:13 |
合計ジャッジ時間 | 4,863 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define all(x) x.begin(),x.end() template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #define ASSERT(...) 42 #endif typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int oo = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,q; cin >> n >> q; string s; cin >> s; vi prefx(n+1),prefy(n+1); for(int i=0;i<n;++i) { prefx[i+1]=prefx[i] + (s[i]=='R'); prefy[i+1]=prefy[i]+(s[i]=='D'); } while(q--) { int h,w,p; cin >> h >> w >> p; ll lo = 0, hi = 2e9; while(lo<hi) { auto mid = (lo+hi)/2; auto e = (mid+p)%n; ll loops = (p+mid)/n - p/n; auto get = [&](vi& v) { return v[n]*loops + v[e]-v[p]; }; if(get(prefx)>=w or get(prefy)>=h) { hi = mid; } else lo = mid+1; } cout << (lo+p)%n << '\n'; } }