結果

問題 No.2716 Falcon Method
ユーザー startcppstartcpp
提出日時 2024-04-05 21:41:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 67,992 KB
実行使用メモリ 9,952 KB
最終ジャッジ日時 2024-04-05 21:41:13
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 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 390 ms
9,660 KB
testcase_12 AC 274 ms
9,664 KB
testcase_13 AC 212 ms
9,716 KB
testcase_14 AC 324 ms
8,900 KB
testcase_15 AC 244 ms
9,428 KB
testcase_16 AC 279 ms
8,912 KB
testcase_17 AC 320 ms
9,032 KB
testcase_18 AC 382 ms
9,160 KB
testcase_19 AC 308 ms
8,856 KB
testcase_20 AC 224 ms
9,388 KB
testcase_21 AC 302 ms
8,980 KB
testcase_22 AC 378 ms
9,952 KB
testcase_23 AC 371 ms
9,952 KB
testcase_24 AC 382 ms
9,952 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 402 ms
9,952 KB
testcase_28 AC 381 ms
9,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, q;
string s;
int cntR[400001], cntD[400001];

int solve(int h, int w, int p) {
	int ng = 0, ok = 1e+10, mid;
	while (ok - ng >= 2) {
		mid = (ng + ok) / 2;
		int cR = (mid / n) * cntR[n] + cntR[p + mid % n] - cntR[p];
		int cD = (mid / n) * cntD[n] + cntD[p + mid % n] - cntD[p];
		if (cR >= w || cD >= h) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	return (p + ok) % n;
}

signed main() {
	int i;
	
	cin >> n >> q >> s;
	rep(i, 2 * n) cntR[i + 1] = cntR[i] + (s[i % n] == 'R');
	rep(i, 2 * n) cntD[i + 1] = cntD[i] + (s[i % n] == 'D');
	rep(i, q) {
		int h, w, p;
		cin >> h >> w >> p;
		int ans = solve(h, w, p);
		cout << ans << endl;
	}
	return 0;
}
0