結果
| 問題 | No.329 全射 |
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-12-25 18:21:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,000 ms |
| コード長 | 948 bytes |
| 記録 | |
| コンパイル時間 | 300 ms |
| コンパイル使用メモリ | 36,936 KB |
| 実行使用メモリ | 20,620 KB |
| 最終ジャッジ日時 | 2024-09-18 23:56:50 |
| 合計ジャッジ時間 | 4,810 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d%d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:27:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | rep(i,N) scanf("%d",w+i);
| ~~~~~^~~~~~~~~~
main.cpp:29:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | rep(i,M){scanf("%d%d",&x,&y);x--;E[x][--y]=w[x];}
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <stdio.h>
using namespace std;
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
#define W 1001
LL C[W][W],F[W][W];
int w[W-1],E[W-1][W-1];
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;LL A=0;
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]=0;
scanf("%d%d",&N,&M);
rep(i,N) scanf("%d",w+i);
rep(i,N){rep(j,N)E[i][j]=0; E[i][i]=w[i];}
rep(i,M){scanf("%d%d",&x,&y);x--;E[x][--y]=w[x];}
rep(k,N) rep(i,N) rep(j,N) E[i][j]=max(E[i][j],min(E[i][k],E[k][j]));
rep(i,N) rep(j,N) if(w[j]<=E[i][j]) F[w[i]][w[j]]++;
rep(i,W) rep(j,i+1) if(F[i][j]){A=(A+F[i][j]*calc(i,j))%P;}
printf("%lld\n",A);
return 0;
}
Tawara