QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884089#3553. Hamburg Steakmakrav#2 41ms7272kbC++205.1kb2025-02-05 21:16:322025-02-05 21:16:32

Judging History

This is the latest submission verdict.

  • [2025-02-05 21:16:32]
  • Judged
  • Verdict: 2
  • Time: 41ms
  • Memory: 7272kb
  • [2025-02-05 21:16:32]
  • Submitted

answer

#include <bits/stdc++.h>
#include <cassert>

using namespace std;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

pair<int, int> inters(pair<int, int> A, pair<int, int> B) {
    return {max(A.first, B.first), min(A.second, B.second)};
}

void solve() {
    int n, k; cin >> n >> k;
    vector<array<int, 4>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
        // left down right up
    }
    int minright = -1, maxleft = 1e9 + 1, minup = 1e9 + 1, maxdown = -1;
    for (int i = 0; i < n; i++) {
        minright = min(minright, a[i][2]);
        maxleft = max(maxleft, a[i][0]);
        maxdown = max(maxdown, a[i][1]);
        minup = min(minup, a[i][3]);
    }
    if (minright >= maxleft) {
        vector<int> used(n, 0);
        vector<pair<int, int>> ans;
        while (true) {
            int minu = 1e9 + 1, ps = -1;
            for (int i = 0; i < n; i++) {
                if (!used[i] && minu > a[i][3]) {
                    minu = a[i][3]; ps = i;
                }
            }
            if (ps == -1) break;
            ans.pb({minright, minu});
            for (int j = 0; j < n; j++) {
                if (a[j][1] <= minu && minu <= a[j][3]) {
                    used[j] = 1;
                } 
            }
        }
        for (auto u : ans) cout << u.first << ' ' << u.second << '\n';
        for (int i = 0; i < k - sz(ans); i++) cout << ans[0].first << ' ' << ans[0].second << '\n';
        return;
    }
    if (minup >= maxdown) {
        vector<int> used(n, 0);
        vector<pair<int, int>> ans;
        while (true) {
            int minu = 1e9 + 1, ps = -1;
            for (int i = 0; i < n; i++) {
                if (!used[i] && minu > a[i][2]) {
                    minu = a[i][2]; ps = i;
                }
            }
            if (ps == -1) break;
            ans.pb({minu, minup});
            for (int j = 0; j < n; j++) {
                if (a[j][0] <= minu && minu <= a[j][2]) {
                    used[j] = 1;
                } 
            }
        }
        for (auto u : ans) cout << u.first << ' ' << u.second << '\n';
        for (int i = 0; i < k - sz(ans); i++) cout << ans[0].first << ' ' << ans[0].second << '\n';
        return;
    }
    assert(k >= 2);
    int posr = -1, posl = -1;
    for (int i = 0; i < n; i++) {
        if (a[i][2] == minright) posr = i;
        if (a[i][0] == maxleft) posl = i;
    }
    vector<pair<int, int>> segs_left, segs_right;
    for (int i = 0; i < n; i++) {
        if (i != posl && i != posr) {
            auto lolleft = inters({a[posr][1], a[posr][3]}, {a[i][1], a[i][3]}), lolright = inters({a[posl][1], a[posl][3]}, {a[i][1], a[i][3]});
            segs_left.pb(lolleft);
            segs_right.pb(lolright);
        }
    }
    if (segs_left.size() == n - 2 && segs_right.size() == n - 2) {
        if (segs_left.empty()) {
            for (int i = 0; i < n; i++) cout << a[i][0] << ' ' << a[i][1] << '\n';
            for (int j = 0; j < k - n; j++) cout << a[0][0] << ' ' << a[0][1] << '\n';
            return;
        }
        multiset<int> Ls, Rs;
        for (int i = 0; i < sz(segs_right); i++) {
            Ls.insert(segs_right[i].first); Rs.insert(segs_right[i].second);
        }
        if (*Ls.rbegin() <= *Rs.begin()) {
            cout << minright << ' ' << 1 << '\n' << maxleft << ' ' << *Ls.rbegin() << '\n';
            for (int jj = 0; jj < k - 2; jj++) cout << 1 << ' ' << 1 << '\n';
            return;
        }
        vector<pair<int, int>> events;
        for (int i = 0; i < sz(segs_left); i++) {
            events.pb({segs_left[i].first, i});
            events.pb({segs_left[i].second + 1, i});
        }
        sort(all(events));
        vector<int> usedd(sz(segs_left), 0);
        int i = 0;
        while (i < sz(events)) {
            int j = i;
            while (j < sz(events) && events[j].first == events[i].first) {
                if (usedd[events[j].second] == 1) {
                    Ls.insert(segs_right[events[j].second].first);
                    Rs.insert(segs_right[events[j].second].second);
                } else {
                    Ls.erase(Ls.find(segs_right[events[j].second].first));
                    Rs.erase(Rs.find(segs_right[events[j].second].second));
                    usedd[events[j].second] = 1;
                }
                j++;
            }
            if (Ls.empty() || *Ls.rbegin() <= *Rs.begin()) {
                cout << minright << ' ' << events[i].first << '\n' << maxleft << ' ' << *Ls.rbegin() << '\n';
                for (int jj = 0; jj < k - 2; jj++) cout << 1 << ' ' << 1 << '\n';
                return;
            }
            i = j;
        }
    }
    //else assert(k >= 3);
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else 
        cin.tie(0)->sync_with_stdio(false);
    #endif

    while (tt--) {
        solve();
    }
    return 0;
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 0ms
memory: 3840kb

input:

1936 1
275634612 269663887 525116613 936487725
97408668 7442476 814869170 687312206
436819238 107950642 958111100 591552952
7518596 205530980 782566587 854412425
496572510 309198877 998274921 764947740
205948014 311140816 696959672 600779117
332275583 5172242 984611829 780400859
404519140 226954535 ...

