답안 #1059532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059532 2024-08-15T04:47:12 Z pcc 분수 공원 (IOI21_parks) C++17
5 / 100
86 ms 16836 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[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;
      |     ~~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
17 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
17 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
17 Incorrect 1 ms 1116 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
17 Incorrect 86 ms 16836 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 56 ms 12872 KB Output is correct
10 Correct 6 ms 2396 KB Output is correct
11 Correct 23 ms 7512 KB Output is correct
12 Correct 7 ms 3160 KB Output is correct
13 Correct 12 ms 5336 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 86 ms 12876 KB Output is correct
17 Incorrect 1 ms 1112 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -