結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー tatuyan_edsontatuyan_edson
提出日時 2016-03-21 15:26:24
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 21:22:39
合計ジャッジ時間 5,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,548 KB
testcase_01 AC 0 ms
6,548 KB
testcase_02 AC 0 ms
6,548 KB
testcase_03 AC 0 ms
6,548 KB
testcase_04 AC 160 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 0 ms
6,548 KB
testcase_07 AC 0 ms
6,548 KB
testcase_08 AC 0 ms
6,548 KB
testcase_09 AC 174 ms
6,548 KB
testcase_10 AC 21 ms
6,548 KB
testcase_11 AC 174 ms
6,548 KB
testcase_12 AC 8 ms
6,548 KB
testcase_13 AC 56 ms
6,548 KB
testcase_14 AC 20 ms
6,548 KB
testcase_15 AC 24 ms
6,548 KB
testcase_16 AC 73 ms
6,548 KB
testcase_17 AC 117 ms
6,548 KB
testcase_18 AC 108 ms
6,548 KB
testcase_19 AC 0 ms
6,548 KB
testcase_20 AC 0 ms
6,548 KB
testcase_21 AC 1 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 0 ms
6,548 KB
testcase_24 AC 0 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 1 ms
6,548 KB
testcase_27 AC 1 ms
6,548 KB
testcase_28 AC 1 ms
6,548 KB
testcase_29 AC 1 ms
6,548 KB
testcase_30 AC 1 ms
6,548 KB
testcase_31 AC 1 ms
6,548 KB
testcase_32 AC 0 ms
6,548 KB
testcase_33 AC 1 ms
6,548 KB
testcase_34 AC 1 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 AC 0 ms
6,548 KB
testcase_37 AC 0 ms
6,548 KB
testcase_38 AC 1 ms
6,548 KB
testcase_39 AC 1 ms
6,548 KB
testcase_40 AC 1 ms
6,548 KB
testcase_41 AC 1 ms
6,548 KB
testcase_42 AC 0 ms
6,548 KB
testcase_43 AC 0 ms
6,548 KB
testcase_44 AC 1 ms
6,548 KB
testcase_45 AC 0 ms
6,548 KB
testcase_46 AC 1 ms
6,548 KB
testcase_47 AC 0 ms
6,548 KB
testcase_48 AC 1 ms
6,548 KB
testcase_49 AC 32 ms
6,548 KB
testcase_50 AC 2 ms
6,548 KB
testcase_51 AC 2 ms
6,548 KB
testcase_52 AC 6 ms
6,548 KB
testcase_53 AC 4 ms
6,548 KB
testcase_54 AC 7 ms
6,548 KB
testcase_55 AC 1 ms
6,548 KB
testcase_56 AC 3 ms
6,548 KB
testcase_57 AC 14 ms
6,548 KB
testcase_58 AC 27 ms
6,548 KB
testcase_59 AC 20 ms
6,548 KB
testcase_60 AC 9 ms
6,548 KB
testcase_61 AC 43 ms
6,548 KB
testcase_62 AC 10 ms
6,548 KB
testcase_63 AC 27 ms
6,548 KB
testcase_64 AC 7 ms
6,548 KB
testcase_65 AC 5 ms
6,548 KB
testcase_66 AC 8 ms
6,548 KB
testcase_67 AC 8 ms
6,548 KB
testcase_68 AC 7 ms
6,548 KB
testcase_69 AC 84 ms
6,548 KB
testcase_70 AC 37 ms
6,548 KB
testcase_71 AC 61 ms
6,548 KB
testcase_72 AC 23 ms
6,548 KB
testcase_73 AC 45 ms
6,548 KB
testcase_74 AC 65 ms
6,548 KB
testcase_75 AC 56 ms
6,548 KB
testcase_76 AC 19 ms
6,548 KB
testcase_77 AC 115 ms
6,548 KB
testcase_78 AC 5 ms
6,548 KB
testcase_79 AC 0 ms
6,548 KB
testcase_80 AC 0 ms
6,548 KB
testcase_81 AC 0 ms
6,548 KB
testcase_82 AC 0 ms
6,548 KB
testcase_83 AC 0 ms
6,548 KB
testcase_84 AC 1 ms
6,548 KB
testcase_85 AC 0 ms
6,548 KB
testcase_86 AC 1 ms
6,548 KB
testcase_87 AC 0 ms
6,548 KB
testcase_88 AC 1 ms
6,548 KB
testcase_89 AC 36 ms
6,548 KB
testcase_90 AC 62 ms
6,548 KB
testcase_91 AC 113 ms
6,548 KB
testcase_92 AC 15 ms
6,548 KB
testcase_93 AC 68 ms
6,548 KB
testcase_94 AC 2 ms
6,548 KB
testcase_95 AC 72 ms
6,548 KB
testcase_96 AC 56 ms
6,548 KB
testcase_97 AC 51 ms
6,548 KB
testcase_98 AC 23 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   scanf("%llu%*c",&M);
      |   ^~~~~~~~~~~~~~~~~~~
main.c:16:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     scanf("%llu%c",&temp,&c);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

unsigned long long const modnum=1000000007;

unsigned long long invdiv(unsigned long long p);

int main(void){
  unsigned long long M,S=0,n=0,ans=1;
  unsigned long long alls,rest,temp;
  unsigned long long i,j,k;
  char c;

  scanf("%llu%*c",&M);
  do{
    scanf("%llu%c",&temp,&c);
    S+=temp;
    n++;
  }while(c==' ');

  if(S+n-1>M) puts("NA");
  else if(S==0) puts("1");
  else{
    alls=M-S+1;
    rest=alls-n;

    for(i=1;i<=alls;i++){
      ans*=i;
      ans%=modnum;
    }
    for(i=1;i<=rest;i++){
      ans*=invdiv(i);
      ans%=modnum;
    }
    for(i=1;i<=n;i++){
      ans*=invdiv(i);
      ans%=modnum;
    }
    printf("%llu\n",ans);
  }
  return 0;
}


unsigned long long invdiv(unsigned long long p) {
	unsigned long long r[3], q;
	unsigned long long x[3];
	div_t clc;

	r[0] = p;
	r[1] = modnum;

	x[0] = 1;
	x[1] = 0;

	do {
		clc = div(r[0], r[1]);
		q = clc.quot;
		r[2] = clc.rem;
		while(x[0] < q * x[1]) x[0] += modnum;
		x[2] = (x[0] - q * x[1]) % modnum;

		r[0] = r[1];
		r[1] = r[2];

		x[0] = x[1];
		x[1] = x[2];
	} while(r[2] > 1);
	return x[2];
}
0