답안 #829495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829495 2023-08-18T11:32:02 Z Abrar_Al_Samit 분수 공원 (IOI21_parks) C++17
0 / 100
148 ms 17176 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;

const int nax = 200000;
vector<int>g[nax];
bool vis[nax];
int par[nax], sz[nax];

void trav(int v) {
    vis[v] = 1;
    for(int u : g[v]) if(!vis[u]) {
        trav(u);
    }
}

int find(int v) {
    return par[v] = (v==par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
    u = find(u), v = find(v);
    if(sz[u] < sz[v]) swap(u, v);
    sz[u] += sz[v];
    par[v] = u;
}
int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    map<pair<int,int>, int>ft;
    for(int i=0; i<n; ++i) {
        ft[{x[i], y[i]}] = i;
    }

    int dx[] = {2, -2, 0, 0};
    int dy[] = {0, 0, 2, -2};

    vector<int>u, v, a, b;

    map<pair<int,int>, int>ben;

    for(int i=0; i<n; ++i) {
        par[i] = i, sz[i] = 1;
    }
    for(int i=0; i<n; ++i) {
        for(int j=0; j<4; ++j) {
            int nx = x[i] + dx[j], ny = y[i] + dy[j];
            if(ft.count(make_pair(nx, ny))) {
                if(find(i) == find(ft[{nx, ny}])) continue;

                g[i].push_back(ft[{nx, ny}]);
                unite(i, ft[{nx, ny}]);
                u.push_back(i);
                v.push_back(ft[{nx, ny}]);

                if(j < 2) { //horizontal
                    if(!ben.count(make_pair(x[i] + nx >> 1, ny - 1))) {
                        ben[{x[i] + nx >> 1, ny - 1}] = 1;
                        a.push_back(x[i] + nx >> 1);
                        b.push_back(ny - 1);
                    } else if(!ben.count(make_pair(x[i] + nx >> 1, ny + 1))) {
                        ben[{x[i] + nx >> 1, ny + 1}] = 1;
                        a.push_back(x[i] + nx >> 1);
                        b.push_back(ny + 1);

                    } else assert(0);
                } else { //vertical
                    if(x[i]==2) {
                        a.push_back(x[i] - 1);
                        b.push_back(y[i] + ny >> 1);
                    } else if(x[i]==6) {
                        a.push_back(x[i] + 1);
                        b.push_back(y[i] + ny >> 1);
                    } else {
                        if(!ben.count(make_pair(nx-1, y[i] + ny >> 1))) {
                            ben[{nx-1, y[i] + ny >> 1}] = 1;
                            a.push_back(nx-1);
                            b.push_back(y[i] + ny >> 1);
                        } else if(!ben.count(make_pair(nx+1, y[i] + ny >> 1))) {
                            ben[{nx+1, y[i] + ny >> 1}] = 1;
                            a.push_back(nx+1);
                            b.push_back(y[i] + ny >> 1);
                        } else assert(0);
                    }
                }
            }
        }
    }
    trav(0);
    for(int i=0; i<n; ++i) if(!vis[i]) {
        return 0;
    }

    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:55:50: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |                     if(!ben.count(make_pair(x[i] + nx >> 1, ny - 1))) {
parks.cpp:56:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |                         ben[{x[i] + nx >> 1, ny - 1}] = 1;
parks.cpp:57:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |                         a.push_back(x[i] + nx >> 1);
parks.cpp:59:57: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |                     } else if(!ben.count(make_pair(x[i] + nx >> 1, ny + 1))) {
parks.cpp:60:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |                         ben[{x[i] + nx >> 1, ny + 1}] = 1;
parks.cpp:61:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |                         a.push_back(x[i] + nx >> 1);
parks.cpp:68:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |                         b.push_back(y[i] + ny >> 1);
parks.cpp:71:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |                         b.push_back(y[i] + ny >> 1);
parks.cpp:73:60: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |                         if(!ben.count(make_pair(nx-1, y[i] + ny >> 1))) {
parks.cpp:74:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |                             ben[{nx-1, y[i] + ny >> 1}] = 1;
parks.cpp:76:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |                             b.push_back(y[i] + ny >> 1);
parks.cpp:77:67: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |                         } else if(!ben.count(make_pair(nx+1, y[i] + ny >> 1))) {
parks.cpp:78:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |                             ben[{nx+1, y[i] + ny >> 1}] = 1;
parks.cpp:80:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |                             b.push_back(y[i] + ny >> 1);
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 148 ms 17176 KB Solution announced impossible, but it is possible.
10 Halted 0 ms 0 KB -