QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#494757 | #9141. Array Spread | ucup-team052# | WA | 7ms | 7132kb | C++14 | 3.4kb | 2024-07-27 16:52:05 | 2024-07-27 16:52:05 |
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 16:52:05]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
#define double long double
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 = 4005;
int l[N], r[N], b[N];
int T, n, m, ans1, ans2;
namespace dcx {
const int N = 4005, M = 4005;
const double eps = 1e-14;
double a[N][M];
int n, m;
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
void pivot(int u, int v) {
if(fabs(a[u][v]) <= eps) while (true);
double iv = 1. / a[u][v];
L(i, 0, n) a[u][i] *= iv;
a[u][v] = iv;
L(i, 0, m) if(i != u && fabs(a[i][v]) > 0) {
double c = a[i][v];
a[i][v] = 0;
L(j, 0, n) a[i][j] -= a[u][j] * c;
}
}
double simplex() {
a[0][0] = 0;
while (true) {
int u = 1, v = -1;
L(i, 1, m) if(a[i][0] < a[u][0]) u = i;
if(a[u][0] >= -eps) break ;
L(i, 1, n) if(a[u][i] < -eps) v = i;
if(v == -1) {
assert(0);
}
pivot(u, v);
}
while (true) {
int u = -1, v = 1;
L(i, 1, n) if(a[0][i] < a[0][v]) v = i;
if(a[0][v] >= -eps) break ;
double mn = 1e18;
L(i, 1, m) if(a[i][v] > eps) {
double qwq = a[i][0] / a[i][v];
if(qwq < mn) u = i, mn = qwq;
}
if(u == -1) {
assert(0);
}
pivot(u, v);
}
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]; b[i + m] = r[i];
}
sort(b + 1, b + 2 * m + 1);
int len = unique(b + 1, b + 2 * m + 1) - b - 1;
dcx::m = m * 2;
dcx::n = len + 1;
for (int i = 1; i <= len; i++) dcx::a[0][i] = 0;
dcx::a[0][len + 1] = 1;
for (int i = 1; i <= m; i++) {
l[i] = lower_bound(b + 1, b + len + 1, l[i]) - b;
r[i] = lower_bound(b + 1, b + len + 1, r[i]) - b;
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][len + 1] = -1;
}
double res = -dcx::simplex();
// fprintf(stderr, "res = %.6lf\n", res);
double mn = 1e9;
int ans = 0;
for (int i = 1; ; i++) {
long long j = floor(1ll * i * res + 0.5);
double diff = fabs((double)j / i - res);
// fprintf(stderr, "i = %d, j = %d\n", i, j);
if (diff < mn) {
mn = diff;
ans = mul(j % md, fpow(i, md - 2));
if (diff < 1e-12) {
break;
}
// fprintf(stderr, "ans = %d, i = %d, j = %d, diff = %.6lf\n", ans, i, j, diff);
}
}
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: 1ms
memory: 4644kb
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: 5ms
memory: 6048kb
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: 0
Accepted
time: 6ms
memory: 7132kb
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 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 2 1 1 1 1 ...
result:
ok 1000 numbers
Test #4:
score: -100
Wrong Answer
time: 7ms
memory: 6912kb
input:
500 1000000000 13 964546318 987364574 367845944 907446075 259314137 890312338 458318546 959971971 353677471 522446336 782931403 845199078 514387878 786979588 532634932 793056892 905393511 960628299 747423889 986373313 796099347 833069525 906969434 971335651 574582540 647534593 1000000000 6 987712893...
output:
3 1 3 1 1 1 1 1 1 3 2 1 1 1 3 1 2 1 1 2 1 3 1 1 1 2 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 3 1 2 1 1 1 1 2 3 1 1 1 1 1 1 1 3 2 1 3 2 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 2 1 1 1 3 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 1 4 1 2 1 4 1 3 1 1 1 1 1 2 1 1 4 1 ...
result:
wrong answer 455th numbers differ - expected: '1', found: '499122178'