Submission #987156

# Submission time Handle Problem Language Result Execution time Memory
987156 2024-05-22T05:52:53 Z cig32 Fountain Parks (IOI21_parks) C++17
15 / 100
730 ms 53272 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;
  }
  std::vector<int> u, v, a, b;
  map<pair<int, int>, int> mp;
  int n = x.size();
  for(int i=0; i<n; i++) {
    mp[{x[i], y[i]}] = i;
  }
  for(int i=0; i<n; i++) {
    if(mp[{x[i], y[i] + 2}] > i) {
      u.push_back(mp[{x[i], y[i] + 2}]);
      v.push_back(i);
      a.push_back((x[i] == 2 ? 1 : 5));
      b.push_back(y[i] + 1);
    }
    if(mp[{x[i], y[i] - 2}] > i) {
      u.push_back(mp[{x[i], y[i] - 2}]);
      v.push_back(i);
      a.push_back((x[i] == 2 ? 1 : 5));
      b.push_back(y[i] - 1);
    }
    if(mp[{x[i] + 2, y[i]}] > i) {
      u.push_back(mp[{x[i] + 2, y[i]}]);
      v.push_back(i);
      a.push_back(3);
      b.push_back(y[i] - 1);
    }
    if(mp[{x[i] - 2, y[i]}] > i) {
      u.push_back(mp[{x[i] - 2, y[i]}]);
      v.push_back(i);
      a.push_back(3);
      b.push_back(y[i] - 1);
    }
  }
  for(int i=0; i<n; i++) dsu[i] = i;
  for(int i=0; i<u.size(); i++) {
    union_(u[i], v[i]);
  }
  for(int i=1; i<n; i++) if(set_of(i) != set_of(i-1)) return 0;
  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
*/

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int i=0; i<u.size(); i++) {
      |                ~^~~~~~~~~
# 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 692 ms 44996 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 5 ms 1112 KB Output is correct
28 Correct 158 ms 18104 KB Output is correct
29 Correct 297 ms 27240 KB Output is correct
30 Correct 474 ms 36260 KB Output is correct
31 Correct 664 ms 44948 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 348 KB Output is correct
35 Correct 1 ms 372 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 238 ms 22676 KB Output is correct
46 Correct 457 ms 32676 KB Output is correct
47 Correct 432 ms 32792 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 692 ms 44996 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 5 ms 1112 KB Output is correct
28 Correct 158 ms 18104 KB Output is correct
29 Correct 297 ms 27240 KB Output is correct
30 Correct 474 ms 36260 KB Output is correct
31 Correct 664 ms 44948 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 348 KB Output is correct
35 Correct 1 ms 372 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 238 ms 22676 KB Output is correct
46 Correct 457 ms 32676 KB Output is correct
47 Correct 432 ms 32792 KB Output is correct
48 Incorrect 1 ms 348 KB Tree (a[1], b[1]) = (3, 1) is not adjacent to edge between u[1]=1 @(4, 2) and v[1]=0 @(6, 2)
49 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 KB Output is correct
17 Incorrect 1 ms 348 KB Tree (a[0], b[0]) = (5, 3) is not adjacent to edge between u[0]=1 @(200000, 4) and v[0]=0 @(200000, 2)
18 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 KB Output is correct
17 Incorrect 730 ms 53272 KB Tree (a[0], b[0]) = (3, 100001) is not adjacent to edge between u[0]=168975 @(82424, 100002) and v[0]=0 @(82422, 100002)
18 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 376 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 274 ms 26552 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 70 ms 14412 KB Output is correct
12 Correct 16 ms 4424 KB Output is correct
13 Correct 44 ms 10440 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 251 ms 26636 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 692 ms 44996 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 5 ms 1112 KB Output is correct
28 Correct 158 ms 18104 KB Output is correct
29 Correct 297 ms 27240 KB Output is correct
30 Correct 474 ms 36260 KB Output is correct
31 Correct 664 ms 44948 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 348 KB Output is correct
35 Correct 1 ms 372 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 238 ms 22676 KB Output is correct
46 Correct 457 ms 32676 KB Output is correct
47 Correct 432 ms 32792 KB Output is correct
48 Incorrect 1 ms 348 KB Tree (a[1], b[1]) = (3, 1) is not adjacent to edge between u[1]=1 @(4, 2) and v[1]=0 @(6, 2)
49 Halted 0 ms 0 KB -