結果

問題 No.329 全射
ユーザー TawaraTawara
提出日時 2015-12-25 15:33:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 901 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 53,176 KB
実行使用メモリ 22,808 KB
最終ジャッジ日時 2023-10-19 03:34:47
合計ジャッジ時間 9,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
22,476 KB
testcase_01 AC 14 ms
22,476 KB
testcase_02 AC 14 ms
22,476 KB
testcase_03 AC 14 ms
22,476 KB
testcase_04 AC 14 ms
22,476 KB
testcase_05 AC 15 ms
22,476 KB
testcase_06 AC 14 ms
22,480 KB
testcase_07 AC 14 ms
22,476 KB
testcase_08 AC 14 ms
22,476 KB
testcase_09 AC 14 ms
22,476 KB
testcase_10 AC 13 ms
22,476 KB
testcase_11 AC 14 ms
22,476 KB
testcase_12 AC 14 ms
22,476 KB
testcase_13 AC 837 ms
22,728 KB
testcase_14 AC 313 ms
22,576 KB
testcase_15 AC 461 ms
22,708 KB
testcase_16 AC 703 ms
22,804 KB
testcase_17 AC 600 ms
22,720 KB
testcase_18 AC 901 ms
22,808 KB
testcase_19 AC 880 ms
22,728 KB
testcase_20 AC 842 ms
22,724 KB
testcase_21 AC 695 ms
22,720 KB
testcase_22 AC 650 ms
22,684 KB
testcase_23 AC 164 ms
22,680 KB
testcase_24 AC 140 ms
22,672 KB
testcase_25 AC 251 ms
22,704 KB
testcase_26 AC 116 ms
22,636 KB
testcase_27 AC 26 ms
22,524 KB
testcase_28 AC 14 ms
22,480 KB
testcase_29 AC 20 ms
22,500 KB
testcase_30 AC 19 ms
22,500 KB
testcase_31 AC 14 ms
22,476 KB
testcase_32 AC 21 ms
22,500 KB
testcase_33 AC 15 ms
22,484 KB
testcase_34 AC 15 ms
22,484 KB
testcase_35 AC 16 ms
22,484 KB
testcase_36 AC 15 ms
22,484 KB
testcase_37 AC 15 ms
22,484 KB
testcase_38 AC 15 ms
22,484 KB
testcase_39 AC 15 ms
22,484 KB
testcase_40 AC 15 ms
22,484 KB
testcase_41 AC 15 ms
22,484 KB
testcase_42 AC 15 ms
22,488 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         scanf("%d%d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         rep(i,N)scanf("%d",w+i);
      |                 ~~~~~^~~~~~~~~~
main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         rep(i,M){scanf("%d%d",&x,&y);E[--x].push_back(--y);}
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)
#define P 1000000007
#define W 1001

LL C[W][W],F[W][W];
int w[W-1],V[W][W];
vector < vector <int> > E;
LL mpow(LL b,LL e){LL r=1;for(;e>0;e>>=1){if(e&1)r=r*b%P;b=b*b%P;}return r;}
LL calc(LL a,LL b){LL r=0;rep(k,b)r=(r+(k%2?-1:1)*C[b][k]*mpow(b-k,a)%P+P)%P;return r;}
int main(){
	int N,M,x,y,h,m;LL A=0;
	priority_queue <PII, vector<PII> > Q;
	C[0][0]=1;
	rep(i,W-1)rep(j,i+1){C[i+1][j]=(C[i][j]+C[i+1][j])%P;C[i+1][j+1]=(C[i][j]+C[i+1][j+1])%P;}
	rep(i,W)rep(j,W)F[i][j]=V[i][j]=0;
	scanf("%d%d",&N,&M);
	E.resize(N);
	rep(i,N)scanf("%d",w+i);
	rep(i,M){scanf("%d%d",&x,&y);E[--x].push_back(--y);}
	rep(s,N){
		Q.push(PII(w[s],s));
		while(Q.size()){
			PII t=Q.top();Q.pop();
			m=t.first;h=t.second;
			if(m<=V[s][h])continue;
			V[s][h]=m;
			if(w[s]>=w[h]&&w[h]<=m)F[w[s]][w[h]]++;
			m=min(m,w[h]);
			for(auto it:E[h])Q.push(PII(m,it));
		}
	}
	rep(i,W)rep(j,i+1)if(F[i][j]>0){A=(A+F[i][j]*calc(i,j))%P;}
	printf("%lld\n",A);
	return 0;
}
0