結果

問題 No.2716 Falcon Method
ユーザー fextivityfextivity
提出日時 2024-04-05 21:51:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 205,488 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 21:51:45
合計ジャッジ時間 4,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 57 ms
6,676 KB
testcase_12 AC 52 ms
6,676 KB
testcase_13 AC 41 ms
6,676 KB
testcase_14 AC 62 ms
6,676 KB
testcase_15 AC 46 ms
6,676 KB
testcase_16 AC 55 ms
6,676 KB
testcase_17 AC 63 ms
6,676 KB
testcase_18 AC 75 ms
6,676 KB
testcase_19 AC 56 ms
6,676 KB
testcase_20 AC 44 ms
6,676 KB
testcase_21 AC 48 ms
6,676 KB
testcase_22 AC 63 ms
6,676 KB
testcase_23 AC 78 ms
6,676 KB
testcase_24 AC 64 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 79 ms
6,676 KB
testcase_28 AC 80 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#if __cplusplus < 202002L
template <class T> int ssize(const T& a){ return a.size(); }
#endif
template <class T1, class T2> istream& operator>> (istream& in, pair <T1, T2>& a){ in >> a.first >> a.second; return in; }
template <class T> istream& operator>> (istream& in, vector <T>& a){ for (auto &x: a){ in >> x; } return in; }

using ll = long long;
using ld = long double;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	if (fopen("KEK.inp", "r")){
		freopen("KEK.inp", "r", stdin);
		freopen("KEK.out", "w", stdout);
	}
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;

	vector <int> a, b;
	for (auto i = 0; i < n; i++){
		if (s[i] == 'D'){
			a.emplace_back(i);
		}
		else{
			b.emplace_back(i);
		}
	}

	constexpr int inf = 1e9 + 7;
	while (q--){
		int h, w, i;
		cin >> h >> w >> i;

		int ans = -1;
		auto jump = [&](){
			int cnt_h = ssize(a) - (lower_bound(begin(a), end(a), i) - begin(a));
			int cnt_w = ssize(b) - (lower_bound(begin(b), end(b), i) - begin(b));
			if (h > cnt_h and w > cnt_w){
				h -= cnt_h;
				w -= cnt_w;
				i = 0;
				return;
			}
			int pos = n;
			if (h <= cnt_h){
				pos = min(pos, *(lower_bound(begin(a), end(a), i) + h - 1));
			}
			if (w <= cnt_w){
				pos = min(pos, *(lower_bound(begin(b), end(b), i) + w - 1));
			}
			ans = pos + 1;
			if (ans >= n){
				ans -= n;
			}
		};

		jump();
		if (ans == -1){
			int loop = min(a.empty() ? inf : (h - 1) / ssize(a), b.empty() ? inf : (w - 1) / ssize(b));
			h -= loop * ssize(a);
			w -= loop * ssize(b);
			jump();
		}

		cout << ans << "\n";
	}
}
0