結果
| 問題 |
No.3376 Rectangle in Circle
|
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2025-11-21 08:56:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 249 ms / 2,000 ms |
| コード長 | 2,279 bytes |
| コンパイル時間 | 4,963 ms |
| コンパイル使用メモリ | 335,084 KB |
| 実行使用メモリ | 10,240 KB |
| 最終ジャッジ日時 | 2025-11-21 20:53:03 |
| 合計ジャッジ時間 | 8,833 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = atcoder::modint998244353;
// using mint = double;
#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define siz(x) (int)(x).size()
template<class T> bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
const int inf = 1e9;
const ll INF = 4e18;
template<class T> using pq = priority_queue<T, vector<T>, less<T>>;
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;
vector<int> di = {0, 0, 1, -1};
vector<int> dj = {1, -1, 0, 0};
struct Edge {
int to, cost;
};
void solve() {
int N, L; cin >> N >> L;
vector<int> D(N);
for (int& d : D) cin >> d;
int cnt = 0;
if (L%2 == 0) {
rep(i, 0, N) {
if (D[i] < L / 2) {
if (binary_search(all(D), D[i] + L / 2)) cnt++;
}
}
}
// cout << cnt << endl;
vector<mint> inv(N+1);
rep(i, 1, N+1) {
inv[i] = mint(1) / i;
}
if (cnt <= 1) {
//NG
mint ans = 0;
//全部埋めるまでにかかる回数
for (int i = 1; i <= N; i++) ans += N * inv[i];
cout << ans.val() << endl;
return;
}
vector dp(cnt + 1, vector<mint>(3));
for (int i = cnt; i >= 0; i--) {
for (int j = 2; j >= 0; j--) {
if (j > i) continue;
if (j == 2) {
dp[i][j] = 0;
continue;
}
int zero = cnt - i;
int one = i - j;
int two = j;
mint blank = 2 * zero + one;
//成功確率
mint p = blank / N;
//コスト
mint cost = 1 / p;
//0 -> 1
if (zero > 0) dp[i][j] += dp[i+1][j] * mint(2 * zero) / blank;
//1 -> 0
if (one > 0) dp[i][j] += dp[i][j+1] * mint(one) / blank;
dp[i][j] += cost;
}
}
cout << dp[0][0].val() << endl;
}
int main() {
int T; cin >> T;
while(T--) solve();
}
Iroha_3856