結果

問題 No.2716 Falcon Method
ユーザー planesplanes
提出日時 2024-04-05 22:46:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 170,464 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-05 22:46:08
合計ジャッジ時間 7,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 3 ms
6,548 KB
testcase_06 AC 4 ms
6,548 KB
testcase_07 AC 4 ms
6,548 KB
testcase_08 AC 4 ms
6,548 KB
testcase_09 AC 5 ms
6,548 KB
testcase_10 AC 4 ms
6,548 KB
testcase_11 AC 316 ms
6,656 KB
testcase_12 AC 213 ms
6,656 KB
testcase_13 AC 164 ms
6,656 KB
testcase_14 AC 257 ms
6,548 KB
testcase_15 AC 179 ms
6,548 KB
testcase_16 AC 256 ms
6,548 KB
testcase_17 AC 261 ms
6,548 KB
testcase_18 AC 310 ms
6,548 KB
testcase_19 AC 223 ms
6,548 KB
testcase_20 AC 182 ms
6,548 KB
testcase_21 AC 257 ms
6,548 KB
testcase_22 AC 290 ms
6,784 KB
testcase_23 AC 299 ms
6,784 KB
testcase_24 AC 343 ms
6,784 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 288 ms
6,784 KB
testcase_28 AC 288 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
ll N,Q;cin>>N>>Q;
string S;cin>>S;

vector<ll> x(N+1),y(N+1);

for(ll i=0;i<N;i++) {
  x[i+1]=x[i];
  y[i+1]=y[i];
  if(S[i]=='D') x[i+1]++;
  else y[i+1]++;
}






for(ll i=0;i<Q;i++) {
  ll H,W,P;cin>>H>>W>>P;

  //何回の移動?

  ll s=0;
  ll g=1000000000000000;

  while(s<g) {
    ll X=0,Y=0;

    //<=の最小

    ll k=(s+g)/2;
    ll K=k;


    ll noko=N-P;

    if(noko<=k) {
      X+=x[N]-x[P];
      Y+=y[N]-y[P];
      k-=N-P;
    }
    else {
      X+=x[P+k]-x[P];
      Y+=y[P+k]-y[P];
      k=0;
    }
    
    ll count=k/N;
    k%=N;
    X+=x[N]*count;
    Y+=y[N]*count;

    if(k>0) {
      X+=x[k];
      Y+=y[k];
    k=0;
    }
  
  if(X>=H||Y>=W) {
    g=K;
  }

  else s=K+1;
  }


  ll k=s;
  ll noko=N-P;
  ll X=0,Y=0;



  if(noko<=k) {
      X+=x[N]-x[P];
      Y+=y[N]-y[P];
      k-=N-P;
    }

    else {
      X+=x[P+k]-x[P];
      Y+=y[P+k]-y[P];
      k=0;
    }
    
    ll count=k/N;
    k%=N;
    X+=x[N]*count;
    Y+=y[N]*count;

    if(k>0) {
      X+=x[k];
      Y+=y[k];
    k=0;
    }

    


  

    cout<<(P+s)%N<<endl;
}


}


0