結果

問題 No.2716 Falcon Method
ユーザー ecotteaecottea
提出日時 2024-01-29 17:06:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 203,952 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-29 17:06:15
合計ジャッジ時間 8,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 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 3 ms
6,676 KB
testcase_11 AC 258 ms
6,676 KB
testcase_12 AC 197 ms
6,676 KB
testcase_13 AC 139 ms
6,676 KB
testcase_14 AC 240 ms
6,676 KB
testcase_15 AC 153 ms
6,676 KB
testcase_16 AC 188 ms
6,676 KB
testcase_17 AC 219 ms
6,676 KB
testcase_18 AC 265 ms
6,676 KB
testcase_19 AC 200 ms
6,676 KB
testcase_20 AC 150 ms
6,676 KB
testcase_21 AC 218 ms
6,676 KB
testcase_22 AC 254 ms
6,676 KB
testcase_23 AC 252 ms
6,676 KB
testcase_24 AC 277 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 243 ms
6,676 KB
testcase_28 AC 250 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS

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


int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, q; string s;
	cin >> n >> q >> s;

	// '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;

		// 移動回数を二分探索する.
		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