QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549566 | #9141. Array Spread | FDUdululu | WA | 2ms | 3896kb | C++14 | 2.9kb | 2024-09-06 17:39:54 | 2024-09-06 17:39:55 |
Judging History
answer
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e3 + 5;
const ll inf = 1e6;
const double eps = 1e-12;
const ll mod = 998244353;
int n, m, k;
int l[N], r[N];
vector<int> t;
vector<pair<int, int>> e[N];
double dis[N];
int cnt[N], vis[N];
queue<int> q;
ll fpow(ll x, ll k) {
ll ans = 1;
while (k) {
if (k & 1)
ans = ans * x % mod;
x = x * x % mod;
k >>= 1;
}
return ans;
}
bool cmp(pair<int, int> x, pair<int, int> y) {
return x.first * y.second < x.second * y.first;
}
int check(double mid) {
for (int i = 0; i <= k; i++) {
dis[i] = inf;
cnt[i] = vis[i] = 0;
}
dis[0] = 0, vis[0] = 1;
q.push(0);
while (!q.empty()) {
int x = q.front();
q.pop();
vis[x] = 0;
for (auto [y, w] : e[x]) {
double d = w;
if (w > 0)
d = mid;
if (dis[y] > dis[x] + d) {
dis[y] = dis[x] + d;
cnt[y] = cnt[x] + 1;
if (cnt[y] >= k + 1)
return 0;
if (!vis[y]) {
q.push(y);
vis[y] = 1;
}
}
}
}
return 1;
}
void solve() {
cin >> n >> m;
t.clear();
for (int i = 1; i <= m; i++) {
cin >> l[i] >> r[i];
l[i]--;
t.push_back(l[i]);
t.push_back(r[i]);
}
sort(t.begin(), t.end());
t.erase(unique(t.begin(), t.end()), t.end());
for (int i = 1; i <= m; i++) {
l[i] = lower_bound(t.begin(), t.end(), l[i]) - t.begin() + 1;
r[i] = lower_bound(t.begin(), t.end(), r[i]) - t.begin() + 1;
}
k = t.size();
for (int i = 0; i <= k; i++)
e[i].clear();
for (int i = 2; i <= k; i++)
e[i].push_back({i - 1, 0});
for (int i = 1; i <= k; i++)
e[0].push_back({i, 0});
for (int i = 1; i <= m; i++) {
e[r[i]].push_back({l[i], -1});
e[l[i]].push_back({r[i], 1});
}
vector<pair<int, int>> val;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= i; j++)
val.push_back({i, j});
sort(val.begin(), val.end(), cmp);
int l = 0, r = val.size() - 1, mid, ans = 0;
while (l <= r) {
mid = (l + r) >> 1;
if (check(1.0 * val[mid].first / val[mid].second)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
cout << val[ans].first * fpow(val[ans].second, mod - 2) % mod << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 0ms
memory: 3696kb
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: 1ms
memory: 3632kb
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: 2ms
memory: 3896kb
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 3 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 499122178 1 1 3 1 1 1 1 1 1 1 2 499122178 1 2 1 1 1 2 1 4 1 2 1 4 1 3 1 1 ...
result:
wrong answer 11th numbers differ - expected: '2', found: '3'