QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784251 | #9786. Magical Bags | ucup-team2172# | WA | 1ms | 4084kb | C++23 | 2.0kb | 2024-11-26 14:18:00 | 2024-11-26 14:18:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, ans;
vector<pair<int, int> > all, vec[maxn];
inline void solve_contain(){
vector<pair<int, int> > all_new;
sort(all.begin(), all.end(), [&] (const pair<int, int> &ths, const pair<int, int> &oth) { return ths.second < oth.second; });
int mxl = 0;
for (auto p: all) {
if (mxl > p.first) continue; // this interval contains others, single point never contain others
mxl = max(mxl, p.first);
if (p.first != p.second) all_new.push_back(p);
}
all = all_new;
// for (auto p: all) printf("(%d %d) ", p.first, p.second); puts("");
}
int main(){
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int cnt; scanf("%d", &cnt);
int mn = (int)(1e9) + 1, mx = 1;
for (int j = 0; j < cnt; ++j) {
int x; scanf("%d", &x);
mn = min(mn, x);
mx = max(mx, x);
}
if (cnt >= 2) ans += 2;
else ans += 1;
all.push_back(make_pair(mn, mx));
}
solve_contain();
// printf("ans = %d\n", ans);
int L = (int)(1e9) + 1, R = 0, tot = 0;
for (auto p: all) {
if (p.first < R) {
vec[tot].push_back(p);
L = min(L, p.first);
R = max(R, p.second);
}
else {
++tot;
vec[tot].push_back(p);
L = p.first, R = p.second;
}
}
for (int i = 1; i <= tot; ++i) {
pair<int, int> mn = vec[i][0], mx = vec[i][0];
// for (auto p: vec[i]) printf("(%d %d) ", p.first, p.second); puts("");
for (auto p: vec[i]) {
if (p.first < mn.first) mn = p;
if (p.second > mx.first) mx = p;
}
if (mn.second < mx.first) ans -= 2; // non-intersect => 2 is ok
else ans -= 1; // only 1
}
printf("%d\n", ans);
return 0;
}
/*
4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13
4
1 1
1 2
1 3
1 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
4 3 4 7 10 2 1 9 4 11 2 8 14 3 6 12 13
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
4 1 1 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4084kb
input:
4 3 4 7 10 2 1 9 4 11 2 8 14 3 6 12 13
output:
7
result:
ok 1 number(s): "7"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
4 1 1 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3804kb
input:
100 4 372861091 407948190 424244630 359746969 6 568180757 527358812 494745349 665803213 674832670 586694351 4 696340797 775899164 919971335 716827187 4 123145962 344250363 122030550 251739234 4 342654413 368648894 150539766 255189030 1 194505887 3 755984448 736803561 745474041 4 709314938 498953418 ...
output:
175
result:
wrong answer 1st numbers differ - expected: '177', found: '175'