提出 #65503003


ソースコード 拡げる

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

typedef long long ll;
typedef pair<int, int> pii;
constexpr int MAXN = 1'000'007;
constexpr int INF = 2'000'000'000;
constexpr ll INFF = 1'000'000'000'000'000'000LL;
constexpr ll MOD = 998'244'353;
#define mkp make_pair
#define F first
#define S second
#define pb emplace_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    ll ans = 1;
    int curd = 0, curr = 0, curx = 0;
    for (int i = 0; i < n + m - 2; i++) {
      curd += (s[i] == 'D');
      curr += (s[i] == 'R');
      curx += (s[i] == '?');
    }
    int acc = 0;
    for (int i = 0; i < n + m - 2; i++) {
      acc += (s[i] == '?');
      int mn = max(0, ((n - 1) - curd) - (curx - acc));
      int mx = min(acc, (n - 1) - curd);
      ans += max(0, (mx - mn + 1));
    }
    cout << ans << '\n';
  }
}
/*
- How to come up with solutions? (https://hackmd.io/-3cIVAFSQMC3iJTh9EpszA)
  - Play with some small examples.
  - Make observations (or random guesses) by intuition.
    - Try to find counterexamples of the "observations."
  - Find the characteristics of an optimal solution.
  - Try to solve simple cases.
  - Brute force and print out the results.
  - Pick a method (greedy, dp, d&c, ...)
    - But DO NOT force algos on problems!
  - IF YOU'RE STUCK, TRY SOMETHING ELSE! Make new observations!

- Before writing the solution:
  - check TL/ML/correctness of samples/implementation details!

- Pre-submit:
  - Did you make a typo when copying a template?
  - Test more cases if unsure.
    - Write a naive solution and check small cases.
  - Submit the correct file.

- Debugging:
  - General Debugging:
    - Read the whole problem again.
    - Think over the algorithm again.
    - Go to the toilet.

  - Wrong Answer:
    - Any possible overflows?
      - > `__int128` ?
      - Try `-ftrapv` or `#pragma GCC optimize("trapv")`
    - Floating point errors?
      - > `long double` ?
      - turn off math optimizations
      - check for `==`, `>=`, `acos(1.000000001)`, etc.
    - Did you forget to sort or unique?
    - Generate large and worst "corner" cases.
    - Check your `m` / `n`, `i` / `j`,  `x` / `y` and `<` / `>`.
    - Are everything initialized or reset properly?
    - Are you sure about the STL thing you are using?
      - Read cppreference.
    - Print everything and run it on pen and paper.

  - Time Limit Exceeded:
    - Calculate your time complexity again.
    - Does the program actually end?
      - Check for `while(q.size())` etc.
    - Test the largest cases locally.
    - Did you do unnecessary stuff?
      - e.g. pass vectors by value
      - e.g. `memset` for every test case
    - Is your constant factor reasonable?

  - Runtime Error:
    - Check memory usage.
      - Forget to clear or destroy stuff?
      - > `vector::shrink_to_fit()`
    - Stack overflow?
    - Bad pointer / array access?
      - Try `-fsanitize=address`
    - Division by zero? NaN's?
*/

提出情報

