結果

問題 No.329 全射
ユーザー TawaraTawara
提出日時 2015-12-24 23:57:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,427 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 89,680 KB
実行使用メモリ 10,868 KB
最終ジャッジ日時 2023-10-19 02:56:53
合計ジャッジ時間 14,324 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,536 KB
testcase_01 AC 11 ms
10,540 KB
testcase_02 AC 11 ms
10,540 KB
testcase_03 AC 12 ms
10,536 KB
testcase_04 AC 11 ms
10,540 KB
testcase_05 AC 11 ms
10,540 KB
testcase_06 AC 11 ms
10,540 KB
testcase_07 AC 11 ms
10,540 KB
testcase_08 AC 11 ms
10,536 KB
testcase_09 AC 11 ms
10,540 KB
testcase_10 AC 11 ms
10,536 KB
testcase_11 AC 11 ms
10,540 KB
testcase_12 AC 12 ms
10,536 KB
testcase_13 WA -
testcase_14 AC 581 ms
10,636 KB
testcase_15 WA -
testcase_16 AC 981 ms
10,864 KB
testcase_17 AC 971 ms
10,780 KB
testcase_18 WA -
testcase_19 AC 1,407 ms
10,788 KB
testcase_20 WA -
testcase_21 AC 1,034 ms
10,780 KB
testcase_22 AC 1,129 ms
10,744 KB
testcase_23 AC 206 ms
10,740 KB
testcase_24 WA -
testcase_25 AC 338 ms
10,764 KB
testcase_26 AC 180 ms
10,696 KB
testcase_27 WA -
testcase_28 AC 12 ms
10,540 KB
testcase_29 AC 23 ms
10,560 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 25 ms
10,560 KB
testcase_33 WA -
testcase_34 AC 14 ms
10,548 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 15 ms
10,548 KB
testcase_39 AC 14 ms
10,548 KB
testcase_40 AC 15 ms
10,548 KB
testcase_41 AC 15 ms
10,544 KB
testcase_42 AC 16 ms
10,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef pair<int,int> PII;
typedef long long LL;

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

#define P 1000000007

LL C[1001][1001];
int w[1000];
LL my_pow(LL b, LL e){
	LL ret = 1, prod = b;
	for (LL inc = e;inc>0;inc>>=1){
		if (inc&1){ret *= prod; ret %= P;}
		prod = prod * prod % P;
	}
	return ret;
}
LL calc(int i, int j){
	LL ret = 0;
	rep(k,w[j]){ret+=(k%2?-1:1)*(C[w[j]][k]*my_pow((LL)w[j]-k,(LL)w[i])%P);ret%=P;}
	return ret;
}
int main(){
	int N,M,x,y,w_min,h;
	LL ans = 0;
	VVI E;
	VI ::iterator it;
	PII tmp;
	map <int,int> V;
	priority_queue <PII, vector<PII> > Q;
	C[0][0] = 1;
	rep(i,1000) 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;
	}
	cin >> N >> M;
	E.resize(N);
	rep(i,N) cin >> w[i];
	rep(i,M){cin >> x >> y;E[--x].push_back(--y);}
	rep(s,N){
		V.clear();
		Q.push(PII(w[s],s));
		while (Q.size()>0){
			tmp = Q.top(); Q.pop();
			w_min = tmp.first; h = tmp.second;
			if (w_min <= V[h]) continue;
			V[h] = w_min;
			if(w[s] >= w[h] and w[h] <= w_min){ans += calc(s,h); ans %= P;} 
			w_min = min(w_min,w[h]);
			for (it=E[h].begin(); it!=E[h].end(); it++) Q.push(PII(w_min,*it));
		}
	}
	cout << ans << endl;
	return 0;
}
0