結果

問題 No.2716 Falcon Method
ユーザー mintmint
提出日時 2024-04-07 20:25:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 949 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 204,860 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-04-07 20:25:21
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,436 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 4 ms
6,676 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;

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