結果

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

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); 
    int n, q; 
    string s; cin >> n >> q >> s;
    vector<int> dd(n+1), rr(n+1);
    for(int i = 0; i < n; i++){
        if(s[i] == 'D') dd[i+1] += dd[i] + 1;
        else dd[i+1] = dd[i];
        if(s[i] == 'R') rr[i+1] += rr[i] + 1;
        else rr[i+1] = rr[i];
    }
    auto cc = [&](ll c, ll m, ll p, vector<int> dr){
        c += dr[n] * ((p + m) / n) + dr[(p + m) % n];
        c -= dr[n] * (p / n) + dr[p % n];
        return c;
    };
    while(q--){
        ll h, w, p, r, l = 0;
        cin >> h >> w >> p;
        r = h + w;
        while(r - l > 1){
            ll m = (r + l) / 2, cd = 0, cr = 0;
            cd = cc(cd, m, p, dd);
            cr = cc(cr, m, p, rr);
            if(cd >= h || cr >= w) r = m;
            else l = m;
        }
        cout << (p + r) % n << '\n';
    }
    return 0;
}
0