結果

問題 No.243 出席番号(2)
ユーザー Kmcode1
提出日時 2015-07-11 00:30:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 98,028 KB
実行使用メモリ 55,936 KB
最終ジャッジ日時 2024-07-08 02:28:00
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:60:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |                 scanf("%d", &a);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<cstdio>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
using namespace std;
#define MOD 1000000007
#define MAX 5001
int cnt[MAX];
int n;
vector<long long int> cn;
int dp[MAX][MAX];
long long int k[MAX];
long long int ppow(long long int i, long long int j){
long long int r = 1LL;
while (j){
if ((j & 1LL)){
r *= i;
r %= MOD;
}
i *= i;
i %= MOD;
j >>= 1LL;
}
return r;
}
int main(){
scanf("%d", &n);
k[0] = 1LL;
for (int i = 1; i < MAX; i++){
k[i] = k[i - 1];
k[i] *= (long long int)(i);
k[i] %= MOD;
}
for (int i = 0; i < n; i++){
int a;
scanf("%d", &a);
cnt[a]++;
}
int countt = 0;
for (int i = 0; i < MAX; i++){
if (cnt[i]){
if (i >= n){
countt += cnt[i];
continue;
}
cn.push_back(cnt[i]);
}
}
dp[0][0] = 1LL;
for (int i = 0; i < cn.size(); i++){
for (int j = 0; j <= cn.size(); j++){
dp[i + 1][j+1] += (dp[i][j]*cn[i])%MOD;
dp[i + 1][j] += dp[i][j];
dp[i + 1][j + 1] %= MOD;
dp[i + 1][j] %= MOD;
}
}
long long int ans = 0;
for (int i = 0; i <= cn.size(); i++){
long long int g = 1LL;
if (i % 2 == 1LL){
g = -1LL;
}
long long int way = dp[cn.size()][i] * k[n - i];// *ppow(k[n - i + countt - 1], MOD - 2);
way %= MOD;
if (g == -1){
ans += MOD - way;
ans %= MOD;
}
else{
ans += way;
ans %= MOD;
}
}
//ans *= k[countt];
//ans %= MOD;
printf("%lld\n",ans);
return 0;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1