結果

問題 No.329 全射
ユーザー tailstails
提出日時 2015-12-22 01:21:16
言語 Perl
(5.38.2)
結果
TLE  
実行時間 -
コード長 555 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 5,672 KB
実行使用メモリ 9,988 KB
最終ジャッジ日時 2023-10-18 22:24:09
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,988 KB
testcase_01 AC 4 ms
5,640 KB
testcase_02 AC 4 ms
5,644 KB
testcase_03 AC 4 ms
5,644 KB
testcase_04 AC 4 ms
5,652 KB
testcase_05 AC 5 ms
5,652 KB
testcase_06 AC 4 ms
5,652 KB
testcase_07 AC 4 ms
5,652 KB
testcase_08 AC 4 ms
5,652 KB
testcase_09 AC 4 ms
5,652 KB
testcase_10 AC 4 ms
5,640 KB
testcase_11 AC 4 ms
5,640 KB
testcase_12 AC 4 ms
5,652 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

$mod=1e9+7;

sub nok{
	my($n,$k)=@_;
	$nok{$n,$k}//=$k==0||$k==$n?1:(nok($n-1,$k)+nok($n-1,$k-1))%$mod;
}

sub pow{
	my($n,$e)=@_;
	$pow{$n,$e}//=$e==0?1:($e&1?$n:1)*pow($n*$n,$e>>1)%$mod;
}

sub i{<>=~/\d+/g}
($n,$m)=i;
@w=(0,i);
for(1..$m){
	($i,$j)=i;
	push@$i,$j;
}

for$k(1..$n){
	@u=();$u[$k]++;
	@a=[$k,$w[$k]];
	while(@a){
		($l,$s)=@{pop@a};
		$t=$w[$l];
		if($s>=$t){
			for$i(1..$t){
				$r+=(-1)**($t-$i)*nok($t,$i)*pow($i,$s);
				$r%=$mod;
			}
		}

		$s=$t if $s>$t;
		for(@$l){
			if(!$u[$_]++){
				push@a,[$_,$s];
			}
		}
	}
}
print$r;
0