結果

問題 No.2716 Falcon Method
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-05 21:51:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 205,112 KB
実行使用メモリ 7,004 KB
最終ジャッジ日時 2024-04-05 21:51:32
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 177 ms
6,856 KB
testcase_12 AC 118 ms
6,856 KB
testcase_13 AC 94 ms
6,864 KB
testcase_14 AC 144 ms
6,676 KB
testcase_15 AC 103 ms
6,676 KB
testcase_16 AC 126 ms
6,676 KB
testcase_17 AC 148 ms
6,676 KB
testcase_18 AC 174 ms
6,676 KB
testcase_19 AC 145 ms
6,676 KB
testcase_20 AC 99 ms
6,676 KB
testcase_21 AC 130 ms
6,676 KB
testcase_22 AC 161 ms
7,004 KB
testcase_23 AC 165 ms
7,004 KB
testcase_24 AC 162 ms
7,004 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 159 ms
7,004 KB
testcase_28 AC 184 ms
7,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N,Q; cin >> N >> Q;
    string s; cin >> s;
    int D = 0,R = 0;
    for(auto c : s){
        if(c == 'D') D++;
        else R++; 
    }
    s += s;

    vector<int> sumd(2*N),sumr(2*N);
    for(int i=0; i<2*N; i++){
        if(s.at(i) == 'D') sumd.at(i)++;
        else sumr.at(i)++;
    }
    for(int i=1; i<2*N; i++) sumd.at(i) += sumd.at(i-1),sumr.at(i) += sumr.at(i-1);

    while(Q--){
        int h,w,p; cin >> h >> w >> p;
        int hl = 2e9,wl = 2e9;
        if(D) hl = (h-1)/D;
        if(R) wl = (w-1)/R;

        h -= min(hl,wl)*D;
        w -= min(hl,wl)*R;
        
        int ph = 0,pw = 0;
        if(p) ph = sumd.at(p-1),pw = sumr.at(p-1);

        int low = p-1,high = p+N;
        while(high-low > 1){
            int mid = (high+low)/2;
            int nowh = sumd.at(mid)-ph,noww = sumr.at(mid)-pw;
            if(nowh >= h || noww >= w) high = mid;
            else low = mid;
        }
        high++;
        cout << high%N << endl;    
    }
}
0