Submission #6539243


Source Code Expand

Copy
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
long long mod_inv(long long a, long long mod = MOD) {
  a %= mod;
  if (__gcd(a, mod) != 1) return -1;
  long long b = mod, x = 1, y = 0;
  while (b > 0) {
    long long tmp = a / b;
    a -= tmp * b;
    swap(a, b);
    x -= tmp * y;
    swap(x, y);
  }
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

const int MAX = 10000000;
long long fact[MAX + 1], fact_inv[MAX + 1];
void nCk_init(int val = MAX, long long mod = MOD) {
  fact[0] = 1;
  FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i % mod;
  fact_inv[val] = mod_inv(fact[val], mod);
  for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i % mod;
}

long long nCk(int n, int k, long long mod = MOD) {
  if (n < 0 || n < k || k < 0) return 0;
  return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  nCk_init();
  int n, m; cin >> n >> m;
  long long ans = 0;
  REP(i, min(n, m) + 1) {
    int gp = 3 * m - i;
    if (gp & 1) continue;
    gp /= 2;
    (ans += nCk(n, i) * nCk(gp + n - 1, n - 1) % MOD) %= MOD;
  }
  long long tmp = 0;
  REP(i, m) (tmp += nCk(i + n - 2, n - 2)) %= MOD;
  (tmp *= n) %= MOD;
  ans -= tmp;
  if (ans < 0) ans += MOD;
  cout << ans << '\n';
  return 0;
}

Submission Info

Submission Time
Task C - GP 2
User emthrm
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2133 Byte
Status AC
Exec Time 353 ms
Memory 156544 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 4
AC × 26
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 327 ms 156544 KB
01-02.txt AC 343 ms 156544 KB
01-03.txt AC 328 ms 156544 KB
01-04.txt AC 336 ms 156544 KB
01-05.txt AC 332 ms 156544 KB
01-06.txt AC 336 ms 156544 KB
01-07.txt AC 341 ms 156544 KB
01-08.txt AC 337 ms 156544 KB
01-09.txt AC 335 ms 156544 KB
01-10.txt AC 349 ms 156544 KB
01-11.txt AC 350 ms 156544 KB
01-12.txt AC 352 ms 156544 KB
01-13.txt AC 333 ms 156544 KB
01-14.txt AC 339 ms 156544 KB
01-15.txt AC 334 ms 156544 KB
01-16.txt AC 353 ms 156544 KB
01-17.txt AC 327 ms 156544 KB
01-18.txt AC 327 ms 156544 KB
01-19.txt AC 326 ms 156544 KB
01-20.txt AC 338 ms 156544 KB
01-21.txt AC 338 ms 156544 KB
01-22.txt AC 339 ms 156544 KB
sample-01.txt AC 326 ms 156544 KB
sample-02.txt AC 327 ms 156544 KB
sample-03.txt AC 326 ms 156544 KB
sample-04.txt AC 329 ms 156544 KB