結果

問題 No.148 試験監督(3)
ユーザー LayCurseLayCurse
提出日時 2015-02-09 22:50:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 1,000 ms
コード長 9,151 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 160,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 16:50:12
合計ジャッジ時間 2,673 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,248 KB
testcase_01 AC 31 ms
5,248 KB
testcase_02 AC 79 ms
5,376 KB
testcase_03 AC 93 ms
5,376 KB
testcase_04 AC 89 ms
5,376 KB
testcase_05 AC 71 ms
5,376 KB
testcase_06 AC 52 ms
5,376 KB
testcase_07 AC 87 ms
5,376 KB
testcase_08 AC 74 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[77000000]; void *mem = memarr;
#define MD 1000000007

int get_inv(ll a, int md){ll t=a,s=md,u=1,v=0,e;while(s){e=t/s;t-=e*s;u-=e*v;swap(t,s);swap(u,v);}if(u<0)u+=md;return u;}

const char *fact_str = "Q%'*86Q$G')Mj#/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`$MC7Nb#*K,8s$L(?,x$1>?|%:C>Gw%A=JCj*&I2y$3E*-S'#D!d;</:|%(?;3d$HNN.r$1B:7|%88L/[%B:'!|0IAF[&>O1I_#B8L9o#8K)Ky$42L,x%%A+KiH6-7X&+/.;|#E3:;S&7HC7b&AA(.w#.)N!~<,OA[&@NHO{#(N&CR%!=)!ZM.I.X##=-,_9LD&^$L>3LZ%I**Hk%@J8Mk#(G.0r#E$>*Z%)9%]%@*:3]%EO#E~'FJ;|-#4Hl%3N+5w&)O?IP,MC;v%7/F:X%<A':u&8,$$y%KDK/W4C?>k%09>Kz#$:6I~&/.:=aI:&<d+G.~9:5=X#K&M1z$1)7X%5D@6n#:3.Dl$DD$(t%6*)J^,DF+e&=06@W#A8>>^#2H/6e$-389f)#@,XK5((k&AB*-Z&GB-5U&6?B)|&.J%A{&2OE7~#;K'%p$88?HU#7D4H`=#':V&B#<J~$4$.A`COOIzFM+,g%/K5BX&6G42h$<NG=Y%=?--{$4J/Ev$=K1Bb?1FKy#H.;Hz#7.4;q&*$:3^%/&.*{#G4C8Y&'065}%OL1Du$FC5Fd218(P&?.MHa&'/7(X#)JLOf%(5:2i#$-=8cOOJ;tC8)j%F4;0]%OA80p$K>*>e&,+5Mv%4#08XPPPP";
template<class T> int extend(const char arr[], T res[]){int i,j,s=1,z=0;static int c[128],f=0;if(f==0)REP(i,33,127)if(i!=34&&i!=92)c[i]=f++;if(arr[0]<' ')return 0;res[0]=0;for(i=0;;i++){if(arr[i]<' ')break;if(c[arr[i]]<46)res[z]=res[z]*46+c[arr[i]];else{res[z]=res[z]*46+c[arr[i]]-46;if(s==-1)res[z]*=-1,s=1;res[++z]=0;}}return z;}

ll fact_memo[1100];
ll get_fact(int n){int i;ll f;f=fact_memo[n/1000000];i=n/1000000*1000000;while(i<n)f=f*(++i)%MD;return f;}

int T;
ll C, P, CC;
char buf[200000];

int main(){
  int i, j, k;
  ll res;

  extend(fact_str, fact_memo);

  reader(&T);
  while(T--){
    C = P = CC = 0;
    
    k = reader(buf);
    rep(i,k){
      C = (C*10+buf[i]-'0') % MD;
      CC = CC*10+buf[i]-'0';
    }
    if(k>15) CC = 1000000000000000000LL;
    
    k = reader(buf);
    rep(i,k) P = P*10 + (buf[i]-'0');
    if(P >= MD || k >= 12){ writerLn(0); continue; }
    if(P > (CC+1)/2){ writerLn(0); continue; }
    
    C = (C+1-P+MD) % MD;
    if(C < P){ writerLn(0); continue; }
    
    res = get_fact(C) * get_inv(get_fact(C-P), MD) % MD;
    writerLn(res);
  }

  return 0;
}
0