結果
問題 | No.2716 Falcon Method |
ユーザー |
|
提出日時 | 2024-04-05 21:51:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 1,609 bytes |
コンパイル時間 | 2,097 ms |
コンパイル使用メモリ | 197,752 KB |
最終ジャッジ日時 | 2025-02-20 21:14:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:24: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | freopen("KEK.inp", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:18:24: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | freopen("KEK.out", "w", stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;#if __cplusplus < 202002Ltemplate <class T> int ssize(const T& a){ return a.size(); }#endiftemplate <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";}}