提出日時
問題 A - Union of Grid Paths
ユーザ henotrix
言語 C++ 20 (gcc 12.2)
得点 400
コード長 3208 Byte
結果 AC
実行時間 7 ms
メモリ 3800 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 56
セット名 テストケース
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_mid_01.txt, 03_mid_02.txt, 03_mid_03.txt, 03_mid_04.txt, 03_mid_05.txt, 04_max_01.txt, 04_max_02.txt, 04_max_03.txt, 04_max_04.txt, 04_max_05.txt, 04_max_06.txt, 04_max_07.txt, 04_max_08.txt, 04_max_09.txt, 04_max_10.txt, 04_max_11.txt, 04_max_12.txt, 04_max_13.txt, 04_max_14.txt, 04_max_15.txt, 04_max_16.txt, 04_max_17.txt, 04_max_18.txt, 04_max_19.txt, 04_max_20.txt, 04_max_21.txt, 04_max_22.txt, 04_max_23.txt, 04_max_24.txt, 04_max_25.txt, 04_max_26.txt, 04_max_27.txt, 04_max_28.txt, 04_max_29.txt, 04_max_30.txt, 04_max_31.txt, 04_max_32.txt, 04_max_33.txt, 04_max_34.txt, 04_max_35.txt, 04_max_36.txt, 04_max_37.txt, 04_max_38.txt, 04_max_39.txt, 04_max_40.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 1 ms 3388 KiB
02_small_01.txt AC 7 ms 3412 KiB
02_small_02.txt AC 7 ms 3484 KiB
02_small_03.txt AC 7 ms 3324 KiB
02_small_04.txt AC 7 ms 3464 KiB
02_small_05.txt AC 7 ms 3396 KiB
02_small_06.txt AC 7 ms 3528 KiB
02_small_07.txt AC 7 ms 3480 KiB
02_small_08.txt AC 7 ms 3416 KiB
02_small_09.txt AC 7 ms 3460 KiB
02_small_10.txt AC 7 ms 3424 KiB
03_mid_01.txt AC 2 ms 3476 KiB
03_mid_02.txt AC 2 ms 3496 KiB
03_mid_03.txt AC 2 ms 3508 KiB
03_mid_04.txt AC 2 ms 3556 KiB
03_mid_05.txt AC 2 ms 3460 KiB
04_max_01.txt AC 2 ms 3720 KiB
04_max_02.txt AC 2 ms 3644 KiB
04_max_03.txt AC 2 ms 3632 KiB
04_max_04.txt AC 2 ms 3780 KiB
04_max_05.txt AC 2 ms 3636 KiB
04_max_06.txt AC 2 ms 3724 KiB
04_max_07.txt AC 2 ms 3784 KiB
04_max_08.txt AC 2 ms 3688 KiB
04_max_09.txt AC 2 ms 3692 KiB
04_max_10.txt AC 2 ms 3680 KiB
04_max_11.txt AC 2 ms 3700 KiB
04_max_12.txt AC 2 ms 3720 KiB
04_max_13.txt AC 2 ms 3728 KiB
04_max_14.txt AC 2 ms 3724 KiB
04_max_15.txt AC 2 ms 3724 KiB
04_max_16.txt AC 2 ms 3644 KiB
04_max_17.txt AC 2 ms 3732 KiB
04_max_18.txt AC 2 ms 3644 KiB
04_max_19.txt AC 2 ms 3696 KiB
04_max_20.txt AC 2 ms 3732 KiB
04_max_21.txt AC 2 ms 3736 KiB
04_max_22.txt AC 2 ms 3728 KiB
04_max_23.txt AC 2 ms 3740 KiB
04_max_24.txt AC 2 ms 3732 KiB
04_max_25.txt AC 2 ms 3800 KiB
04_max_26.txt AC 2 ms 3728 KiB
04_max_27.txt AC 2 ms 3688 KiB
04_max_28.txt AC 2 ms 3724 KiB
04_max_29.txt AC 3 ms 3728 KiB
04_max_30.txt AC 3 ms 3560 KiB
04_max_31.txt AC 2 ms 3784 KiB
04_max_32.txt AC 2 ms 3660 KiB
04_max_33.txt AC 2 ms 3636 KiB
04_max_34.txt AC 2 ms 3724 KiB
04_max_35.txt AC 2 ms 3744 KiB
04_max_36.txt AC 2 ms 3564 KiB
04_max_37.txt AC 2 ms 3708 KiB
04_max_38.txt AC 2 ms 3784 KiB
04_max_39.txt AC 2 ms 3724 KiB
04_max_40.txt AC 2 ms 3732 KiB