Submission #987298

# Submission time Handle Problem Language Result Execution time Memory
987298 2024-05-22T14:11:06 Z cig32 Fountain Parks (IOI21_parks) C++17
15 / 100
472 ms 68472 KB
#include "parks.h"
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 12;
int dsu[MAXN];
int set_of(int u) {
  if(dsu[u] == u) return u;
  return dsu[u] = set_of(dsu[u]);
}
void union_(int u, int v) {
  dsu[set_of(u)] = set_of(v);
}

int construct_roads(std::vector<int> x, std::vector<int> y) {
  if (x.size() == 1) {
    build({}, {}, {}, {});
    return 1;
  }
  int n = x.size();
  pair<pair<int, int>, int> p[n];
  vector<int> stox = x, stoy = y;
  for(int i=0; i<n; i++) {
    p[i].first.first = x[i];
    p[i].first.second = y[i];
    p[i].second = i;
  }
  sort(p, p + n);
  for(int i=0; i<n; i++) x[i] = stox[p[i].second], y[i] = stoy[p[i].second];
  std::vector<int> u, v, a, b;
  map<pair<int, int>, int> mp;
  map<pair<int, int>, pair<int,int> > buh;
  set<pair<int, int>> bench;
  
  for(int i=0; i<n; i++) dsu[i] = i;
  for(int i=0; i<n; i++) {
    mp[{x[i], y[i]}] = i;
  }
  vector<pair<int,int>> edges;
  map<pair<int,int>, bool> wtf;
  for(int i=0; i<n; i++) {
    if(mp.count({x[i] + 2, y[i]})) {
      int U = i, V = mp[{x[i] + 2, y[i]}];
      wtf[{x[i], y[i]}] = 1;
      edges.push_back({U, V});
      union_(U, V);
    }
  }
  for(int i=0; i<n; i++) {
    if(mp.count({x[i], y[i] + 2})) {
      int U = i, V = mp[{x[i], y[i] + 2}];
      if(set_of(U) != set_of(V)) {
        edges.push_back({U, V});
        union_(U, V);
        if(!wtf.count({x[i] - 2, y[i] + 2}) && !wtf.count({x[i] - 2, y[i]})) {
          bench.insert({x[i] - 1, y[i] + 1});
          buh[{U, V}] = {x[i] - 1, y[i] + 1};
        }
        else if(!wtf.count({x[i], y[i]}) && !wtf.count({x[i], y[i] + 2})) {
          bench.insert({x[i] + 1, y[i] + 1});
          buh[{U, V}] = {x[i] + 1, y[i] + 1};
        }
        else if(!wtf.count({x[i] - 2, y[i] + 2}) || !wtf.count({x[i] - 2, y[i]})) {
          bench.insert({x[i] - 1, y[i] + 1});
          buh[{U, V}] = {x[i] - 1, y[i] + 1};
        }
        else {
          bench.insert({x[i] + 1, y[i] + 1});
          buh[{U, V}] = {x[i] + 1, y[i] + 1};
        }
      }
    }
  }
  for(int i=0; i<n; i++) {
    if(mp.count({x[i] + 2, y[i]})) {
      int U = i, V = mp[{x[i] + 2, y[i]}];
      if(!bench.count({x[i] + 1, y[i] - 1})) {
        bench.insert({x[i] + 1, y[i] - 1});
        buh[{U, V}] = {x[i] + 1, y[i] - 1};
      }
      else if(!bench.count({x[i] + 1, y[i] + 1})) {
        bench.insert({x[i] + 1, y[i] + 1});
        buh[{U, V}] = {x[i] + 1, y[i] + 1};
      }
      else return 0;
    }
  }
  for(int i=1; i<n; i++) if(set_of(i) != set_of(i-1)) return 0;
  for(auto x: edges) {
    int U = x.first, V = x.second;
    u.push_back(p[U].second);
    v.push_back(p[V].second);
    pair<int, int> wow = buh[{U, V}];
    a.push_back(wow.first);
    b.push_back(wow.second);
  }
  build(u, v, a, b);
  return 1;
}

/*

#!/bin/bash

problem=parks
grader_name=grady

g++ -std=c++17 -O2 -o "${problem}" "${grader_name}.cpp" "${problem}.cpp"
./parks < input.txt
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 376 ms 63596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 4 ms 1112 KB Output is correct
27 Correct 4 ms 1372 KB Output is correct
28 Correct 147 ms 25756 KB Output is correct
29 Correct 227 ms 38092 KB Output is correct
30 Correct 291 ms 51408 KB Output is correct
31 Correct 396 ms 63476 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 444 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 183 ms 30664 KB Output is correct
46 Correct 290 ms 44992 KB Output is correct
47 Correct 302 ms 44900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 376 ms 63596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 4 ms 1112 KB Output is correct
27 Correct 4 ms 1372 KB Output is correct
28 Correct 147 ms 25756 KB Output is correct
29 Correct 227 ms 38092 KB Output is correct
30 Correct 291 ms 51408 KB Output is correct
31 Correct 396 ms 63476 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 444 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 183 ms 30664 KB Output is correct
46 Correct 290 ms 44992 KB Output is correct
47 Correct 302 ms 44900 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 429 ms 65208 KB Output is correct
56 Incorrect 1 ms 344 KB Solution announced impossible, but it is possible.
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 472 ms 63512 KB Output is correct
21 Correct 439 ms 64676 KB Output is correct
22 Correct 463 ms 63216 KB Output is correct
23 Correct 313 ms 55948 KB Output is correct
24 Correct 131 ms 22356 KB Output is correct
25 Correct 343 ms 58304 KB Output is correct
26 Correct 240 ms 45760 KB Output is correct
27 Correct 331 ms 56036 KB Output is correct
28 Correct 302 ms 56004 KB Output is correct
29 Correct 457 ms 68344 KB Output is correct
30 Correct 457 ms 68472 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Incorrect 14 ms 3160 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
17 Correct 401 ms 63320 KB Output is correct
18 Correct 388 ms 63516 KB Output is correct
19 Incorrect 280 ms 41828 KB Solution announced impossible, but it is possible.
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 158 ms 29544 KB Output is correct
10 Correct 14 ms 3336 KB Output is correct
11 Correct 71 ms 16016 KB Output is correct
12 Correct 18 ms 4836 KB Output is correct
13 Correct 44 ms 10896 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 162 ms 29380 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 376 ms 63596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 4 ms 1112 KB Output is correct
27 Correct 4 ms 1372 KB Output is correct
28 Correct 147 ms 25756 KB Output is correct
29 Correct 227 ms 38092 KB Output is correct
30 Correct 291 ms 51408 KB Output is correct
31 Correct 396 ms 63476 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 444 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 183 ms 30664 KB Output is correct
46 Correct 290 ms 44992 KB Output is correct
47 Correct 302 ms 44900 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 429 ms 65208 KB Output is correct
56 Incorrect 1 ms 344 KB Solution announced impossible, but it is possible.
57 Halted 0 ms 0 KB -