結果

問題 No.2572 Midori on the grid
ユーザー binapbinap
提出日時 2023-12-02 16:45:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 457 ms / 5,000 ms
コード長 2,402 bytes
コンパイル時間 4,584 ms
コンパイル使用メモリ 266,824 KB
実行使用メモリ 13,672 KB
最終ジャッジ日時 2023-12-02 16:45:19
合計ジャッジ時間 9,468 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 457 ms
13,672 KB
testcase_01 AC 217 ms
9,392 KB
testcase_02 AC 356 ms
11,016 KB
testcase_03 AC 326 ms
10,516 KB
testcase_04 AC 166 ms
7,040 KB
testcase_05 AC 352 ms
11,036 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

using mint = modint998244353;

// combination mod prime
// https://youtu.be/8uowVvQ_-Mo?t=6002
// https://youtu.be/Tgd_zLfRZOQ?t=9928
struct modinv {
  int n; vector<mint> d;
  modinv(): n(2), d({0,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} invs;
struct modfact {
  int n; vector<mint> d;
  modfact(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*n), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} facts;
struct modfactinv {
  int n; vector<mint> d;
  modfactinv(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*invs(n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} ifacts;
mint comb(int n, int k) {
  if (n < k || k < 0) return 0;
  return facts(n)*ifacts(k)*ifacts(n-k);
}

int main(){
	int x, y, q;
	cin >> x >> y >> q;
	vl t(q);
	cin >> t;
	if(y < x){
		swap(x, y);
		rep(i, q) t[i] *= -1;
	}
	rep(i, q){
		if(t[i] >= 0 and t[i] <= y - x){
			cout << 0 << "\n";
			continue;
		}
		if(t[i] < 0) t[i] = y - x - t[i];
		mint ans = comb(y + x, y);
		if(t[i] <= y) ans -= comb(y + x, y - t[i]);
		cout << ans << "\n";
	}
	return 0;
}
0