提出 #49687223


ソースコード 拡げる

// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define _RREP(i,n) RREPI(i,n,0)
#define RREPI(i,a,b) for(int i=int(a);i>=int(b);--i)
#define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
typedef long long ll;
const int INF32 = 1001001001;
const long long INF64 = 1001001001001001001;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class T> T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; }
template<class T> T lcm(T x, T y){ return x / gcd(x, y) * y; }
template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T> void output(vector<T> v) { for (auto u : v) cout << u << ' '; cout << '\n'; };
void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; }
void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; }
void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; }

// clang-format on
using mint = modint1000000007;

template <typename T> T binomial(int n, int k) {
    if (k < 0 || n < k) return 0;
    static vector<T> fact;
    static vector<T> ifact;
    if ((int)fact.size() < n + 1) {
        int pos = (int)fact.size();
        fact.resize(n + 1);
        for (int i = pos; i <= n; ++i) {
            if (i > 0) {
                fact[i] = i * fact[i - 1];
            } else {
                fact[i] = 1;
            }
        }
    }
    int mx = max(k, n - k);
    if ((int)ifact.size() < mx + 1) {
        int pos = (int)ifact.size();
        ifact.resize(mx + 1);
        ifact[mx] = 1 / fact[mx];
        for (int i = mx - 1; i >= pos; --i) {
            ifact[i] = (i + 1) * ifact[i + 1];
        }
    }
    return fact[n] * ifact[k] * ifact[n - k];
}

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> rc(n);
    REP(i, n) cin >> rc[i].first >> rc[i].second;
    rc.emplace_back(1, 1);
    rc.emplace_back(h, w);
    sort(ALL(rc));
    ++n;
    vector dp(n + 1, vector<mint>(2, 0));
    dp[0][0] = 1;
    REP(i, n) {
        REP(k, 2) {
            REP(j, i + 1, n + 1) {
                auto [ri, ci] = rc[i];
                auto [rj, cj] = rc[j];
                if (ri <= rj && ci <= cj) {
                    int dr = rj - ri;
                    int dc = cj - ci;
                    dp[j][1 - k] += dp[i][k] * binomial<mint>(dr + dc, dr);
                }
            }
        }
    }
    mint ans = dp[n][1] - dp[n][0];
    output(ans.val());
}

提出情報

提出日時
問題 Y - Grid 2
ユーザ noko206
言語 C++ 17 (gcc 12.2)
得点 100
コード長 3161 Byte
結果 AC
実行時間 67 ms
メモリ 5464 KiB

コンパイルエラー

Main.cpp: In instantiation of ‘void output(const T&, const Ts& ...) [with T = unsigned int; Ts = {}]’:
Main.cpp:87:11:   required from here
Main.cpp:26:86: warning: statement has no effect [-Wunused-value]
   26 | template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                      ^~~~

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 22
セット名 テストケース
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17
ケース名 結果 実行時間 メモリ
0_00 AC 1 ms 3464 KiB
0_01 AC 1 ms 3552 KiB
0_02 AC 1 ms 3564 KiB
0_03 AC 3 ms 4448 KiB
1_00 AC 1 ms 3564 KiB
1_01 AC 1 ms 3552 KiB
1_02 AC 3 ms 4628 KiB
1_03 AC 3 ms 4628 KiB
1_04 AC 1 ms 3464 KiB
1_05 AC 8 ms 3700 KiB
1_06 AC 66 ms 4532 KiB
1_07 AC 67 ms 4604 KiB
1_08 AC 67 ms 4916 KiB
1_09 AC 10 ms 4932 KiB
1_10 AC 51 ms 4932 KiB
1_11 AC 48 ms 5272 KiB
1_12 AC 52 ms 5156 KiB
1_13 AC 52 ms 4812 KiB
1_14 AC 50 ms 4652 KiB
1_15 AC 51 ms 5464 KiB
1_16 AC 51 ms 4468 KiB
1_17 AC 50 ms 4996 KiB