Submission #30922085


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr bool operator==(const modint& r) const { return a == r.a; }
  constexpr bool operator!=(const modint& r) const { return a != r.a; }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator-() const { return modint(0) - modint(*this); }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

using fp = modint<998244353>;

#include <vector>
#include <tuple>
using i64 = long long;

template<class T>
struct factorial {
  std::vector<T> fact;
  std::vector<T> finv;
  std::vector<T> inv;

  void build(int N) {
    fact.resize(N);
    finv.resize(N);
    inv.resize(N);
    fact[0] = T(1);
    for(int i = 1;i < N;i++) {
      fact[i] = fact[i - 1] * T(i);
    }
    finv[N - 1] = T(1) / fact[N - 1];
    for(int i = N - 1; i --> 0;) {
      finv[i] = finv[i + 1] * T(i + 1);
    }
    for(int i = 0;i < N;i++) {
      inv[i] = fact[i - 1] * finv[i];
    }
  }

  T binom(int n, int r) const {
    if(0 <= r && r <= n) return fact[n] * finv[n - r] * finv[r];
    else return T(0);
  }

  std::tuple<const std::vector<T>&, const std::vector<T>&, const std::vector<T>&> get() const {
    return std::tuple<const std::vector<T>&, const std::vector<T>&, const std::vector<T>&>(fact, finv, inv);
  }
};


factorial<fp> fact;

int main() {
  i64 N, M;
  cin >> N >> M;
  i64 p, q, r;
  cin >> p >> q >> r;

  fact.build(N * 2);

  vector<fp> acc(M);
  rep(i,0,N + 1) acc[i % M] += fact.binom(N, i);

  fp sum = 0;
  rep(i,0,M) {
    i64 j = (p - i + M + N) % M;
    i64 k = (q - i + M + N) % M;
    if((j + k - N % M + M) % M == r) {
      sum += acc[i] * acc[j] * acc[k];
    }
  }
  cout << sum << endl;
}

Submission Info

