結果

問題 No.2716 Falcon Method
ユーザー Today03Today03
提出日時 2024-04-05 21:50:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 560 ms / 2,000 ms
コード長 1,273 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 205,996 KB
実行使用メモリ 14,520 KB
最終ジャッジ日時 2024-04-05 21:50:16
合計ジャッジ時間 9,724 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 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 AC 455 ms
13,960 KB
testcase_12 AC 355 ms
13,972 KB
testcase_13 AC 249 ms
14,144 KB
testcase_14 AC 388 ms
12,268 KB
testcase_15 AC 302 ms
13,608 KB
testcase_16 AC 335 ms
12,308 KB
testcase_17 AC 418 ms
12,716 KB
testcase_18 AC 495 ms
13,144 KB
testcase_19 AC 344 ms
12,120 KB
testcase_20 AC 283 ms
13,460 KB
testcase_21 AC 374 ms
12,528 KB
testcase_22 AC 447 ms
14,520 KB
testcase_23 AC 532 ms
14,520 KB
testcase_24 AC 560 ms
14,520 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 452 ms
14,520 KB
testcase_28 AC 433 ms
14,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<vector<int>> cnt(N + 1, vector<int>(2, 0));
    for (int i = 0; i < N; i++) {
        cnt[i + 1][0] = cnt[i][0];
        cnt[i + 1][1] = cnt[i][1];
        if (S[i] == 'D') {
            cnt[i + 1][0]++;
        } else {
            cnt[i + 1][1]++;
        }
    }

    while (Q--) {
        ll H, W, P;
        cin >> H >> W >> P;

        ll lo = 0, hi = 1ll * INF * 3;
        while (hi - lo > 1) {
            ll mid = (lo + hi) / 2;

            ll cycle = mid / N;
            ll rem = (P + mid) % N;

            ll nx = 0, ny = 0;
            nx += cnt[N][0] * cycle;
            ny += cnt[N][1] * cycle;

            if (P <= rem) {
                nx += cnt[rem][0] - cnt[P][0];
                ny += cnt[rem][1] - cnt[P][1];
            } else {
                nx += cnt[N][0] - cnt[P][0] + cnt[rem][0];
                ny += cnt[N][1] - cnt[P][1] + cnt[rem][1];
            }

            if (nx < H && ny < W) {
                lo = mid;
            } else {
                hi = mid;
            }
        }

        cout << (P + hi) % N << '\n';
    }
}
0