QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#494432 | #9141. Array Spread | ucup-team052# | WA | 3ms | 4020kb | C++23 | 3.2kb | 2024-07-27 15:46:16 | 2024-07-27 15:46:17 |
Judging History
你现在查看的是最新测评结果
- [2024-09-18 18:58:44]
- hack成功,自动添加数据
- (/hack/840)
- [2024-09-18 18:53:02]
- hack成功,自动添加数据
- (/hack/839)
- [2024-07-29 03:53:23]
- hack成功,自动添加数据
- (/hack/753)
- [2024-07-29 03:51:16]
- hack成功,自动添加数据
- (/hack/752)
- [2024-07-29 03:50:24]
- hack成功,自动添加数据
- (/hack/751)
- [2024-07-29 03:48:52]
- hack成功,自动添加数据
- (/hack/750)
- [2024-07-27 15:46:16]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline int mul(int x, int y) {
return 1ull * x * y % md;
}
inline int fpow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
}
const int N = 2005;
int l[N], r[N], b[N];
int T, n, m, ans1, ans2;
namespace dcx {
const int N = 1005, M = 10005;
const double eps = 1e-8;
double a[M][N];
int id[N + M];
int n, m;
void pivot(int r, int c) {
swap(id[r + n], id[c]);
double tmp = -a[r][c]; a[r][c] = -1;
for (int i = 0; i <= n; i++) a[r][i] /= tmp;
for (int i = 0; i <= m; i++) {
if (i != r && fabs(a[i][c]) > eps) {
tmp = a[i][c]; a[i][c] = 0;
for (int j = 0; j <= n; j++) a[i][j] += tmp * a[r][j];
}
}
}
double simplex() {
memset(id, 0, sizeof(id)); a[0][0] = 0;
for (int i = 1; i <= n; i++) id[i] = i;
while (1) {
int r = -1;
for (int i = 1; i <= m; i++) {
if (a[i][0] < -eps) {
if (r == -1 || a[i][0] < a[r][0]) {
r = i;
}
}
}
if (r == -1) break;
int c = -1;
for (int i = 1; i <= n; i++) {
if (a[r][i] > eps) {
c = i;
break;
}
}
assert(c != -1);
pivot(r, c);
}
while (1) {
int c = -1;
for (int i = 1; i <= n; i++) {
if (a[0][i] > eps) {
c = i;
break;
}
}
if (c == -1) break;
int r = -1; double lim;
for (int i = 1; i <= m; i++) {
if (a[i][c] < -eps) {
double now = a[i][0] / -a[i][c];
if (r == -1 || now < lim) {
lim = now;
r = i;
}
}
}
assert(r != -1);
pivot(r, c);
}
return a[0][0];
}
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &l[i], &r[i]);
b[i] = l[i];
}
sort(b + 1, b + m + 1);
dcx::m = m * 2;
dcx::n = m + 1;
for (int i = 1; i <= m; i++) dcx::a[0][i] = 0;
dcx::a[0][m + 1] = -1;
for (int i = 1; i <= m; i++) {
l[i] = lower_bound(b + 1, b + m + 1, l[i]) - b;
r[i] = upper_bound(b + 1, b + m + 1, r[i]) - b - 1;
memset(dcx::a[i * 2 - 1], 0, sizeof(dcx::a[i * 2 - 1]));
memset(dcx::a[i * 2], 0, sizeof(dcx::a[i * 2 - 1]));
for (int j = l[i]; j <= r[i]; j++) {
dcx::a[i * 2 - 1][j] = 1;
dcx::a[i * 2][j] = -1;
}
dcx::a[i * 2 - 1][0] = -1;
dcx::a[i * 2][m + 1] = 1;
}
double res = -dcx::simplex();
// fprintf(stderr, "res = %.6lf\n", res);
int ok = 0, ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= i; j++) {
if (fabs((double)i / j - res) < 1e-8) {
ans = mul(i, fpow(j, md - 2)); ok = 1;
break;
}
}
if (ok) break;
}
printf("%d\n", ans);
}
return 0;
}
/*
3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4020kb
input:
3 3 3 1 3 2 3 1 2 12 6 2 3 5 7 1 9 4 8 1 2 7 11 4 5 3 4 2 3 1 2 4 4 1 1
output:
1 2 499122178
result:
ok 3 number(s): "1 2 499122178"
Test #2:
score: 0
Accepted
time: 3ms
memory: 3936kb
input:
2000 1000000000 1 259923446 367011266 1000000000 1 882434225 971573327 1000000000 1 41585677 470369580 1000000000 1 371902212 947250194 1000000000 1 787209148 924205796 1000000000 1 259074809 960876164 1000000000 1 148079314 188254573 1000000000 1 940091047 948318624 1000000000 1 40636497 743979446 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 2000 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3980kb
input:
1000 1000000000 5 575330909 661595447 708422488 913945134 658050911 930246647 786571892 904549453 851755566 969150871 1000000000 2 198072104 844159589 8876188 644559580 1000000000 2 740802634 976972118 783909534 898449184 1000000000 2 871819537 941611957 465883854 640988372 1000000000 1 99458969 462...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 ...
result:
wrong answer 32nd numbers differ - expected: '1', found: '2'