結果
問題 |
No.2716 Falcon Method
|
ユーザー |
|
提出日時 | 2024-04-05 21:47:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 956 bytes |
コンパイル時間 | 2,087 ms |
コンパイル使用メモリ | 198,492 KB |
最終ジャッジ日時 | 2025-02-20 21:09:07 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 18 RE * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main () { int N, Q; cin >> N >> Q; string s; cin >> s; std::vector<ll> sum[2]; string key = "DR"; for (int i = 0; i < 2; i ++) { sum[i].resize(N + 1); sum[i][0] = 0; for (int j = 0; j < N; j ++) { sum[i][j + 1] = sum[i][j] + (key[i] == s[j]); } } while (Q--) { int h, w, p; cin >> h >> w >> p; ll Ls[] = {h, w}; ll ans = (ll)1e18; for (int q = 0; q < 2; q ++) { if (sum[q][N] - sum[q][p] >= Ls[q]) { auto pt = lower_bound(sum[q].begin(), sum[q].end(), Ls[q] + sum[q][p]); ll d = pt - sum[q].begin(); d -= p; ans = min(ans, d); } else { ll goal = Ls[q] - sum[q][p]; ll pl = N - p; pl += ((goal - 1) / sum[q][N]) * N; goal = (goal - 1) % sum[q][N] + 1; auto pt = lower_bound(sum[q].begin(), sum[q].end(), Ls[q]); pl += pt - sum[q].begin(); ans = min(ans, pl); } } cout << (ans + p) % N << endl; } }