結果

問題 No.2716 Falcon Method
ユーザー shobonvipshobonvip
提出日時 2024-04-06 09:30:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 4,644 ms
コンパイル使用メモリ 263,232 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2024-04-06 09:30:31
合計ジャッジ時間 12,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
6,676 KB
testcase_11 AC 379 ms
9,560 KB
testcase_12 AC 297 ms
9,572 KB
testcase_13 AC 228 ms
9,720 KB
testcase_14 AC 343 ms
8,576 KB
testcase_15 AC 247 ms
9,392 KB
testcase_16 AC 324 ms
8,576 KB
testcase_17 AC 340 ms
8,876 KB
testcase_18 AC 397 ms
9,116 KB
testcase_19 AC 331 ms
8,576 KB
testcase_20 AC 241 ms
9,260 KB
testcase_21 AC 323 ms
8,704 KB
testcase_22 AC 397 ms
9,920 KB
testcase_23 AC 408 ms
9,920 KB
testcase_24 AC 415 ms
9,920 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 425 ms
9,920 KB
testcase_28 AC 396 ms
9,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<ll> rui_down(2 * n + 1);
	vector<ll> rui_right(2 * n + 1);
	rep(i,0,2 * n){
		rui_down[i+1] += rui_down[i];
		rui_right[i+1] += rui_right[i];
		if (s[i % n] == 'D') rui_down[i+1]++;
		else rui_right[i+1]++;
	}

	auto steps = [&](ll times, ll p) -> pair<ll,ll> {
		ll f = times / n;
		ll g = times % n;
		ll down = f * (rui_down[n + p] - rui_down[p]) + rui_down[g + p] - rui_down[p];
		ll right = f * (rui_right[n + p] - rui_right[p]) + rui_right[g + p] - rui_right[p];
		return pair(down, right);
	};

	auto check_border = [&](ll h, ll w, ll p) -> ll {
		ll ub = 3e9;
		ll lb = -1;
		while (ub - lb > 1){
			ll t = (ub + lb) / 2;
			pair<ll,ll> x = steps(t, p);
			if (x.first < h && x.second < w) lb = t;
			else ub = t;
		}
		return (ub + p) % n;
	};

	while(q--){
		ll h, w, p; cin >> h >> w >> p;
		cout << check_border(h, w, p) << '\n';
	}
}

0