結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2015-07-11 00:06:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 233 ms / 2,000 ms |
コード長 | 1,793 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 67,452 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-08 02:26:04 |
合計ジャッジ時間 | 3,840 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; typedef long long LL; const LL MOD = 1000000007; int main(){ int N; cin >> N; vector<LL> deny; for(int i = 0; i < N; i++){ int d; cin >> d; if(d < N){ deny.push_back(d); } } sort(deny.begin(), deny.end()); vector<LL> cur((N+1)*2); vector<LL> next((N+1)*2); LL prev_deny = -1; cur[0] = 1; for(int i = 1; i <= deny.size(); i++){ for(int u = 0; u < 2; u++){ for(int j = 0; j <= N; j++){ int u2 = u; if(prev_deny != deny[i-1]) u2 = 0; next[j*2 + u2] += cur[j*2 + u]; next[j*2 + u2] %= MOD; } if(u == 0 || prev_deny != deny[i-1]){ for(int j = 0; j+1 <= N; j++){ next[(j+1)*2 + 1] += cur[j*2 + u]; next[(j+1)*2 + 1] %= MOD; } } } prev_deny = deny[i-1]; next.swap(cur); for(int j = 0; j < next.size(); j++){ next[j] = 0; } } vector<LL> pat(N+1); for(int i = 0; i <= N; i++){ pat[i] += cur[i*2 + 0]; pat[i] %= MOD; pat[i] += cur[i*2 + 1]; pat[i] %= MOD; } LL ans = 1; for(int i = 0; i < N; i++){ ans *= (N-i); ans %= MOD; } for(int cnt = 1; cnt <= N; cnt++){ LL tmp = pat[cnt]; for(int i = cnt; i < N; i++){ tmp *= (N-i); tmp %= MOD; } if(cnt % 2 == 1){ ans += MOD - tmp; ans %= MOD; }else{ ans += tmp; ans %= MOD; } } cout << ans << endl; return 0; }