結果

問題 No.2716 Falcon Method
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-04-06 01:06:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 487 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 2,778 ms
コンパイル使用メモリ 204,460 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-06 01:06:42
合計ジャッジ時間 10,919 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 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 5 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 414 ms
6,676 KB
testcase_12 AC 347 ms
6,676 KB
testcase_13 AC 242 ms
6,676 KB
testcase_14 AC 366 ms
6,676 KB
testcase_15 AC 268 ms
6,676 KB
testcase_16 AC 349 ms
6,676 KB
testcase_17 AC 383 ms
6,676 KB
testcase_18 AC 432 ms
6,676 KB
testcase_19 AC 336 ms
6,676 KB
testcase_20 AC 253 ms
6,676 KB
testcase_21 AC 327 ms
6,676 KB
testcase_22 AC 487 ms
6,784 KB
testcase_23 AC 475 ms
6,784 KB
testcase_24 AC 462 ms
6,784 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 474 ms
6,784 KB
testcase_28 AC 468 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    long long n, q;
    string s;
    cin >> n >> q >> s;
    vector<long long> d(n + 1), r(n + 1);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'D') {
            d[i + 1]++;
        } else {
            r[i + 1]++;
        }
    }
    for (int i = 1; i <= n; i++) {
        d[i] += d[i - 1];
        r[i] += r[i - 1];
    }
    auto getd = [&](long long x) {
        return d[n] * (x / n) + d[x % n];
    };
    auto getr = [&](int x) {
        return r[n] * (x / n) + r[x % n];
    };
    while (q--) {
        long long h, w, p;
        cin >> h >> w >> p;
        long long l = 2000000010, r = 0LL;
        while (l - r > 1) {
            long long mid = (l + r) / 2;
            long long cntd = getd(p + mid) - getd(p);
            long long cntr = getr(p + mid) - getr(p);
            if (cntd >= h || cntr >= w) {
                l = mid;
            } else {
                r = mid;
            }
        }
        cout << (p + l) % n << endl;
    }
}
0