Submission Time
Task K - One or All
User niuez
Language C++ (GCC 9.2.1)
Score 500
Code Size 4303 Byte
Status AC
Exec Time 100 ms
Memory 57884 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:112:3: note: in expansion of macro ‘rep’
  112 |   rep(i,0,N + 1) acc[i % M] += fact.binom(N, i);
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:115:3: note: in expansion of macro ‘rep’
  115 |   rep(i,0,M) {
      |   ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 87
Set Name Test Cases
Sample sample_00, sample_01, sample_02
All sample_00, sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_21, testcase_22, testcase_23, testcase_24, testcase_25, testcase_26, testcase_27, testcase_28, testcase_29, testcase_3, testcase_30, testcase_31, testcase_32, testcase_33, testcase_34, testcase_35, testcase_36, testcase_37, testcase_38, testcase_39, testcase_4, testcase_40, testcase_41, testcase_42, testcase_43, testcase_44, testcase_45, testcase_46, testcase_47, testcase_48, testcase_49, testcase_5, testcase_50, testcase_51, testcase_52, testcase_53, testcase_54, testcase_55, testcase_56, testcase_57, testcase_58, testcase_59, testcase_6, testcase_60, testcase_61, testcase_62, testcase_63, testcase_64, testcase_65, testcase_66, testcase_67, testcase_68, testcase_69, testcase_7, testcase_70, testcase_71, testcase_72, testcase_73, testcase_74, testcase_75, testcase_76, testcase_77, testcase_78, testcase_79, testcase_8, testcase_80, testcase_81, testcase_82, testcase_83, testcase_9
Case Name Status Exec Time Memory
sample_00 AC 7 ms 3596 KiB
sample_01 AC 2 ms 3372 KiB
sample_02 AC 67 ms 50228 KiB
testcase_0 AC 67 ms 50132 KiB
testcase_1 AC 68 ms 50152 KiB
testcase_10 AC 66 ms 50092 KiB
testcase_11 AC 67 ms 50056 KiB
testcase_12 AC 67 ms 50000 KiB
testcase_13 AC 65 ms 50136 KiB
testcase_14 AC 68 ms 49980 KiB
testcase_15 AC 67 ms 49976 KiB
testcase_16 AC 65 ms 50056 KiB
testcase_17 AC 67 ms 49984 KiB
testcase_18 AC 95 ms 57776 KiB
testcase_19 AC 94 ms 57636 KiB
testcase_2 AC 67 ms 50140 KiB
testcase_20 AC 94 ms 57880 KiB
testcase_21 AC 97 ms 57884 KiB
testcase_22 AC 100 ms 57788 KiB
testcase_23 AC 95 ms 57804 KiB
testcase_24 AC 96 ms 57792 KiB
testcase_25 AC 93 ms 57640 KiB
testcase_26 AC 67 ms 50180 KiB
testcase_27 AC 65 ms 50152 KiB
testcase_28 AC 71 ms 49976 KiB
testcase_29 AC 67 ms 50224 KiB
testcase_3 AC 67 ms 50176 KiB
testcase_30 AC 66 ms 50096 KiB
testcase_31 AC 64 ms 50224 KiB
testcase_32 AC 66 ms 50040 KiB
testcase_33 AC 72 ms 49984 KiB
testcase_34 AC 47 ms 21448 KiB
testcase_35 AC 18 ms 8344 KiB
testcase_36 AC 32 ms 11588 KiB
testcase_37 AC 60 ms 42492 KiB
testcase_38 AC 69 ms 46960 KiB
testcase_39 AC 59 ms 37896 KiB
testcase_4 AC 68 ms 50228 KiB
testcase_40 AC 91 ms 54112 KiB
testcase_41 AC 43 ms 30116 KiB
testcase_42 AC 48 ms 35200 KiB
testcase_43 AC 55 ms 35968 KiB
testcase_44 AC 29 ms 19432 KiB
testcase_45 AC 50 ms 28228 KiB
testcase_46 AC 36 ms 22932 KiB
testcase_47 AC 38 ms 14400 KiB
testcase_48 AC 71 ms 46000 KiB
testcase_49 AC 51 ms 31748 KiB
testcase_5 AC 66 ms 49980 KiB
testcase_50 AC 59 ms 34284 KiB
testcase_51 AC 65 ms 46364 KiB
testcase_52 AC 43 ms 22680 KiB
testcase_53 AC 84 ms 50248 KiB
testcase_54 AC 54 ms 34204 KiB
testcase_55 AC 63 ms 38968 KiB
testcase_56 AC 84 ms 50652 KiB
testcase_57 AC 58 ms 29452 KiB
testcase_58 AC 92 ms 55808 KiB
testcase_59 AC 80 ms 50932 KiB
testcase_6 AC 66 ms 50000 KiB
testcase_60 AC 57 ms 38176 KiB
testcase_61 AC 18 ms 9872 KiB
testcase_62 AC 54 ms 38788 KiB
testcase_63 AC 75 ms 46436 KiB
testcase_64 AC 41 ms 17300 KiB
testcase_65 AC 78 ms 49036 KiB
testcase_66 AC 49 ms 22864 KiB
testcase_67 AC 46 ms 26560 KiB
testcase_68 AC 37 ms 24700 KiB
testcase_69 AC 33 ms 11060 KiB
testcase_7 AC 64 ms 50124 KiB
testcase_70 AC 40 ms 19804 KiB
testcase_71 AC 12 ms 5632 KiB
testcase_72 AC 89 ms 53556 KiB
testcase_73 AC 35 ms 11492 KiB
testcase_74 AC 65 ms 32308 KiB
testcase_75 AC 85 ms 51624 KiB
testcase_76 AC 66 ms 37820 KiB
testcase_77 AC 64 ms 31908 KiB
testcase_78 AC 26 ms 9384 KiB
testcase_79 AC 40 ms 19068 KiB
testcase_8 AC 66 ms 50060 KiB
testcase_80 AC 17 ms 10784 KiB
testcase_81 AC 44 ms 19072 KiB
testcase_82 AC 39 ms 24112 KiB
testcase_83 AC 33 ms 16780 KiB
testcase_9 AC 65 ms 50060 KiB