답안 #831873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831873 2023-08-20T16:32:41 Z andrey27_sm 분수 공원 (IOI21_parks) C++17
5 / 100
400 ms 37172 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> cons[200001];
int mask_l[200001];
vector<int> u;
vector<int> v;
vector<int> a;
vector<int> b;
struct dsu{
    int sz = 0;
    vector<int> pr;
    int p(int v){
        if(pr[v] == v) return v;
        return pr[v] = p(pr[v]);
    }
    bool un(int u,int v){
        u = p(u);
        v = p(v);
        if(u == v){
            return 0;
            exit(1);
        }
        pr[u] = v;
        sz++;
        return 1;
    }
} D;
int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    D.pr.resize(n);
    map<pair<int,int>,int> sol;
    for (int i = 0; i < n; ++i)
    {
        D.pr[i] = i;
    }
    vector<pair<int,pair<int,int>>> x_d;
    vector<pair<int,pair<int,int>>> y_d;
    for (int i = 0; i < n; ++i)
    {
        x_d.push_back({x[i],{y[i],i}});
        y_d.push_back({y[i],{x[i],i}});
        sol[{x[i],y[i]}] = i;
    }
    /*for(int i = 0;i < n;i++){
        assert(sol.count({x[i],y[i]}) + sol.count({x[i]+2,y[i]})+sol.count({x[i]+2,y[i]+2})+sol.count({x[i],y[i]+2}) < 4);
    }*/
    sort(x_d.begin(), x_d.end());
    sort(y_d.begin(), y_d.end());
    for (int i = 1; i < n; ++i)
    {
        if(x_d[i].first == x_d[i-1].first and x_d[i].second.first-2 == x_d[i-1].second.first){
            D.un(x_d[i-1].second.second,x_d[i].second.second);
        }
    }
    for (int i = 1; i < n; ++i)
    {
        if(y_d[i].first == y_d[i-1].first and y_d[i].second.first-2 == y_d[i-1].second.first){
            D.un(y_d[i-1].second.second,y_d[i].second.second);
        }
    }
    if(D.sz != n-1) return 0;
    for (int i = 0; i < n; ++i)
    {
        if(sol.count({x[i],y[i]+2}) and (((x[i]+y[i])&3) != 1 or !(sol.count({x[i]+2,y[i]+2}) and sol.count({x[i]+2,y[i]})))) {
            u.push_back(sol[{x[i],y[i]+2}]);
            v.push_back(i);
            if((x[i]+y[i])&3) a.push_back(x[i]+1);
            else a.push_back(x[i]-1);
            b.push_back(y[i]+1);
        }

        if(sol.count({x[i]+2,y[i]}) and (((x[i]+y[i])&3) != 0 or !(sol.count({x[i]+2,y[i]+2}) and sol.count({x[i]+2,y[i]})))){
            u.push_back(sol[{x[i]+2,y[i]}]);
            v.push_back(i);
            if((x[i]+y[i])&3) b.push_back(y[i]-1);
            else b.push_back(y[i]+1);
            a.push_back(x[i]+1);
        }
    }
    //if(points.size() != n-1) return 0;
    build(u,v,a,b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
17 Incorrect 4 ms 4948 KB Given structure is not connected: There is no path between vertices 0 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
17 Correct 400 ms 37168 KB Output is correct
18 Correct 366 ms 37172 KB Output is correct
19 Incorrect 396 ms 35584 KB Given structure is not connected: There is no path between vertices 0 and 1
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5008 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 143 ms 20792 KB Output is correct
10 Correct 10 ms 6652 KB Output is correct
11 Correct 55 ms 13624 KB Output is correct
12 Correct 18 ms 7448 KB Output is correct
13 Correct 19 ms 9924 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5184 KB Output is correct
16 Correct 127 ms 20808 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -