結果

問題 No.2716 Falcon Method
ユーザー kk0414
提出日時 2024-04-16 23:20:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,090 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 199,360 KB
最終ジャッジ日時 2025-02-21 02:44:09
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 10 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;


ll p,q;
ll h,w,k;

ll bs(ll l, ll r, vector<ll>&X,ll x){
    if (l>r){
        return r;
    }
    ll m = (l+r)/2;
    ll t = X[p] * ((m+k)/p) + X[(m+k)%p];
    t -= X[p]*(k/p) + X[k%p];

    if (t<x){
        return bs(m+1,r,X,x);
    }
    else {
        return bs(l,m-1,X,x);
    }
}

int main(){
    cin >> p >> q;
    string s;
    cin >> s;
    vector<ll> H (p+1,0);
    vector<ll> W (p+1,0);
    for (int i=0;i<p;i++){
        if (s[i]=='R'){
            H[i+1] = H[i];
            W[i+1] = W[i]+1;
        }
        else if (s[i]=='D'){
            H[i+1] = H[i]+1;
            W[i+1] = W[i];
        }
    }
    
    for (int i=0;i<q;i++){
        cin >> h >> w >> k;
        vector<ll> hw = {h,w};
        ll ans = 100000000000;
        int j = 0;
        for (auto X:{H,W}){
            ll x = hw[j];
            if (X[p]==0){
                continue;
            }
            ll res = bs(0,p,X,x);
            ans = min(ans,res);
            j++;
        }
        cout << (ans+k+1)%p << endl;
    }

    }
0