Submission #218234

# Submission time Handle Problem Language Result Execution time Memory
218234 2020-04-01T15:10:58 Z MiricaMatei Hamburg Steak (JOI20_hamburg) C++14
21 / 100
3000 ms 7544 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;
const int MAXK = 4;
const int INF = 1000000000;

struct Drept {
  int x1, y1, x2, y2;
} v[MAXN], sol[MAXK + 5], sol1[MAXN + 5], sol2[MAXN + 5];

pair<bool, Drept> inters(const Drept& a, const Drept& b) {
  Drept c;
  c.x1 = max(a.x1, b.x1);
  c.y1 = max(a.y1, b.y1);
  c.x2 = min(a.x2, b.x2);
  c.y2 = min(a.y2, b.y2);
  if (c.x1 <= c.x2 && c.y1 <= c.y2)
    return {1, c};
  return {0, c};
}

int main() {
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);

  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d%d%d", &v[i].x1, &v[i].y1, &v[i].x2, &v[i].y2);

  shuffle(v + 1, v + n + 1, rng);
  while (1) {
    for (int i = 1; i <= k; ++i)
      sol[i] = {1, 1, INF, INF};
    bool gas = 1;
    int m = 0, t = 0;
    for (int i = 1; i <= n; ++i) {
      bool ok = 0;
      for (int j = 1; j <= k; ++j) {
        pair<bool, Drept>aux = inters(sol[j], v[i]);
        if (aux.first) {
          swap(sol[j], aux.second);
          ok = 1;
          sol2[++t] = v[i];
          break;
        }
      }
      if (!ok) {
        gas = 0;
        sol1[++m] = v[i];
      }
    }
    if (gas) {
      for (int i = 1; i <= k; ++i)
        printf("%d %d\n", sol[i].x1, sol[i].y1);
      return 0;
    }
    shuffle(sol1 + 1, sol1 + m + 1, rng);
    for (int i = 1; i <= m; ++i)
      v[i] = sol1[i];
    for (int i = 1; i <= t; ++i)
      v[m + i] = sol2[i];
  }

  return 0;
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     scanf("%d%d%d%d", &v[i].x1, &v[i].y1, &v[i].x2, &v[i].y2);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 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 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 145 ms 6520 KB Output is correct
6 Correct 149 ms 6648 KB Output is correct
7 Correct 143 ms 6520 KB Output is correct
8 Correct 150 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 165 ms 6924 KB Output is correct
6 Correct 152 ms 6648 KB Output is correct
7 Correct 154 ms 6648 KB Output is correct
8 Correct 189 ms 6828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 161 ms 6612 KB Output is correct
14 Correct 156 ms 7032 KB Output is correct
15 Correct 154 ms 6776 KB Output is correct
16 Correct 166 ms 6624 KB Output is correct
17 Correct 161 ms 6776 KB Output is correct
18 Correct 150 ms 6632 KB Output is correct
19 Correct 175 ms 7352 KB Output is correct
20 Correct 166 ms 7320 KB Output is correct
21 Correct 165 ms 7544 KB Output is correct
22 Correct 160 ms 7032 KB Output is correct
23 Correct 165 ms 7248 KB Output is correct
24 Correct 163 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 166 ms 6648 KB Output is correct
60 Correct 170 ms 6640 KB Output is correct
61 Correct 166 ms 7160 KB Output is correct
62 Correct 155 ms 6648 KB Output is correct
63 Correct 177 ms 6932 KB Output is correct
64 Correct 157 ms 6648 KB Output is correct
65 Correct 181 ms 6756 KB Output is correct
66 Correct 210 ms 6776 KB Output is correct
67 Correct 171 ms 6908 KB Output is correct
68 Correct 166 ms 7032 KB Output is correct
69 Correct 173 ms 7160 KB Output is correct
70 Correct 180 ms 7160 KB Output is correct
71 Correct 155 ms 6740 KB Output is correct
72 Correct 172 ms 7160 KB Output is correct
73 Correct 168 ms 7044 KB Output is correct
74 Correct 155 ms 7068 KB Output is correct
75 Correct 166 ms 6884 KB Output is correct
76 Correct 180 ms 7160 KB Output is correct
77 Correct 171 ms 7240 KB Output is correct
78 Correct 160 ms 7160 KB Output is correct
79 Correct 175 ms 7032 KB Output is correct
80 Correct 156 ms 7032 KB Output is correct
81 Correct 167 ms 6872 KB Output is correct
82 Correct 173 ms 6852 KB Output is correct
83 Correct 161 ms 6904 KB Output is correct
84 Correct 197 ms 6904 KB Output is correct
85 Correct 157 ms 6596 KB Output is correct
86 Correct 161 ms 7160 KB Output is correct
87 Correct 165 ms 7160 KB Output is correct
88 Correct 155 ms 6904 KB Output is correct
89 Correct 159 ms 6776 KB Output is correct
90 Correct 190 ms 7372 KB Output is correct
91 Correct 169 ms 6920 KB Output is correct
92 Correct 155 ms 6664 KB Output is correct
93 Correct 173 ms 7360 KB Output is correct
94 Correct 180 ms 7160 KB Output is correct
95 Correct 168 ms 7180 KB Output is correct
96 Correct 176 ms 7160 KB Output is correct
97 Correct 171 ms 7032 KB Output is correct
98 Correct 166 ms 6852 KB Output is correct
99 Correct 171 ms 7064 KB Output is correct
100 Correct 183 ms 7288 KB Output is correct
101 Correct 164 ms 6904 KB Output is correct
102 Correct 156 ms 6776 KB Output is correct
103 Correct 164 ms 7236 KB Output is correct
104 Correct 155 ms 6904 KB Output is correct
105 Correct 157 ms 7032 KB Output is correct
106 Correct 205 ms 6940 KB Output is correct
107 Correct 167 ms 7084 KB Output is correct
108 Correct 183 ms 7032 KB Output is correct
109 Correct 165 ms 6908 KB Output is correct
110 Correct 169 ms 7012 KB Output is correct
111 Correct 182 ms 7072 KB Output is correct
112 Correct 154 ms 6780 KB Output is correct
113 Correct 159 ms 6708 KB Output is correct
114 Correct 175 ms 6776 KB Output is correct
115 Correct 157 ms 6776 KB Output is correct
116 Correct 177 ms 6904 KB Output is correct
117 Execution timed out 3069 ms 6752 KB Time limit exceeded
118 Halted 0 ms 0 KB -