結果
| 問題 | No.3572 Number of special equations |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-16 23:40:49 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,766 bytes |
| 記録 | |
| コンパイル時間 | 2,042 ms |
| コンパイル使用メモリ | 332,476 KB |
| 実行使用メモリ | 25,984 KB |
| 最終ジャッジ日時 | 2026-06-19 20:51:18 |
| 合計ジャッジ時間 | 6,082 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 8 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=998244353;
const long long FACSIZE=1048576;
long long power(long long a,long long b){
long long x=1,y=a;
while(b>0){
if(b&1ll){
x=(x*y)%mod;
}
y=(y*y)%mod;
b>>=1;
}
return x%mod;
}
long long modular_inverse(long long n){
return power(n,mod-2);
}
long long factorial[FACSIZE];
long long invfact[FACSIZE];
void cfact(){
long long i;
factorial[0]=1;
factorial[1]=1;
for(i=2;i<FACSIZE;i++){
factorial[i]=factorial[i-1]*i;
factorial[i]%=mod;
}
invfact[FACSIZE-1]=modular_inverse(factorial[FACSIZE-1]);
for(i=FACSIZE-2;i>=0;i--){
invfact[i]=invfact[i+1]*(i+1);
invfact[i]%=mod;
}
}
long long calcnCr(long long n,long long k){
if(k<0 || n<k){return 0;}
return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}
int main(){
cfact();
ll N;
cin >> N;
ll res=1;
for(ll n=1;n<=N;n++){
if(n%2==1){
ll pn=(n/2);
for(ll a=0;a<=N;a++){
for(ll b=1;a+b<=N;b++){
ll rem=N-a-b;
if(pn==0){
if(rem==0){res++;}
continue;
}
if(rem>=pn*2 && rem%2==0){
rem/=2; rem-=pn;
res+=calcnCr(rem+pn-1,pn-1); res%=mod;
}
}
}
}
else{
ll pn=(n/2)-1;
for(ll a=0;a<=N;a++){
for(ll b=1;a+b<=N;b++){
for(ll c=1;a+b+c<=N;c++){
ll rem=N-a-b-c;
if(pn==0){
if(rem==0){res++;}
continue;
}
if(rem>=pn*2 && rem%2==0){
rem/=2; rem-=pn;
res+=calcnCr(rem+pn-1,pn-1); res%=mod;
}
}
}
}
}
}
cout << res%mod << "\n";
return 0;
}