結果

問題 No.2716 Falcon Method
ユーザー umimelumimel
提出日時 2024-04-05 22:09:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,951 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 170,720 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-05 22:09:36
合計ジャッジ時間 5,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,548 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 WA -
testcase_09 AC 3 ms
6,548 KB
testcase_10 AC 3 ms
6,548 KB
testcase_11 AC 141 ms
6,656 KB
testcase_12 AC 116 ms
6,656 KB
testcase_13 AC 103 ms
6,656 KB
testcase_14 AC 157 ms
6,548 KB
testcase_15 AC 125 ms
6,548 KB
testcase_16 AC 162 ms
6,548 KB
testcase_17 AC 196 ms
6,548 KB
testcase_18 AC 252 ms
6,548 KB
testcase_19 AC 212 ms
6,548 KB
testcase_20 AC 142 ms
6,548 KB
testcase_21 AC 176 ms
6,548 KB
testcase_22 AC 161 ms
6,784 KB
testcase_23 AC 236 ms
6,784 KB
testcase_24 AC 259 ms
6,784 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 1 ms
6,548 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


void solve(){
    ll n;
    int q;
    cin >> n >> q;
    string s; cin >> s;
    vector<ll> xsum(n, 0), ysum(n, 0);
    for(int i=0; i<n; i++){
        if(i>0){
            xsum[i] = xsum[i-1];
            ysum[i] = ysum[i-1];
        }

        if(s[i]=='D') xsum[i]++;
        else ysum[i]++;
    }

    while(q--){
        ll h, w, p;
        cin >> h >> w >> p;

        // xが先にhに到達
        {
            ll lo = p, hi = 2e9, mid;
            while(hi-lo>1){
                mid = (lo + hi)/2;
                ll x = xsum[n-1]*(mid/n) + xsum[mid%n];
                if(p>0) x -= xsum[p-1];

                if(x>=h) hi = mid;
                else lo = mid;
            }

            ll y = ysum[n-1]*(hi/n) + ysum[hi%n];
            if(p > 0) y -= ysum[p-1];

            if(y < w){
                cout << (hi+1)%n << '\n';
                continue;
            } 
        }
        
        // yが先にwに到達
        {
            ll lo = p-1, hi = 2e9, mid;
            while(hi-lo>1){
                mid = (lo + hi)/2;
                ll y = ysum[n-1]*(mid/n) + ysum[mid%n];
                if(p>0) y -= ysum[p-1];

                if(y>=w) hi = mid;
                else lo = mid;
            }

            cout << (hi+1)%n << '\n';
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0