結果

問題 No.2716 Falcon Method
ユーザー hongrockhongrock
提出日時 2024-04-05 21:59:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,328 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 202,288 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2024-04-05 21:59:25
合計ジャッジ時間 4,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 54 ms
6,804 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 59 ms
6,676 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 46 ms
6,676 KB
testcase_22 AC 61 ms
6,796 KB
testcase_23 AC 80 ms
6,796 KB
testcase_24 AC 59 ms
6,796 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 81 ms
6,796 KB
testcase_28 AC 83 ms
6,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define pb emplace_back
#define mp make_pair
 
using ll = long long;
using pii = pair<int,int>;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr int N = 4e5 + 10;

int n, Q, d[N], r[N];
string s;

int calc(int *a, int m, int p){
  int r = m % a[n-1];
  if(r == 0)  r = a[n-1];
  if(p != 0)  r += a[p-1];
  return lower_bound(a, a+n*2, r) - a + 1;
}

int solve(int h, int w, int p){
  if(d[n-1] == 0){
    return calc(r, w, p) % n;
  }
  if(r[n-1] == 0){
    return calc(d, h, p) % n;
  }
  int c1, c2;
  if(h % d[n-1] == 0){
    c1 = calc(d, h, p) - p + (h / d[n-1] - 1) * n;
  } else {
    c1 = calc(d, h, p) - p + h / d[n-1] * n;
  }
  if(w % r[n-1] == 0){
    c2 = calc(r, w, p) - p + (w / r[n-1] - 1) * n;
  } else {
    c2 = calc(r, w, p) - p + w / r[n-1] * n;
  }
  if(c1 < c2) return calc(d, h, p) % n;
  return calc(r, w, p) % n;
}

void _main(){
  cin >> n >> Q >> s;
  for(int i=0; i<n; ++i){
    if(s[i] == 'D'){
      d[i] = d[i+n] = 1;
    } else {
      r[i] = r[i+n] = 1;
    }
  }
  for(int i=1; i<n*2; ++i){
    d[i] += d[i-1];
    r[i] += r[i-1];
  }
  int h, w, p;
  while(Q--){
    cin >> h >> w >> p;
    cout << solve(h, w, p) << '\n';
  }
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0