結果

問題 No.2716 Falcon Method
ユーザー ttkkggwwttkkggww
提出日時 2024-04-05 21:51:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,336 bytes
コンパイル時間 4,451 ms
コンパイル使用メモリ 264,124 KB
実行使用メモリ 12,232 KB
最終ジャッジ日時 2024-04-05 21:51:43
合計ジャッジ時間 9,280 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
ll N,Q;
string S;
vector<ll> H,W,P;
vector<ll> Rsum,Dsum;
void init(){
    Rsum = vector<ll>(N*2+1);
    Dsum = vector<ll>(N*2+1);
    for(ll i = 0;i<N*2;i++){
        if(S[i]=='R'){
            Rsum[i+1] = Rsum[i]+1;
            Dsum[i+1] = Dsum[i];
        }else{
            Rsum[i+1] = Rsum[i];
            Dsum[i+1] = Dsum[i]+1;
        }
    }
}

pair<ll,ll> query(ll l,ll r){
    pair<ll,ll> res = {0,0};
    ll div = (r-l)/N;
    res = {Dsum[N]*div,Rsum[N]*div};
    r %= N;
    if(r<l){
        r += N;
    }
    res.first += Dsum[r]-Dsum[l];
    res.second += Rsum[r]-Rsum[l];
    return res;
}

void solve2(ll H,ll W,ll P){
    ll ok = P,ng = 1e13;
    while(ng-ok>1){
        ll mid = (ok+ng)/2;
        auto [x,y] = query(P, mid);
        if(x>=H||y>=W){
            ng = mid;
        }else{
            ok = mid;
        }
    }
    cout<<ng%N<<endl;
}

void solve(){
    init();
    for(int i = 0;i<Q;i++){
        solve2(H[i],W[i],P[i]);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>Q;
    cin>>S;
    H = vector<ll>(Q);
    W = vector<ll>(Q);
    P = vector<ll>(Q);
    for(ll i = 0;i<Q;i++)
        cin>>H[i]>>W[i]>>P[i];
    solve();
}
0