結果

問題 No.329 全射
ユーザー tailstails
提出日時 2015-12-22 12:18:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 886 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 2,681 ms
コンパイル使用メモリ 165,136 KB
実行使用メモリ 9,252 KB
最終ジャッジ日時 2023-10-18 22:34:04
合計ジャッジ時間 10,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,848 KB
testcase_01 AC 2 ms
5,848 KB
testcase_02 AC 2 ms
5,856 KB
testcase_03 AC 2 ms
5,848 KB
testcase_04 AC 2 ms
5,856 KB
testcase_05 AC 2 ms
5,848 KB
testcase_06 AC 2 ms
5,856 KB
testcase_07 AC 2 ms
5,848 KB
testcase_08 AC 2 ms
5,852 KB
testcase_09 AC 2 ms
5,856 KB
testcase_10 AC 2 ms
5,848 KB
testcase_11 AC 2 ms
5,852 KB
testcase_12 AC 2 ms
5,852 KB
testcase_13 AC 763 ms
9,248 KB
testcase_14 AC 630 ms
9,244 KB
testcase_15 AC 533 ms
9,248 KB
testcase_16 AC 620 ms
9,240 KB
testcase_17 AC 685 ms
9,236 KB
testcase_18 AC 674 ms
9,248 KB
testcase_19 AC 836 ms
9,244 KB
testcase_20 AC 743 ms
9,252 KB
testcase_21 AC 715 ms
9,248 KB
testcase_22 AC 886 ms
9,244 KB
testcase_23 AC 29 ms
9,196 KB
testcase_24 AC 28 ms
9,188 KB
testcase_25 AC 33 ms
9,188 KB
testcase_26 AC 29 ms
9,184 KB
testcase_27 AC 23 ms
9,184 KB
testcase_28 AC 16 ms
8,636 KB
testcase_29 AC 22 ms
9,180 KB
testcase_30 AC 17 ms
8,688 KB
testcase_31 AC 5 ms
7,012 KB
testcase_32 AC 20 ms
8,940 KB
testcase_33 AC 19 ms
9,192 KB
testcase_34 AC 19 ms
9,200 KB
testcase_35 AC 19 ms
9,184 KB
testcase_36 AC 19 ms
9,176 KB
testcase_37 AC 20 ms
9,216 KB
testcase_38 AC 19 ms
9,188 KB
testcase_39 AC 20 ms
9,216 KB
testcase_40 AC 20 ms
9,188 KB
testcase_41 AC 20 ms
9,216 KB
testcase_42 AC 20 ms
9,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:25:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         for(i=1;i<=n;++i)scanf("%d",w+i);
      |                          ~~~~~^~~~~~~~~~
main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf("%d%d",&i,&j);
      |                 ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

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

#define mod 1000000007

int noktbl[1010][1010];
int nok(int n,int k){
	if(!noktbl[n][k]){
		noktbl[n][k]=k==0||k==n?1:(nok(n-1,k)+nok(n-1,k-1))%mod;
	}
	return noktbl[n][k];
}

long long mpow(long long n,int e){
	return e?(e&1?n:1)*mpow(n*n%mod,e/2)%mod:1;
}

priority_queue<int> a;
int w[210],ln[210][210],li[210],u[210];
int rtbl[1010][1010];

int main(){
	int i,j,k,l,m,n,r,s,t;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)scanf("%d",w+i);
	for(k=0;k<m;++k){
		scanf("%d%d",&i,&j);
		ln[i][li[i]++]=j;
	}
	r=0;

	for(k=1;k<=n;++k){
		memset(u,0,sizeof u);
		u[k]=w[k];
		a.push(k|w[k]<<8);
		while(!a.empty()){
			l=a.top();a.pop();
			s=l>>8;
			l&=255;
			for(i=0;j=ln[l][i];++i){
				t=min(s,w[j]);
				if(u[j]<t){
					u[j]=t;
					a.push(j|t<<8);
				}
			}
		}
		s=w[k];
		for(l=1;l<=n;++l){
			if((t=u[l])&&t==w[l]){
				if(!rtbl[s][t]){
					long long h=0;
					for(i=1;i<=t;++i){
						h=(mpow(i,s)*nok(t,i)-h+mod)%mod;
					}
					rtbl[s][t]=h;
				}
				r=(r+rtbl[s][t])%mod;
			}
		}
	}

	printf("%d",r);
}
0