Submission #1059539

# Submission time Handle Problem Language Result Execution time Memory
1059539 2024-08-15T04:51:42 Z pcc Fountain Parks (IOI21_parks) C++17
15 / 100
113 ms 22516 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 2e5+10;
int N;

struct DSU{
	int dsu[mxn];
	DSU(){
		iota(dsu,dsu+mxn,0);
	}
	int root(int k){
		return k == dsu[k]?k:dsu[k] = root(dsu[k]);
	}
	void onion(int a,int b){
		dsu[root(a)] = root(b);
	}
};

DSU dsu;

vector<int> ans[4];

void addans(int s,int e,int x,int y){
	dsu.onion(s,e);
	ans[0].push_back(s);
	ans[1].push_back(e);
	ans[2].push_back(x);
	ans[3].push_back(y);
	return;
}

int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
		build({}, {}, {}, {});
        return 1;
    }
	N = x.size();
	vector<int> v[2];
	for(int i = 0;i<N;i++){
		if(x[i] == 2)v[0].push_back(i);
		else v[1].push_back(i);
	}
	for(auto &i:v)sort(i.begin(),i.end(),[&](int a,int b){return y[a]<y[b];});
	map<int,int> mp;
	for(int i = 0;i<v[0].size();i++){
		int now = v[0][i];
		mp[y[now]] = now;
	}
	for(int i = 0;i<v[1].size();i++){
		int now = v[1][i];
		if(mp.find(y[now]) != mp.end()){
			addans(now,mp[y[now]],x[now]-1,y[now]-1);
		}
	}
	for(int i = 1;i<v[0].size();i++){
		int now = v[0][i],pre = v[0][i-1];
		if(y[pre]+2 == y[now]&&dsu.root(pre) != dsu.root(now))addans(pre,now,x[now]-1,(y[pre]+y[now])>>1);
	}
	for(int i = 1;i<v[1].size();i++){
		int now = v[1][i],pre = v[1][i-1];
		if(y[pre]+2 == y[now]&&dsu.root(pre) != dsu.root(now))addans(pre,now,x[now]+1,(y[pre]+y[now])>>1);
	}
	if(ans[0].size() != N-1)return 0;
	build(ans[0],ans[1],ans[2],ans[3]);
	return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0;i<v[0].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i = 0;i<v[1].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 1;i<v[0].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:65:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 1;i<v[1].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:69:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |  if(ans[0].size() != N-1)return 0;
      |     ~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
17 Correct 1 ms 1112 KB Output is correct
18 Correct 1 ms 1220 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1164 KB Output is correct
23 Correct 109 ms 22372 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 1436 KB Output is correct
27 Correct 2 ms 1372 KB Output is correct
28 Correct 39 ms 9644 KB Output is correct
29 Correct 60 ms 14152 KB Output is correct
30 Correct 87 ms 18240 KB Output is correct
31 Correct 111 ms 22516 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 1 ms 1116 KB Output is correct
34 Correct 1 ms 1112 KB Output is correct
35 Correct 0 ms 1116 KB Output is correct
36 Correct 1 ms 1116 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 0 ms 1116 KB Output is correct
39 Correct 1 ms 1372 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 0 ms 1116 KB Output is correct
43 Correct 1 ms 1372 KB Output is correct
44 Correct 1 ms 1236 KB Output is correct
45 Correct 52 ms 11084 KB Output is correct
46 Correct 74 ms 15420 KB Output is correct
47 Correct 73 ms 15424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
17 Correct 1 ms 1112 KB Output is correct
18 Correct 1 ms 1220 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1164 KB Output is correct
23 Correct 109 ms 22372 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 1436 KB Output is correct
27 Correct 2 ms 1372 KB Output is correct
28 Correct 39 ms 9644 KB Output is correct
29 Correct 60 ms 14152 KB Output is correct
30 Correct 87 ms 18240 KB Output is correct
31 Correct 111 ms 22516 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 1 ms 1116 KB Output is correct
34 Correct 1 ms 1112 KB Output is correct
35 Correct 0 ms 1116 KB Output is correct
36 Correct 1 ms 1116 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 0 ms 1116 KB Output is correct
39 Correct 1 ms 1372 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 0 ms 1116 KB Output is correct
43 Correct 1 ms 1372 KB Output is correct
44 Correct 1 ms 1236 KB Output is correct
45 Correct 52 ms 11084 KB Output is correct
46 Correct 74 ms 15420 KB Output is correct
47 Correct 73 ms 15424 KB Output is correct
48 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
17 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
17 Incorrect 113 ms 18244 KB Pair u[0]=141563 @(22700, 2) and v[0]=199575 @(2, 2) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 53 ms 12760 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 23 ms 7540 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 13 ms 5336 KB Output is correct
14 Correct 1 ms 1216 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 51 ms 12884 KB Output is correct
17 Correct 1 ms 1112 KB Output is correct
18 Correct 1 ms 1220 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1164 KB Output is correct
23 Correct 109 ms 22372 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 1436 KB Output is correct
27 Correct 2 ms 1372 KB Output is correct
28 Correct 39 ms 9644 KB Output is correct
29 Correct 60 ms 14152 KB Output is correct
30 Correct 87 ms 18240 KB Output is correct
31 Correct 111 ms 22516 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 1 ms 1116 KB Output is correct
34 Correct 1 ms 1112 KB Output is correct
35 Correct 0 ms 1116 KB Output is correct
36 Correct 1 ms 1116 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 0 ms 1116 KB Output is correct
39 Correct 1 ms 1372 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 0 ms 1116 KB Output is correct
43 Correct 1 ms 1372 KB Output is correct
44 Correct 1 ms 1236 KB Output is correct
45 Correct 52 ms 11084 KB Output is correct
46 Correct 74 ms 15420 KB Output is correct
47 Correct 73 ms 15424 KB Output is correct
48 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -