提出 #67788367


ソースコード 拡げる

#include<bits/stdc++.h>
typedef long double ld;
typedef long long ll;
#define nl '\n'
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define per(i,a,b) for(int i = (a); i >= (b); i--)
#define repl(i,a,b) for(ll i = (a); i < (b); i++)
#define perl(i,a,b) for(ll i = (a); i >= (b); i--)
using namespace std;
const ll MOD = 1000000007, MOD2 = 998244353, mod = MOD2;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N=5e5+5;
ll fct[N],inv[N],invfct[N];
ll ncr(ll n,ll r){
    if(n<0 || r<0 || n-r<0)return 0;
    ll ans = fct[n]*invfct[r];
    ans%=mod;
    ans = ans * invfct[n-r];
    ans%=mod;
    return ans;
}
void init(){
    fct[0]=fct[1]=1;
    inv[1]=1;
    invfct[0]=invfct[1]=1;
    for(ll i=2;i<N;i++){
        fct[i]=i*fct[i-1]%mod;
        inv[i]=ll(mod-inv[mod%i])*(mod/i)%mod;
        invfct[i]=ll(inv[i])*invfct[i-1]%mod;
    }
}
void solve(){
    ll n,m; cin>>n>>m;
    if(n%2==0){cout<<0<<nl; return;}
    ll ans = 0;
    if(m&1){
        repl(t,0,n+1){
            ll sum = abs(t-(n-t));
            ll ways = ncr(n, t);
            if(__gcd(sum, m) == 1) ans = (ans + ways) % mod;
        }
    }
    else{
        repl(t,0,2*n+1){
            ll sum = abs((t - (2*n-t))/2);
            ll ways = ncr(2*n, t);
            if(__gcd(sum, m/2) == 1) ans = (ans + ways) % mod;
        }
    }
    cout<<ans<<nl;
}

int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    init();
    //int __; cin>>__; while(__--) solve();
    solve();
    return 0;
}

提出情報

提出日時
問題 B - Japanese "Knight's Tour"
ユーザ invertedwinger
言語 C++ 20 (gcc 12.2)
得点 800
コード長 1694 Byte
結果 AC
実行時間 38 ms
メモリ 15324 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 800 / 800
結果
AC × 3
AC × 41
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 03_max_04.txt, 03_max_05.txt, 03_max_06.txt, 03_max_07.txt, 03_max_08.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 11 ms 15272 KiB
00_sample_01.txt AC 10 ms 15316 KiB
00_sample_02.txt AC 11 ms 15232 KiB
01_small_00.txt AC 10 ms 15316 KiB
01_small_01.txt AC 10 ms 15160 KiB
01_small_02.txt AC 10 ms 15268 KiB
01_small_03.txt AC 11 ms 15216 KiB
01_small_04.txt AC 10 ms 15180 KiB
01_small_05.txt AC 11 ms 15156 KiB
01_small_06.txt AC 10 ms 15192 KiB
01_small_07.txt AC 10 ms 15136 KiB
01_small_08.txt AC 10 ms 15076 KiB
02_random_00.txt AC 11 ms 15220 KiB
02_random_01.txt AC 24 ms 15224 KiB
02_random_02.txt AC 10 ms 15080 KiB
02_random_03.txt AC 18 ms 15180 KiB
02_random_04.txt AC 11 ms 15192 KiB
02_random_05.txt AC 29 ms 15076 KiB
02_random_06.txt AC 24 ms 15220 KiB
02_random_07.txt AC 15 ms 15136 KiB
02_random_08.txt AC 13 ms 15188 KiB
02_random_09.txt AC 15 ms 15196 KiB
02_random_10.txt AC 35 ms 15200 KiB
02_random_11.txt AC 29 ms 15200 KiB
02_random_12.txt AC 13 ms 15220 KiB
02_random_13.txt AC 16 ms 15220 KiB
02_random_14.txt AC 11 ms 15320 KiB
02_random_15.txt AC 32 ms 15172 KiB
02_random_16.txt AC 21 ms 15160 KiB
02_random_17.txt AC 24 ms 15184 KiB
02_random_18.txt AC 25 ms 15172 KiB
02_random_19.txt AC 11 ms 15200 KiB
03_max_00.txt AC 11 ms 15196 KiB
03_max_01.txt AC 10 ms 15196 KiB
03_max_02.txt AC 10 ms 15192 KiB
03_max_03.txt AC 38 ms 15264 KiB
03_max_04.txt AC 24 ms 15324 KiB
03_max_05.txt AC 37 ms 15260 KiB
03_max_06.txt AC 11 ms 15224 KiB
03_max_07.txt AC 11 ms 15316 KiB
03_max_08.txt AC 10 ms 15080 KiB