結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 5 ms
6,676 KB
testcase_11 AC 328 ms
6,676 KB
testcase_12 AC 244 ms
6,676 KB
testcase_13 AC 189 ms
6,676 KB
testcase_14 AC 297 ms
6,676 KB
testcase_15 AC 208 ms
6,676 KB
testcase_16 AC 254 ms
6,676 KB
testcase_17 AC 296 ms
6,676 KB
testcase_18 AC 352 ms
6,676 KB
testcase_19 AC 264 ms
6,676 KB
testcase_20 AC 203 ms
6,676 KB
testcase_21 AC 274 ms
6,676 KB
testcase_22 AC 351 ms
6,676 KB
testcase_23 AC 349 ms
6,676 KB
testcase_24 AC 343 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 368 ms
6,676 KB
testcase_28 AC 354 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)1e5);
	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