結果
問題 | No.2716 Falcon Method |
ユーザー |
![]() |
提出日時 | 2025-01-15 17:29:40 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 2,173 bytes |
コンパイル時間 | 3,773 ms |
コンパイル使用メモリ | 297,856 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-15 17:29:49 |
合計ジャッジ時間 | 6,907 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#ifdef t9unkubj#include"debug.cpp"//#include"template_no_debug.h"#else#define dbg(...) 199958#endif#undef _GLIBCXX_DEBUG#pragma GCC optimize("O3")using namespace std;#include<bits/stdc++.h>using ll=long long;using ull=unsigned long long;template<class T>using vc=vector<T>;template<class T>using vvc=vc<vc<T>>;#define rep(i,n) for(ll i=0;i<(ll)(n);i++)#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)#define drep(i,n) for(ll i=((n)-1);i>=0;i--)#define all(x) x.begin(),x.end()#define rall(x) x.rbegin(),x.rend()template<class T,class F>bool chmin(T &x, F y){if(x>y){x=y;return true;}return false;}template<class T, class F>bool chmax(T &x, F y){if(x<y){x=y;return true;}return false;}double pass_time=0;void solve(){int n,q;cin>>n>>q;vc<int>pre1(n+1);vc<int>pre2(n+1);rep(i,n){char c;cin>>c;pre1[i+1]=pre1[i]+(c=='D');pre2[i+1]=pre2[i]+(c=='R');}dbg(pre1,pre2);auto work=[&](int&x,int&y,int h,int w,int&p){int ac=p,wa=n+1;while(wa-ac>1){int wj=ac+wa>>1;int d1=pre1[wj]-pre1[p];int d2=pre2[wj]-pre2[p];if(x+d1>=h||y+d2>=w)wa=wj;else ac=wj;}int d1=pre1[ac]-pre1[p];int d2=pre2[ac]-pre2[p];x+=d1,y+=d2;p=ac;p%=n;};int C1=0,C2=0;if(pre1.back()==0)C1=pre1.back()=1;if(pre2.back()==0)C2=pre2.back()=1;while(q--){int h,w,p;cin>>h>>w>>p;if(C1)h=2e9;if(C2)w=2e9;int x=0,y=0;work(x,y,h,w,p);if(p){cout<<(p+1)%n<<"\n";continue;;}int U1=(h-1-x)/pre1[n];int U2=(w-1-y)/pre2[n];x+=min(U2,U1)*pre1[n];y+=min(U2,U1)*pre2[n];work(x,y,h,w,p);cout<<(p+1)%n<<"\n";}}signed main(){cin.tie(0)->sync_with_stdio(0);pass_time=clock();int t=1;//cin>>t;while(t--)solve();pass_time=clock()-pass_time;dbg(pass_time/CLOCKS_PER_SEC);}