結果

問題 No.2716 Falcon Method
ユーザー kk0414kk0414
提出日時 2024-04-17 22:32:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,152 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 201,564 KB
実行使用メモリ 18,204 KB
最終ジャッジ日時 2024-04-17 22:33:00
合計ジャッジ時間 6,092 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

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 l;
    }
    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];
        }
    }
    
    vector<ll> hw;
    ll ans;
    int j;
    ll x;
    ll res;

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

    }
0