結果

問題 No.2716 Falcon Method
ユーザー Shreyan RayShreyan Ray
提出日時 2024-04-05 21:45:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 2,303 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 205,360 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-05 21:45:52
合計ジャッジ時間 4,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 40 ms
6,676 KB
testcase_12 AC 53 ms
6,676 KB
testcase_13 AC 38 ms
6,676 KB
testcase_14 AC 57 ms
6,676 KB
testcase_15 AC 41 ms
6,676 KB
testcase_16 AC 49 ms
6,676 KB
testcase_17 AC 56 ms
6,676 KB
testcase_18 AC 66 ms
6,676 KB
testcase_19 AC 50 ms
6,676 KB
testcase_20 AC 40 ms
6,676 KB
testcase_21 AC 34 ms
6,676 KB
testcase_22 AC 44 ms
6,784 KB
testcase_23 AC 68 ms
6,784 KB
testcase_24 AC 44 ms
6,784 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 68 ms
6,784 KB
testcase_28 AC 68 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
    int n, q;
    cin >> n >> q;
    
    string s; cin >> s;
    vector <int> p1(n + 1, 0), p2(n + 1, 0);
    for (int i = 1; i <= n; i++){
        p1[i] = p1[i - 1] + (s[i - 1] == 'D');
        p2[i] = p2[i - 1] + (s[i - 1] == 'R');
    }
    
    while (q--){
        int h, w, p; cin >> h >> w >> p;
        p++;
        
        if (p1[n] == 0){
            int steps = w - 1;
            p += steps;
            cout << (p % n) << "\n";
            continue;
        }
        
        if (p2[n] == 0){
            int steps = h - 1;
            p += steps;
            cout << (p % n) << "\n";
            continue;
        }
        
        // can you go whole route? 
        
        int x = 0, y = 0;
        if (x + p1[n] - p1[p - 1] < h && y + p2[n] - p2[p - 1] < w){
            x += p1[n] - p1[p - 1];
            y += p2[n] - p2[p - 1];
            
            int d1 = h - x - 1;
            int d2 = w - y - 1;
            
            int g1 = d1 / p1[n];
            int g2 = d2 / p2[n];
            
            int g = min(g1, g2);
            x += g * p1[n];
            y += g * p2[n];
            
            p = 1;
        } 
        
       // cout << x << " " << y << " " << p << "\n";
        
        int l = p, r = n;
        while (l != r){
            int mid = (l + r) / 2;
            
            if (x + p1[mid] - p1[p - 1] < h && y + p2[mid] - p2[p - 1] < w){
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        
        cout << (l % n) << "\n";
    }
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // freopen("in",  "r", stdin);
    // freopen("out", "w", stdout);
    
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0