Submission #231550

# Submission time Handle Problem Language Result Execution time Memory
231550 2020-05-14T00:31:51 Z duality Hamburg Steak (JOI20_hamburg) C++11
21 / 100
3000 ms 7768 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int L[200000],D[200000],R[200000],U[200000];
vi xLines,yLines;
int order[200000];
struct rect { int l,d,r,u; };
vector<rect> ans;
int main() {
    int i;
    int N,K;
    scanf("%d %d",&N,&K);
    for (i = 0; i < N; i++) {
        scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
        xLines.pb(L[i]),xLines.pb(R[i]+1);
        yLines.pb(D[i]),yLines.pb(U[i]+1);
    }
    sort(xLines.begin(),xLines.end());
    xLines.resize(unique(xLines.begin(),xLines.end())-xLines.begin());
    sort(yLines.begin(),yLines.end());
    yLines.resize(unique(yLines.begin(),yLines.end())-yLines.begin());
    for (i = 0; i < N; i++) {
        L[i] = lower_bound(xLines.begin(),xLines.end(),L[i])-xLines.begin();
        D[i] = lower_bound(yLines.begin(),yLines.end(),D[i])-yLines.begin();
        R[i] = lower_bound(xLines.begin(),xLines.end(),R[i]+1)-xLines.begin()-1;
        U[i] = lower_bound(yLines.begin(),yLines.end(),U[i]+1)-yLines.begin()-1;
    }

    int j;
    for (i = 0; i < N; i++) order[i] = i;
    while (1) {
        random_shuffle(order,order+N);
        for (i = 0; i < N; i++) {
            int u = order[i],b = -1,bb = 0;
            for (j = 0; j < ans.size(); j++) {
                if ((L[u] > ans[j].r) || (R[u] < ans[j].l) || (D[u] > ans[j].u) || (U[u] < ans[j].d)) continue;
                else {
                    rect x = ans[j];
                    x.l = max(x.l,L[u]);
                    x.d = max(x.d,D[u]);
                    x.r = min(x.r,R[u]);
                    x.u = min(x.u,U[u]);
                    if ((b == -1) || (ans[j].u-ans[j].d+ans[j].r-ans[j].l-(x.u-x.d+x.r-x.l) < bb)) {
                        b = j;
                        bb = ans[j].u-ans[j].d+ans[j].r-ans[j].l-(x.u-x.d+x.r-x.l);
                    }
                }
            }
            if (b == -1) ans.pb((rect){L[u],D[u],R[u],U[u]});
            else {
                rect x = ans[b];
                x.l = max(x.l,L[u]);
                x.d = max(x.d,D[u]);
                x.r = min(x.r,R[u]);
                x.u = min(x.u,U[u]);
                ans[b] = x;
            }
            if (ans.size() > K) break;
        }
        if (i == N) {
            for (j = 0; j < K; j++) {
                if (j < ans.size()) printf("%d %d\n",xLines[ans[j].l],yLines[ans[j].d]);
                else printf("0 0\n");
            }
            return 0;
        }
        else ans.clear();
    }

    return 0;
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for (j = 0; j < ans.size(); j++) {
      |                         ~~^~~~~~~~~~~~
hamburg.cpp:112:28: warning: comparison of integer expressions of different signedness: 'std::vector<rect>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  112 |             if (ans.size() > K) break;
      |                 ~~~~~~~~~~~^~~
hamburg.cpp:116:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |                 if (j < ans.size()) printf("%d %d\n",xLines[ans[j].l],yLines[ans[j].d]);
      |                     ~~^~~~~~~~~~~~
hamburg.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |     scanf("%d %d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~
hamburg.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |         scanf("%d %d %d %d",&L[i],&D[i],&R[i],&U[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 11 ms 384 KB Output is correct
16 Correct 14 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 9 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 10 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 9 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 9 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 8 ms 384 KB Output is correct
40 Correct 9 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 26 ms 384 KB Output is correct
50 Correct 12 ms 384 KB Output is correct
51 Correct 12 ms 484 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 16 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 386 ms 7628 KB Output is correct
6 Correct 371 ms 7692 KB Output is correct
7 Correct 384 ms 7512 KB Output is correct
8 Correct 403 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 407 ms 7620 KB Output is correct
6 Correct 407 ms 7572 KB Output is correct
7 Correct 399 ms 7508 KB Output is correct
8 Correct 404 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 382 ms 7640 KB Output is correct
14 Correct 403 ms 7648 KB Output is correct
15 Correct 385 ms 7720 KB Output is correct
16 Correct 443 ms 7632 KB Output is correct
17 Correct 412 ms 7732 KB Output is correct
18 Correct 435 ms 7636 KB Output is correct
19 Correct 550 ms 7560 KB Output is correct
20 Correct 431 ms 7624 KB Output is correct
21 Correct 419 ms 7508 KB Output is correct
22 Correct 453 ms 7512 KB Output is correct
23 Correct 448 ms 7504 KB Output is correct
24 Correct 413 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 11 ms 384 KB Output is correct
16 Correct 14 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 9 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 10 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 9 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 9 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 8 ms 384 KB Output is correct
40 Correct 9 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 26 ms 384 KB Output is correct
50 Correct 12 ms 384 KB Output is correct
51 Correct 12 ms 484 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 16 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 744 ms 7624 KB Output is correct
60 Correct 528 ms 7592 KB Output is correct
61 Correct 390 ms 7636 KB Output is correct
62 Correct 477 ms 7640 KB Output is correct
63 Correct 459 ms 7632 KB Output is correct
64 Correct 399 ms 7632 KB Output is correct
65 Correct 430 ms 7628 KB Output is correct
66 Correct 569 ms 7508 KB Output is correct
67 Correct 422 ms 7632 KB Output is correct
68 Correct 414 ms 7716 KB Output is correct
69 Correct 476 ms 7636 KB Output is correct
70 Correct 460 ms 7632 KB Output is correct
71 Correct 498 ms 7528 KB Output is correct
72 Correct 440 ms 7768 KB Output is correct
73 Correct 417 ms 7508 KB Output is correct
74 Correct 434 ms 7620 KB Output is correct
75 Correct 432 ms 7620 KB Output is correct
76 Correct 709 ms 7728 KB Output is correct
77 Correct 420 ms 7616 KB Output is correct
78 Correct 586 ms 7640 KB Output is correct
79 Correct 478 ms 7632 KB Output is correct
80 Correct 612 ms 7604 KB Output is correct
81 Correct 572 ms 7632 KB Output is correct
82 Correct 380 ms 7636 KB Output is correct
83 Correct 527 ms 7640 KB Output is correct
84 Correct 1020 ms 7636 KB Output is correct
85 Correct 473 ms 7504 KB Output is correct
86 Correct 851 ms 7624 KB Output is correct
87 Correct 408 ms 7512 KB Output is correct
88 Correct 462 ms 7616 KB Output is correct
89 Correct 1553 ms 7744 KB Output is correct
90 Correct 537 ms 7680 KB Output is correct
91 Correct 938 ms 7636 KB Output is correct
92 Correct 606 ms 7640 KB Output is correct
93 Correct 618 ms 7632 KB Output is correct
94 Correct 423 ms 7520 KB Output is correct
95 Correct 393 ms 7616 KB Output is correct
96 Correct 765 ms 7744 KB Output is correct
97 Correct 581 ms 7640 KB Output is correct
98 Correct 761 ms 7628 KB Output is correct
99 Correct 2142 ms 7512 KB Output is correct
100 Correct 416 ms 7524 KB Output is correct
101 Correct 501 ms 7628 KB Output is correct
102 Correct 1620 ms 7616 KB Output is correct
103 Correct 610 ms 7748 KB Output is correct
104 Correct 1797 ms 7632 KB Output is correct
105 Correct 601 ms 7640 KB Output is correct
106 Correct 924 ms 7644 KB Output is correct
107 Correct 536 ms 7656 KB Output is correct
108 Correct 841 ms 7508 KB Output is correct
109 Correct 708 ms 7756 KB Output is correct
110 Correct 789 ms 7620 KB Output is correct
111 Correct 491 ms 7552 KB Output is correct
112 Correct 525 ms 7508 KB Output is correct
113 Correct 401 ms 7512 KB Output is correct
114 Correct 415 ms 7624 KB Output is correct
115 Correct 424 ms 7632 KB Output is correct
116 Correct 398 ms 7568 KB Output is correct
117 Execution timed out 3075 ms 7576 KB Time limit exceeded
118 Halted 0 ms 0 KB -