結果
問題 | No.329 全射 |
ユーザー | koyumeishi |
提出日時 | 2015-12-22 12:48:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 3,318 bytes |
コンパイル時間 | 1,203 ms |
コンパイル使用メモリ | 105,116 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-09-18 18:35:23 |
合計ジャッジ時間 | 3,652 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
11,392 KB |
testcase_01 | AC | 9 ms
11,392 KB |
testcase_02 | AC | 8 ms
11,392 KB |
testcase_03 | AC | 8 ms
11,392 KB |
testcase_04 | AC | 8 ms
11,264 KB |
testcase_05 | AC | 9 ms
11,392 KB |
testcase_06 | AC | 8 ms
11,392 KB |
testcase_07 | AC | 8 ms
11,392 KB |
testcase_08 | AC | 9 ms
11,264 KB |
testcase_09 | AC | 9 ms
11,392 KB |
testcase_10 | AC | 8 ms
11,264 KB |
testcase_11 | AC | 8 ms
11,520 KB |
testcase_12 | AC | 8 ms
11,392 KB |
testcase_13 | AC | 133 ms
11,392 KB |
testcase_14 | AC | 70 ms
11,264 KB |
testcase_15 | AC | 65 ms
11,520 KB |
testcase_16 | AC | 36 ms
11,520 KB |
testcase_17 | AC | 93 ms
11,520 KB |
testcase_18 | AC | 93 ms
11,392 KB |
testcase_19 | AC | 154 ms
11,520 KB |
testcase_20 | AC | 120 ms
11,520 KB |
testcase_21 | AC | 95 ms
11,264 KB |
testcase_22 | AC | 158 ms
11,264 KB |
testcase_23 | AC | 14 ms
11,392 KB |
testcase_24 | AC | 16 ms
11,264 KB |
testcase_25 | AC | 31 ms
11,520 KB |
testcase_26 | AC | 25 ms
11,264 KB |
testcase_27 | AC | 10 ms
11,264 KB |
testcase_28 | AC | 8 ms
11,264 KB |
testcase_29 | AC | 10 ms
11,392 KB |
testcase_30 | AC | 9 ms
11,392 KB |
testcase_31 | AC | 9 ms
11,264 KB |
testcase_32 | AC | 10 ms
11,392 KB |
testcase_33 | AC | 9 ms
11,392 KB |
testcase_34 | AC | 9 ms
11,392 KB |
testcase_35 | AC | 9 ms
11,136 KB |
testcase_36 | AC | 8 ms
11,392 KB |
testcase_37 | AC | 9 ms
11,392 KB |
testcase_38 | AC | 9 ms
11,392 KB |
testcase_39 | AC | 9 ms
11,392 KB |
testcase_40 | AC | 9 ms
11,392 KB |
testcase_41 | AC | 9 ms
11,392 KB |
testcase_42 | AC | 9 ms
11,392 KB |
コンパイルメッセージ
main.cpp: In function ‘std::istream& operator>>(std::istream&, std::vector<int>&)’: main.cpp:15:78: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | istream& operator >> (istream& is, vector<int>& vec){for(int& val: vec) scanf("%d", &val); return is;} | ~~~~~^~~~~~~~~~~~ main.cpp: In function ‘std::istream& operator,(std::istream&, int&)’: main.cpp:17:58: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | istream& operator , (istream& is, int& val){ return scanf("%d", &val) , is;} | ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> using namespace std; istream& operator >> (istream& is, vector<int>& vec){for(int& val: vec) scanf("%d", &val); return is;} template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} istream& operator , (istream& is, int& val){ return scanf("%d", &val) , is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" ");return os;} #define MOD 1000000007 class combination_mod{ const long long mod; const long long size; vector<long long> fact; //n! vector<long long> fact_inv; // (n!)^-1 void make_fact(){ fact[0] = 1; for(long long i=1; i<size; i++){ fact[i] = fact[i-1]*i % mod; } } void make_fact_inv(){ fact_inv[0] = fact_inv[1] = 1; for(long long i=2; i<size; i++){ fact_inv[i] = fact_inv[mod%i] * (mod - mod/i) % mod; // x ^ -1 } for(int i=2; i<size; i++){ fact_inv[i] = fact_inv[i-1] * fact_inv[i] % mod; // x! ^ -1 } } public: combination_mod(long long mod_, long long size_ = 2000000) : mod(mod_), size(size_+1){ fact.resize(size); fact_inv.resize(size); make_fact(); make_fact_inv(); } //nCk mod p O(1) long long comb(long long n, long long k){ if(k==0 || n==k) return 1; long long ret = fact[n] * fact_inv[k] % mod * fact_inv[n-k] % mod; return ret; } //n! mod p O(1) long long factorial(long long n){ return fact[n]; } }; long long mod_pow(long long x, long long y/*, long long MOD*/){ //x^y mod MOD long long ret=1LL; while(y>0LL){ if(y&1LL) ret = (ret * x) % MOD; x = (x*x) % MOD; y >>= 1LL; } return ret; } #include <cassert> int main(){ int n,m; cin >> n,m; vector<int> w(n); cin >> w; vector<vector<int>> G(n); for(int i=0; i<m; i++){ int x,y; cin >> x,y; x--; y--; //if(w[x] >= w[y]) { G[x].push_back(y); } } const int len = 1010; combination_mod cmb(MOD, len); /* vector<vector<long long>> dp(len, vector<long long>(len, 0)); for(int i=1; i<len; i++){ for(int j=1; j<=i; j++){ long long tmp = 0; for(int k=1; k<j; k++){ tmp = tmp + dp[i][k] * cmb.comb(j,k); tmp %= MOD; } dp[i][j] = (mod_pow(j,i) - tmp + MOD)%MOD; } } */ vector<vector<long long>> Stirling2(len, vector<long long>(len, 0)); Stirling2[0][0] = 1; for(int i=1; i<len; i++){ for(int j=1; j<=i; j++){ Stirling2[i][j] = (Stirling2[i-1][j-1] + j*Stirling2[i-1][j]) % MOD; } } long long ans=0; for(int i=0; i<n; i++){ vector<int> sz(n, 0); sz[i] = w[i]; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; pq.push({w[i], i}); while(pq.size()){ auto p = pq.top(); pq.pop(); for(int next : G[p.second] ){ int s = min(p.first, w[next]); if(sz[next] >= s) continue; sz[next] = s; pq.push({s,next}); } } for(int j=0; j<n; j++){ if(sz[j]!=w[j]) continue; ans = (ans + Stirling2[w[i]][sz[j]] * cmb.factorial(sz[j]))%MOD; } } cout << ans << endl; return 0; }