結果
| 問題 |
No.794 チーム戦 (2)
|
| コンテスト | |
| ユーザー |
koi_kotya
|
| 提出日時 | 2019-02-22 22:51:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,774 bytes |
| コンパイル時間 | 1,556 ms |
| コンパイル使用メモリ | 173,076 KB |
| 実行使用メモリ | 7,016 KB |
| 最終ジャッジ日時 | 2024-11-25 17:22:10 |
| 合計ジャッジ時間 | 8,103 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 10 RE * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1e9+7;
#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];
ll pow_mod(ll a,ll b) {
ll ret;
if (b < 0) ret = pow_mod(a,mod+b-1);
else if (b == 0) ret = 1;
else if (b == 1) ret = a;
else {
ll c = pow_mod(a,b/2);
if (b%2) ret = (c*c)%mod*a%mod;
else ret = c*c%mod;
}
return ret;
}
void create_table(int n) {
fact[0] = 1;fact[1] = 1;
for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
fact_inv[n] = pow_mod(fact[n],mod-2);
for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
for (int i = 1;i <= n;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}
int main() {
int n,k;
ll ans = 1;
cin >> n >> k;
vector<int> a(n),b(n,0);
for (int i = 0;i < n;++i) cin >> a[i];
sort(a.begin(),a.end());
bool ok = true;
for (int i = 0;i < n/2;++i) if (a[i]+a[n-i-1] > k) ok = false;
if (!ok) ans = 0;
int j = n-1;
for (int i = 0;i < n;++i) {
while (j >= 0 && a[i]+a[j] > k) j--;
b[i] = max(n/2,j+1);
}
for (int i = 0;i < n-1;++i) if (a[i]+a[i+1] < k) j = (2*i+4-n)/2;
for (int i = 0;i < n;++i) {
ans *= b[n-1-i]-i;
ans %= mod;
}
create_table(n);
ans *= fact_inv[n/2];
ans %= mod;
ans *= pow_mod(2,-j);
ans %= mod;
cout << ans << endl;
return 0;
}
koi_kotya