output:

500995935 495734996

result:

ok all steak sticked

Test #2:

score: 1
Accepted
time: 0ms
memory: 3712kb

input:

1918 1
101495422 186906933 732615030 881441564
458968315 389772762 517376914 972253676
310129691 156509236 593443672 871966220
91341901 261855863 618682147 864249047
98953032 286357489 522693657 556560771
364790412 127843696 903079225 858654564
329423949 270896020 835948130 589093351
409677593 11179...

output:

508742148 490106022

result:

ok all steak sticked

Test #3:

score: 1
Accepted
time: 1ms
memory: 3840kb

input:

1934 1
149390016 218273120 829091825 943957108
465523240 256616763 562611479 561076814
346779336 19349510 498782244 682919444
355187765 473117629 640518942 857154270
428523527 118919644 980443851 505620423
466172753 4854201 565577102 807575992
63057309 306335591 995966133 973208230
277575294 4065971...

output:

484550435 483701337

result:

ok all steak sticked

Test #4:

score: 1
Accepted
time: 1ms
memory: 3712kb

input:

1943 1
447209427 299197697 579958454 975073773
487022253 6405471 553460639 504906460
483616875 87124408 626036564 533315255
33872888 223251549 940210689 985284538
357235178 224597124 537290418 632810537
45568075 166890122 737266711 881843529
465884824 148626173 976612493 608624682
90616486 330697147...

output:

499983164 499876779

result:

ok all steak sticked

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

1928 2
257715250 61165602 852430884 888048968
291121137 322570367 570606015 908598504
418176729 319924920 611676731 632485660
33180758 215166338 468783003 795212414
441068331 188624227 750676748 613482091
344172819 322492096 940801573 568738370
246507550 338324125 785514636 678843646
100885653 12352...

output:


result:

wrong output format Unexpected end of file - int32 expected

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 3
Accepted
time: 1ms
memory: 3840kb

input:

1980 3
580358104 434053443 986861108 684634218
125969708 5379869 593299091 644204766
366688051 54873592 662708561 602035535
211630750 166795940 981075947 676159693
524950613 414516203 951984898 573261034
10925143 210994662 543601795 609644115
82102881 63393894 401995062 922075556
245641393 276511435...

output:

275428833 497556652
438204200 497556652
817184254 497556652

result:

ok all steak sticked

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

1979 3
166188766 501732855 696148516 858594442
448642394 649848030 826585058 892841834
227996253 41181673 597994927 735947663
496120536 146174371 797127295 937876819
142223416 54620669 692019448 761376043
155423015 310182182 964649015 766725969
149600215 175625826 795416544 456728413
409645085 19620...

output:


result:

wrong output format Unexpected end of file - int32 expected

Subtask #4:

score: 0
Wrong Answer

Test #21:

score: 6
Accepted
time: 0ms
memory: 3840kb

input:

1989 4
20688201 462820019 870557654 779905491
299122723 258293216 630017062 521792413
430322558 33567880 691187720 757852374
104994597 262388698 979697437 904439328
237383344 375297588 673858769 638443621
715773360 364818076 896724313 888051478
235043050 422124296 833892854 936850257
434942952 25412...

output:

302970929 495470567
433295211 495470567
489751079 495470567
741862652 495470567

result:

ok all steak sticked

Test #22:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

1913 4
447764235 131766500 662143128 594925961
175752030 143370745 850970381 604940594
315760617 440375785 908808188 914216196
111980814 70287311 781633529 646769135
18056623 198611867 512791707 850722100
131263504 97431361 865097956 701669444
262211923 224930035 533039033 706346045
107163409 354652...

output:


result:

wrong output format Unexpected end of file - int32 expected

Subtask #5:

score: 1
Accepted

Dependency #1:

100%
Accepted

Test #79:

score: 1
Accepted
time: 37ms
memory: 7140kb

input:

199927 1
438629555 351412894 521316748 962909150
4328400 108580550 683171263 836435313
256786425 198212822 578214653 567880535
256673124 384187605 616347107 546662355
17067286 405399036 782995564 759479522
41592585 336223869 779372332 767950897
144763906 27980775 808755799 769950439
190038989 499607...

output:

501218591 500053151

result:

ok all steak sticked

Test #80:

score: 1
Accepted
time: 38ms
memory: 7272kb

input:

199992 1
468369692 51432142 943101549 608968278
127680231 369941094 634667730 516371960
1427728 371977761 569293553 552853223
257885457 347434207 972596280 837837513
12529484 152139714 579576459 897919247
336613920 369023033 998436991 994236118
199517636 485859301 866178585 867603970
240114269 23997...

output:

498945789 501260099

result:

ok all steak sticked

Test #81:

score: 1
Accepted
time: 41ms
memory: 7136kb

input:

199959 1
238817589 70537254 695436468 882043893
416319574 329705088 750294846 997603367
122039910 48189248 775821782 942409460
123142019 92806058 723431298 750522560
4786698 304382499 682308754 815818931
464345660 36298510 907436621 659933836
147740222 250356542 768868832 810218769
141166042 2446879...

output:

497946723 499771271

result:

ok all steak sticked

Test #82:

score: 1
Accepted
time: 39ms
memory: 7272kb

input:

199975 1
140647043 401141353 909868027 932502018
352011992 220163287 771463853 980296352
361128104 404877280 696161321 507368200
4311205 146503975 844576299 861932439
400068006 401139622 794199519 902157094
159967166 324845985 527699521 828787788
305950684 85836346 695843414 724376480
348091458 4722...

output:

500061555 498127241

result:

ok all steak sticked

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%