QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291201 | #6546. Greedy Bipartite Matching | Radewoosh# | WA | 1850ms | 96956kb | C++23 | 3.6kb | 2023-12-26 05:37:31 | 2023-12-26 05:37:32 |
Judging History
answer
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
int n, q;
vector<pii> kra[nax];
vi graf[nax];
int sko[nax];
int ma[nax];
int bylo[nax];
vi farg[nax];
int cov[nax][2];
int odw[nax][2];
int dfs1(int v)
{
bylo[v]=1;
for (int i : graf[v])
{
if (!ma[i] || (!bylo[ma[i]] && dfs1(ma[i])))
{
sko[v]=i;
ma[i]=v;
return 1;
}
}
return 0;
}
int szukaj(int v)
{
for (int i=1; i<=n; i++)
{
graf[i].clear();
farg[i].clear();
}
for (int i=1; i<=v; i++)
{
for (pii j : kra[i])
{
graf[j.first].push_back(j.second);
farg[j.second].push_back(j.first);
}
}
int czy=1;
int ret=0;
while(czy)
{
czy=0;
for (int i=1; i<=n; i++)
bylo[i]=0;
for (int i=1; i<=n; i++)
if (!sko[i] && !bylo[i] && dfs1(i))
czy=1, ret++;
}
return ret;
}
void dfs2(int v, int war, int parz)
{
if (odw[v][war])
return;
odw[v][war]=1;
cov[v][war]=parz;
if (!war)
{
for (int i : graf[v])
dfs2(i, 1, parz^1);
}
else
{
for (int i : farg[v])
dfs2(i, 0, parz^1);
}
}
void cover()
{
for (int i=1; i<=n; i++)
for (int h=0; h<2; h++)
odw[i][h]=cov[i][h]=0;
for (int i=1; i<=n; i++)
if (!sko[i])
dfs2(i, 0, 0);
for (int i=1; i<=n; i++)
if (!ma[i])
dfs2(i, 1, 0);
for (int i=1; i<=n; i++)
if (!odw[i][0])
cov[i][0]=1;
}
int main()
{
scanf("%d%d", &n, &q);
for (int i=1; i<=q; i++)
{
int r;
scanf("%d", &r);
while(r--)
{
int a, b;
scanf("%d%d", &a, &b);
kra[i].push_back({a, b});
}
}
int sum=0;
for (int i=1; i<=q; i++)
{
sum+=szukaj(i);
printf("%d ", sum);
cover();
for (int j=(int)kra[i].size()-1; j>=0; j--)
{
if (cov[kra[i][j].first][0] && cov[kra[i][j].second][1])
{
swap(kra[i][j], kra[i].back());
kra[i].pop_back();
}
}
for (int h=1; h<=q; h++)
{
for (int j=(int)kra[h].size()-1; j>=0; j--)
{
if (cov[kra[h][j].first][0] || cov[kra[h][j].second][1])
{
swap(kra[h][j], kra[h].back());
kra[h].pop_back();
}
}
}
}
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 81788kb
input:
3 4 2 1 1 1 2 2 1 1 2 2 2 1 3 3 2 1 3 3
output:
1 2 2 3
result:
ok 4 number(s): "1 2 2 3"
Test #2:
score: 0
Accepted
time: 16ms
memory: 76240kb
input:
0 0
output:
result:
ok 0 number(s): ""
Test #3:
score: 0
Accepted
time: 12ms
memory: 78392kb
input:
2 2 0 2 1 2 1 2
output:
0 1
result:
ok 2 number(s): "0 1"
Test #4:
score: 0
Accepted
time: 87ms
memory: 89948kb
input:
100000 1 200000 78475 45796 32145 46393 92550 13904 73461 34145 96461 92851 56319 77067 77530 84437 76343 51543 77507 99269 76411 89382 1779 61393 43608 96136 84269 74828 14858 35967 32085 94909 19877 175 1482 94391 12424 55020 64369 92588 81296 7903 25433 46033 36294 61129 73556 84837 8419 10215 12...
output:
100000
result:
ok 1 number(s): "100000"
Test #5:
score: 0
Accepted
time: 73ms
memory: 96956kb
input:
100000 1 200000 56816 52517 2577 76202 40378 1758 50464 66497 15834 50880 9829 16331 80693 9963 51096 17591 15871 35192 91302 65510 90775 57493 11891 8967 44787 41896 3387 35479 93471 47453 84804 93636 90746 34877 18202 38718 7473 34258 36581 19533 13249 27525 6442 69870 8822 61871 94537 67714 41396...
output:
100000
result:
ok 1 number(s): "100000"
Test #6:
score: 0
Accepted
time: 7ms
memory: 78916kb
input:
4 1 7 2 2 3 3 1 1 4 2 2 3 3 1 4 3
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 53ms
memory: 88952kb
input:
100000 1 199999 25371 25371 85965 85964 416 416 16797 16797 12438 12438 45410 45409 63006 63005 22156 22156 87829 87828 84014 84014 37308 37308 72325 72325 83704 83704 55391 55390 6781 6780 78091 78091 9376 9376 82193 82193 74695 74695 49842 49842 15799 15799 69856 69855 82949 82948 97390 97389 205 ...
output:
100000
result:
ok 1 number(s): "100000"
Test #8:
score: 0
Accepted
time: 49ms
memory: 93704kb
input:
100000 1 199999 59470 59470 76774 76773 89517 89517 87041 87041 90185 90185 83076 83076 61455 61455 33616 33616 85795 85794 92073 92072 49726 49726 63843 63842 99248 99248 24122 24122 29553 29552 73534 73534 75846 75846 27030 27029 84419 84419 26637 26637 10101 10100 75014 75013 67342 67342 75647 75...
output:
100000
result:
ok 1 number(s): "100000"
Test #9:
score: 0
Accepted
time: 67ms
memory: 94264kb
input:
100000 1 199999 22285 45796 32145 44931 58735 13904 57137 34145 7549 92851 56319 11875 77530 85279 27040 51543 77507 94258 69266 89382 67074 61393 86160 96136 83228 74828 14858 19501 32085 73640 86885 175 27269 94391 20021 55020 45358 92588 17834 7903 55802 46033 36294 46558 73556 13747 8419 88394 1...
output:
100000
result:
ok 1 number(s): "100000"
Test #10:
score: 0
Accepted
time: 76ms
memory: 87776kb
input:
100000 1 199999 4851 52517 2577 29251 69017 1758 85855 66497 48301 50880 83742 16331 98932 9963 38731 17591 15871 13961 91302 97596 81693 57493 11891 59333 5077 41896 23575 35479 93471 65246 61977 93636 96141 34877 18202 35367 64058 34258 25589 19533 13249 91004 6442 83449 99192 61871 94537 16903 73...
output:
100000
result:
ok 1 number(s): "100000"
Test #11:
score: 0
Accepted
time: 1094ms
memory: 91336kb
input:
100000 1 199997 4415 9894 97824 23182 2551 30097 24322 27913 64552 31862 23073 68076 28494 14953 11400 33367 14514 13085 40869 51446 63170 88054 76550 23848 22657 57759 9479 56985 96440 59224 69954 84962 55443 22220 96520 87619 31746 72821 8800 6061 36912 77572 8970 95816 32991 68335 29931 84159 333...
output:
63398
result:
ok 1 number(s): "63398"
Test #12:
score: 0
Accepted
time: 950ms
memory: 93492kb
input:
100000 1 199998 88398 83466 84749 59029 89875 66158 13827 70123 42158 89836 17150 69739 94515 36029 65168 64957 20523 82579 767 6540 23367 32863 61341 51172 41325 62479 6019 38350 61266 36740 88694 66965 87199 74377 27532 67626 72836 38103 66474 43665 94014 82684 22393 7656 65428 88846 1268 82978 82...
output:
63828
result:
ok 1 number(s): "63828"
Test #13:
score: 0
Accepted
time: 1034ms
memory: 86968kb
input:
100000 1 199999 19916 73760 33590 54291 86580 62788 16261 85328 54723 79797 99874 80572 54928 54473 89925 95257 69135 85704 7329 82391 40585 16916 72524 22756 18765 12473 44987 15352 30916 89510 35447 10869 89920 87243 50945 57679 67164 34842 72434 217 33280 11229 79543 42189 39850 20240 97438 7964 ...
output:
63525
result:
ok 1 number(s): "63525"
Test #14:
score: 0
Accepted
time: 54ms
memory: 87468kb
input:
61379 1 199943 14004 13750 24505 24348 30372 30220 27662 27462 33248 33398 38347 38158 17301 16945 50477 50644 56489 56552 46691 46950 21356 21289 3900 3660 24331 24166 8807 8306 40958 40995 15090 14814 20398 20390 30865 30801 33636 33756 20901 20809 55448 55500 4336 4041 36727 36552 16497 16096 367...
output:
37154
result:
ok 1 number(s): "37154"
Test #15:
score: 0
Accepted
time: 65ms
memory: 84880kb
input:
61352 1 199960 2271 2420 38843 39328 48789 48844 2494 2636 40184 40660 59755 59011 48981 48994 52509 52277 12893 13196 33812 34566 40261 40701 2117 2290 11743 12134 29440 29943 4257 4393 51423 51264 44696 44995 21601 22166 21667 22209 26473 26786 49980 50039 12100 12516 10540 10817 32737 33402 30808...
output:
37442
result:
ok 1 number(s): "37442"
Test #16:
score: 0
Accepted
time: 73ms
memory: 94460kb
input:
100000 1 199998 1 13806 1 33642 2 9260 2 62739 2 70692 2 78119 3 41149 4 15766 4 50060 5 96645 6 91522 7 32563 9 2551 9 11397 9 48346 10 14640 10 51058 10 79294 10 92375 11 64734 11 67021 12 7765 12 46823 12 60303 13 8750 13 27870 13 69570 13 71511 14 35685 14 42580 14 82024 15 34779 16 1976 16 6932...
output:
78404
result:
ok 1 number(s): "78404"
Test #17:
score: 0
Accepted
time: 62ms
memory: 89724kb
input:
100000 1 199998 1 28390 1 41334 1 66667 2 5985 2 15913 4 63754 4 77736 5 25016 5 30451 5 90213 6 66979 6 98910 7 63466 7 78228 7 78951 7 85423 8 1744 8 1869 8 55172 9 37583 10 26492 10 82985 11 29230 11 29812 11 33064 12 10610 12 48602 12 73299 12 95659 13 29065 13 50262 13 63187 13 68617 14 86838 1...
output:
78497
result:
ok 1 number(s): "78497"
Test #18:
score: 0
Accepted
time: 77ms
memory: 94420kb
input:
100000 1 199997 1 4358 1 35526 1 51858 2 57469 2 94928 2 96005 4 75469 5 20203 5 37103 6 32208 7 8678 7 16776 7 46814 7 75641 8 30807 9 4100 9 26455 9 49377 9 55540 9 67033 10 82363 11 11388 11 33779 11 35353 11 50534 11 54707 12 44869 12 59105 15 80529 15 90601 15 99753 16 10955 16 80520 16 87341 1...
output:
78379
result:
ok 1 number(s): "78379"
Test #19:
score: 0
Accepted
time: 7ms
memory: 84828kb
input:
77101 1 11866 5 29612 5 62771 5 65606 6 22178 6 57725 15 59633 15 68650 18 9623 19 9222 19 43356 30 19613 31 44429 33 51278 35 53197 36 20940 38 68143 39 34664 39 36433 40 71933 41 62218 42 40292 44 53543 45 22019 45 60540 48 56820 48 76082 50 18327 51 52877 51 58007 52 64710 52 66012 53 26752 53 45...
output:
8453
result:
ok 1 number(s): "8453"
Test #20:
score: 0
Accepted
time: 46ms
memory: 85712kb
input:
69830 1 148749 1 8566 1 12094 1 12609 3 778 3 8772 4 6107 4 7527 4 10597 4 12200 4 14675 4 17677 5 4644 5 15017 5 17195 7 6949 8 1744 8 7751 9 2306 9 4815 10 4469 10 12247 10 16764 10 17449 11 296 11 12044 11 13972 12 169 12 4448 12 7763 12 15834 12 15994 13 1915 13 3081 13 5650 15 30 16 1676 16 464...
output:
19684
result:
ok 1 number(s): "19684"
Test #21:
score: 0
Accepted
time: 37ms
memory: 86368kb
input:
61958 1 92222 1 23731 1 34076 1 35526 2 30469 2 61016 4 24510 4 36309 5 8062 5 45186 5 54436 6 32531 6 59289 7 10105 7 56658 11 2204 11 3107 11 33779 12 29822 12 59105 13 27898 15 18851 16 13473 16 14984 16 37132 16 40141 16 49347 16 59902 17 12877 17 32646 19 26572 22 60371 23 39981 23 41045 23 611...
output:
40194
result:
ok 1 number(s): "40194"
Test #22:
score: 0
Accepted
time: 83ms
memory: 87880kb
input:
36033 1 130375 1 1578 1 16726 1 22302 1 24559 2 5978 2 6739 2 9340 2 25295 3 763 3 6993 3 10208 3 14609 4 4 4 3003 4 25048 5 12403 5 13816 5 15863 6 4728 7 6681 7 8346 7 10058 7 13353 7 17085 8 9879 8 17894 8 21629 8 23893 9 2602 9 13005 9 19100 9 23029 10 2308 10 13012 10 15777 10 22643 12 7389 12 ...
output:
25668
result:
ok 1 number(s): "25668"
Test #23:
score: 0
Accepted
time: 25ms
memory: 87424kb
input:
99117 1 25214 1 19547 1 37952 2 13805 2 18264 2 38542 2 49320 2 64694 2 81666 2 91778 3 2160 3 8897 5 38135 6 3465 6 52632 7 85972 7 92675 8 5531 8 12992 8 35466 9 12078 9 71947 10 57521 12 75487 12 95228 13 83002 14 83430 14 85533 16 32389 16 49235 16 87160 17 70734 17 95798 18 45028 19 51285 21 38...
output:
12003
result:
ok 1 number(s): "12003"
Test #24:
score: 0
Accepted
time: 20ms
memory: 81196kb
input:
53098 1 57924 1 263 1 3337 1 7252 3 2977 4 4878 5 3404 5 8280 6 4743 7 2962 7 8902 9 5980 9 8809 10 7823 11 416 13 970 14 1059 16 3593 18 5760 19 7129 20 4462 20 9344 21 5012 21 8943 22 8415 23 5218 23 5267 23 5456 24 5699 24 8698 25 5856 26 1212 26 2831 29 3686 30 1867 30 8646 33 6956 33 7046 34 24...
output:
9415
result:
ok 1 number(s): "9415"
Test #25:
score: 0
Accepted
time: 88ms
memory: 89740kb
input:
62612 1 153201 1 1820 2 26258 2 34655 2 41967 3 9610 4 19008 4 31307 4 36055 5 36682 5 42044 5 46886 5 54124 6 35273 6 48536 7 9178 7 44478 8 11190 8 17567 8 41427 8 53725 9 13816 9 36016 9 48167 11 1145 11 2929 11 21149 11 21678 11 46646 13 39908 13 53276 14 52580 15 21090 16 39808 17 46514 18 2478...
output:
53671
result:
ok 1 number(s): "53671"
Test #26:
score: 0
Accepted
time: 19ms
memory: 87500kb
input:
95835 1 31126 8 7490 11 1814 18 1853 19 9254 22 3000 26 1650 29 7089 34 4069 34 6120 35 5652 40 10351 42 5704 44 7513 52 3935 53 4247 56 4276 56 6550 65 8186 67 10081 68 10333 74 6344 74 6433 81 8845 87 1765 88 5647 93 400 96 510 96 9565 103 10599 108 583 122 5614 123 5867 124 7064 126 4181 126 6966...
output:
10716
result:
ok 1 number(s): "10716"
Test #27:
score: 0
Accepted
time: 30ms
memory: 86152kb
input:
49455 1 192460 1 452 1 2960 1 4381 1 4903 1 9093 1 9319 1 10190 1 11110 1 13731 1 15873 1 17605 1 18558 1 19328 1 19872 1 21172 1 24113 1 26986 1 28369 1 28475 1 29570 1 30904 1 31862 1 35961 1 36792 1 38655 1 40351 1 46165 1 46922 1 47527 1 48227 1 48324 1 48593 1 49187 2 2867 2 8430 2 9732 2 9880 ...
output:
5824
result:
ok 1 number(s): "5824"
Test #28:
score: 0
Accepted
time: 58ms
memory: 84060kb
input:
64506 1 150593 1 4769 1 10543 1 14843 1 20603 2 1267 2 12254 3 472 3 13146 3 14024 3 15191 3 18273 3 22690 5 8150 5 9070 7 358 7 10398 7 10870 7 16798 8 5498 8 19180 9 3469 9 6449 9 11474 9 12456 9 13156 10 752 11 11246 12 10587 12 13267 12 17149 12 20207 12 22536 13 5516 14 375 14 19048 15 11868 15...
output:
23290
result:
ok 1 number(s): "23290"
Test #29:
score: -100
Wrong Answer
time: 1850ms
memory: 91984kb
input:
100000 1000 33 78475 45796 32145 46393 92550 13904 73461 34145 96461 92851 56319 77067 77530 84437 76343 51543 77507 99269 76411 89382 1779 61393 43608 96136 84269 74828 14858 35967 32085 94909 19877 175 1482 94391 12424 55020 64369 92588 81296 7903 25433 46033 36294 61129 73556 84837 8419 10215 120...
output:
33 197 311 340 497 500 644 778 1331 2256 2430 2515 2536 2758 3521 3741 3830 3858 4049 4231 4424 4818 4897 4990 5026 5161 5239 5308 5379 5492 5493 5558 5638 6038 6427 6494 7125 7211 7610 7775 7924 8165 8247 8802 8901 9063 9170 9222 9261 9295 9301 9435 9452 9718 9897 9938 10022 10124 10232 11196 11300...
result:
wrong answer 115th numbers differ - expected: '18307', found: '18306'