結果
| 問題 |
No.42 貯金箱の溜息
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-21 23:33:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 5,000 ms |
| コード長 | 961 bytes |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 24,832 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 17:07:31 |
| 合計ジャッジ時間 | 699 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | for(scanf("%d",&T);T--;){
| ~~~~~^~~~~~~~~
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%lld",&m);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <stdio.h>
#define M 3000
#define MOD 1000000009
long long pow_binary_mod(long long x,long long y,long long mod){
long long z=1;
for(;y;y>>=1){
if((y&1)!=0)z=z*x%mod;
x=x*x%mod;
}
return z;
}
int Z[6]={1,5,10,50,100,500};
int A[M+1],REV[13];
int main(){
for(int i=-6;i<=6;i++)REV[6+i]=pow_binary_mod((i+MOD)%MOD,MOD-2,MOD);
REV[6]=A[0]=1;
for(int z=0;z<6;z++)for(int i=0;i<=M-Z[z];i++)A[i+Z[z]]+=A[i];
int T;
for(scanf("%d",&T);T--;){
long long m,x,r,s=0,total=1;
scanf("%lld",&m);
if(m<=3000)s=A[m];
else{
x=m/500,r=m%500;
for(int l=0;l<6;++l)total=( (x-l+MOD)%MOD*total%MOD*REV[l+1] )%MOD;
for(int k=0;k<6;k++){
long long p=A[k*500+r];
//for(int l=0;l<6;l++)if(l!=k)p=(x-l+MOD)%MOD*p%MOD*pow_binary_mod(k-l+MOD,MOD-2,MOD)%MOD;
p=p*total%MOD*pow_binary_mod((x-k+MOD)%MOD,MOD-2,MOD)%MOD;
s=(s+p)%MOD;
total=total*REV[k+6+1]%MOD*pow_binary_mod(REV[k+1],MOD-2,MOD)%MOD;
}
}
printf("%lld\n",s);
}
}