QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#494669 | #9141. Array Spread | ucup-team052# | WA | 5ms | 7848kb | C++14 | 3.6kb | 2024-07-27 16:30:17 | 2024-07-27 16:30:18 |
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:30:17]
- 提交
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 = 2005;
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-12;
double a[M][N];
int n, m;
void pivot(int r, int 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() {
a[0][0] = 0;
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]; 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 <= m; i++) {
int j = floor(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, fpow(i, md - 2));
// 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: 4556kb
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: 4080kb
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: 3ms
memory: 6384kb
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: 3ms
memory: 7848kb
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'