結果

問題 No.2716 Falcon Method
ユーザー ecotteaecottea
提出日時 2024-01-28 19:09:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 692 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 204,344 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-28 19:11:35
合計ジャッジ時間 14,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 684 ms
6,676 KB
testcase_12 AC 627 ms
6,676 KB
testcase_13 AC 531 ms
6,676 KB
testcase_14 AC 644 ms
6,676 KB
testcase_15 AC 581 ms
6,676 KB
testcase_16 AC 550 ms
6,676 KB
testcase_17 AC 680 ms
6,676 KB
testcase_18 AC 672 ms
6,676 KB
testcase_19 AC 632 ms
6,676 KB
testcase_20 AC 635 ms
6,676 KB
testcase_21 AC 594 ms
6,676 KB
testcase_22 AC 662 ms
6,676 KB
testcase_23 AC 692 ms
6,676 KB
testcase_24 AC 655 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 653 ms
6,676 KB
testcase_28 AC 657 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS

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


int main() {
	int n, q; string s;
	cin >> n >> q >> s;

	assert(1 <= n && n <= (int)2e5);
	assert(1 <= q && q <= (int)2e5);
	for (int i = 0; i < n; i++) assert(s[i] == 'D' || s[i] == 'R');

	// 'D', 'R' の個数の累積和の前計算
	vector<int> d(n + 1), r(n + 1);
	for (int i = 0; i < n; i++) {
		d[i + 1] = d[i] + (s[i] == 'D');
		r[i + 1] = r[i] + (s[i] == 'R');
	}

	for (int j = 0; j < q; j++) {
		long long h, w; int p;
		cin >> h >> w >> p;

		assert(1 <= h && h <= (long long)1e9);
		assert(1 <= w && w <= (long long)1e9);
		assert(0 <= p && p < n);

		// 移動回数を二分探索する.
		long long ok = h + w, ng = 0;
		while (ok - ng > 1) {
			long long mid = (ok + ng) / 2;

			// s[p], ..., s[p+k-1] に含まれる 'D' の個数
			long long d_cnt = 0;
			d_cnt += d[n] * ((p + mid) / n) + d[(p + mid) % n];
			d_cnt -= d[n] * (p / n) + d[p % n];

			// s[p], ..., s[p+k-1] に含まれる 'R' の個数
			long long r_cnt = 0;
			r_cnt += r[n] * ((p + mid) / n) + r[(p + mid) % n];
			r_cnt -= r[n] * (p / n) + r[p % n];

			// 'D' が h 個以上または 'R' が w 個以上なら x = h または y = w となっている.
			if (d_cnt >= h || r_cnt >= w) ok = mid;
			else ng = mid;
		}

		// 移動した分だけカウンタを進める.
		cout << (p + ok) % n << endl;
	}
}
0