Submission #987225

# Submission time Handle Problem Language Result Execution time Memory
987225 2024-05-22T11:31:56 Z cig32 Fountain Parks (IOI21_parks) C++17
45 / 100
400 ms 58464 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;
  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]}];
      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((x[i] + y[i]) % 4 == 2) {
          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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 348 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 348 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 387 ms 57292 KB Output is correct
21 Correct 374 ms 58188 KB Output is correct
22 Correct 360 ms 56808 KB Output is correct
23 Correct 310 ms 49088 KB Output is correct
24 Correct 122 ms 22480 KB Output is correct
25 Correct 306 ms 45760 KB Output is correct
26 Correct 239 ms 45780 KB Output is correct
27 Correct 335 ms 56004 KB Output is correct
28 Correct 322 ms 55988 KB Output is correct
29 Correct 374 ms 56072 KB Output is correct
30 Correct 400 ms 56016 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 20 ms 4584 KB Output is correct
33 Correct 81 ms 11868 KB Output is correct
34 Correct 366 ms 58464 KB Output is correct
35 Correct 11 ms 2668 KB Output is correct
36 Correct 59 ms 11872 KB Output is correct
37 Correct 126 ms 23520 KB Output is correct
38 Correct 161 ms 23400 KB Output is correct
39 Correct 199 ms 31368 KB Output is correct
40 Correct 252 ms 40964 KB Output is correct
41 Correct 301 ms 49172 KB Output is correct
42 Correct 398 ms 57332 KB Output is correct
43 Correct 2 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 448 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 860 KB Output is correct
55 Correct 3 ms 1116 KB Output is correct
56 Correct 166 ms 28620 KB Output is correct
57 Correct 252 ms 42056 KB Output is correct
58 Correct 275 ms 42268 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 335 ms 57296 KB Output is correct
63 Correct 346 ms 57280 KB Output is correct
64 Correct 332 ms 56256 KB Output is correct
65 Correct 4 ms 1116 KB Output is correct
66 Correct 8 ms 2140 KB Output is correct
67 Correct 159 ms 28336 KB Output is correct
68 Correct 282 ms 43112 KB Output is correct
69 Correct 380 ms 56516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
17 Correct 357 ms 56988 KB Output is correct
18 Correct 366 ms 57324 KB Output is correct
19 Correct 344 ms 57552 KB Output is correct
20 Correct 356 ms 54800 KB Output is correct
21 Correct 307 ms 49352 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 46 ms 9484 KB Output is correct
24 Correct 22 ms 4944 KB Output is correct
25 Correct 87 ms 16592 KB Output is correct
26 Correct 170 ms 27972 KB Output is correct
27 Correct 164 ms 28872 KB Output is correct
28 Correct 216 ms 35628 KB Output is correct
29 Correct 277 ms 44016 KB Output is correct
30 Correct 325 ms 50272 KB Output is correct
31 Correct 371 ms 57444 KB Output is correct
32 Correct 357 ms 57032 KB Output is correct
33 Correct 349 ms 57316 KB Output is correct
34 Correct 5 ms 1372 KB Output is correct
35 Correct 9 ms 2396 KB Output is correct
36 Correct 167 ms 28176 KB Output is correct
37 Correct 247 ms 42792 KB Output is correct
38 Correct 365 ms 56008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 164 ms 29456 KB Output is correct
10 Correct 15 ms 3336 KB Output is correct
11 Correct 77 ms 15888 KB Output is correct
12 Correct 18 ms 4904 KB Output is correct
13 Correct 52 ms 10744 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 165 ms 29384 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 348 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -