QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#496413 | #9141. Array Spread | ucup-team1231# | WA | 1ms | 5940kb | C++14 | 2.0kb | 2024-07-28 09:27:20 | 2024-07-28 09:27:20 |
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-28 09:27:20]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 998244353;
int inv(int x) {
int t = MOD - 2, ret = 1;
while(t > 0) {
if(t & 1) ret = 1LL * ret * x % MOD;
x = 1LL * x * x % MOD;
t >>= 1;
}
return ret;
}
int n, m, l[2005], r[2005], f[4005][4005];
vector<int> hv, hvr[4005];
void trans(int fr[], int to[]) {
for(int i = 0; i < m; i++) to[i] = INF;
for(int i = 0; i < n; i++) to[l[i]] = min(to[l[i]], fr[r[i]]);
for(int i = m - 2; i >= 0; i--) to[i] = min(to[i], to[i + 1]);
for(int i = 0; i < m; i++)
for(auto j : hvr[i]) for(int k = j; to[k] > to[i] + 1; k--) to[k] = to[i] + 1;
}
bool cmp(const pair<int, int>& u, const pair<int, int>& v) {
return u.first * v.second < u.second * v.first;
}
void solve() {
scanf("%*d%d", &n);
hv.clear();
for(int i = 0; i < n; i++) {
scanf("%d%d", &l[i], &r[i]);
hv.push_back(l[i]);
hv.push_back(r[i] + 1);
}
sort(hv.begin(), hv.end());
hv.resize(unique(hv.begin(), hv.end()) - hv.begin());
m = hv.size();
for(int i = 0; i < n; i++) {
l[i] = lower_bound(hv.begin(), hv.end(), l[i]) - hv.begin();
r[i] = upper_bound(hv.begin(), hv.end(), r[i]) - hv.begin();
}
for(int i = 0; i < m; i++) hvr[i].clear();
for(int i = 0; i < n; i++) hvr[l[i]].push_back(r[i]);
for(int i = 0; i < m; i++) f[0][i] = 0;
for(int i = 1; i <= m; i++) trans(f[i], f[i + 1]);
pair<int, int> ans = make_pair(m, 1);
for(int i = 0; i < m; i++) if(f[m][i] < INF / 2) {
pair<int, int> now = make_pair(-m, 1);
for(int j = 0; j < m; j++) if(f[j][i] < INF / 2) {
pair<int, int> upd = make_pair(f[m][i] - f[j][i], m - j);
if(cmp(now, upd)) now = upd;
}
if(cmp(now, ans)) ans = now;
}
int ret = 1LL * ans.second * inv(ans.first) % MOD;
printf("%d\n", ret);
}
int main() {
int T;
scanf("%d", &T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5940kb
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: -100
Wrong Answer
time: 1ms
memory: 3992kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '1', found: '0'