結果
問題 | No.2716 Falcon Method |
ユーザー |
![]() |
提出日時 | 2024-04-06 09:30:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 342 ms / 2,000 ms |
コード長 | 1,953 bytes |
コンパイル時間 | 3,677 ms |
コンパイル使用メモリ | 251,808 KB |
最終ジャッジ日時 | 2025-02-20 22:28:57 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#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';}}