提出 #39058686


ソースコード 拡げる

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 998244353
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
    int res = 1;
    while(k)
    {
        if(k & 1) Mul(res, x);
        Sqr(x), k >>= 1;
    }
    return res;
}
const int N = 6e7 + 5;
int n, x, y, z, ans;
int fac[N], facinv[N];
void preprocess()
{
    fac[0] = facinv[0] = 1;
    for(int i = 1; i < N; ++i)
        fac[i] = mul(fac[i - 1], i);
    facinv[N - 1] = qwqmi(fac[N - 1]);
    for(int i = N - 2; i >= 1; --i)
        facinv[i] = mul(facinv[i + 1], i + 1);
}
int binom(int n, int m)
{
    if(n < m) return 0;
    return mul(fac[n], mul(facinv[m], facinv[n - m]));
}
int main()
{
    preprocess();
    scanf("%d %d %d %d", &n, &x, &y, &z);
    if(x < 0) x = -x;
    if(y < 0) y = -y;
    if(z < 0) z = -z;
    if((n & 1) ^ ((x + y + z) & 1))
    {
        puts("0");
        return 0;
    }
    if(n < x + y + z)
    {
        puts("0");
        return 0;
    }
    int w = (n - x - y - z) / 2;
    for(int S = 0; S <= w; ++S)
    {
        int v = mul(fac[n], mul(facinv[S], mul(facinv[x + y + S], facinv[n - x - y - 2 * S])));
        Mul(v, binom(x + y + 2 * S, y + S)); Mul(v, binom(z + 2 * w - 2 * S, w - S));
        Inc(ans, v);
    }
    printf("%d\n", ans);
    return 0;
}

提出情報

提出日時
問題 G - Teleporting Takahashi
ユーザ Schucking_Sattin
言語 C++ (GCC 9.2.1)
得点 600
コード長 2252 Byte
結果 AC
実行時間 878 ms
メモリ 472516 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:56:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   56 |     scanf("%d %d %d %d", &n, &x, &y, &z);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 60
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, example0.txt, example1.txt, example2.txt
ケース名 結果 実行時間 メモリ
000.txt AC 791 ms 472200 KiB
001.txt AC 762 ms 472212 KiB
002.txt AC 764 ms 472196 KiB
003.txt AC 768 ms 472388 KiB
004.txt AC 766 ms 472416 KiB
005.txt AC 765 ms 472200 KiB
006.txt AC 878 ms 472424 KiB
007.txt AC 766 ms 472236 KiB
008.txt AC 768 ms 472240 KiB
009.txt AC 872 ms 472448 KiB
010.txt AC 763 ms 472512 KiB
011.txt AC 765 ms 472372 KiB
012.txt AC 767 ms 472328 KiB
013.txt AC 768 ms 472392 KiB
014.txt AC 767 ms 472304 KiB
015.txt AC 767 ms 472304 KiB
016.txt AC 764 ms 472396 KiB
017.txt AC 766 ms 472448 KiB
018.txt AC 765 ms 472396 KiB
019.txt AC 765 ms 472428 KiB
020.txt AC 764 ms 472268 KiB
021.txt AC 766 ms 472500 KiB
022.txt AC 762 ms 472320 KiB
023.txt AC 768 ms 472304 KiB
024.txt AC 764 ms 472396 KiB
025.txt AC 765 ms 472516 KiB
026.txt AC 768 ms 472424 KiB
027.txt AC 768 ms 472200 KiB
028.txt AC 769 ms 472312 KiB
029.txt AC 768 ms 472204 KiB
030.txt AC 769 ms 472200 KiB
031.txt AC 763 ms 472332 KiB
032.txt AC 793 ms 472424 KiB
033.txt AC 778 ms 472268 KiB
034.txt AC 833 ms 472380 KiB
035.txt AC 765 ms 472268 KiB
036.txt AC 767 ms 472272 KiB
037.txt AC 774 ms 472424 KiB
038.txt AC 797 ms 472500 KiB
039.txt AC 789 ms 472448 KiB
040.txt AC 803 ms 472268 KiB
041.txt AC 782 ms 472428 KiB
042.txt AC 830 ms 472328 KiB
043.txt AC 786 ms 472420 KiB
044.txt AC 829 ms 472500 KiB
045.txt AC 798 ms 472400 KiB
046.txt AC 817 ms 472420 KiB
047.txt AC 829 ms 472508 KiB
048.txt AC 858 ms 472384 KiB
049.txt AC 832 ms 472452 KiB
050.txt AC 834 ms 472416 KiB
051.txt AC 817 ms 472400 KiB
052.txt AC 765 ms 472328 KiB
053.txt AC 770 ms 472200 KiB
054.txt AC 763 ms 472320 KiB
055.txt AC 763 ms 472384 KiB
056.txt AC 765 ms 472200 KiB
example0.txt AC 768 ms 472444 KiB
example1.txt AC 767 ms 472316 KiB
example2.txt AC 764 ms 472300 KiB