답안 #1021048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021048 2024-07-12T13:17:17 Z Blistering_Barnacles 분수 공원 (IOI21_parks) C++17
5 / 100
3500 ms 42632 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int construct_roads(vector<int> x, vector<int> y) {
    if (x.size() == 1) {
    build({}, {}, {}, {});
        return 1;
    }
    map<pair<int, int>, int> mp;
    vector<int> u, v, a, b;
    vector<pair<int, int>> e;
    int n = (int)x.size();
    for(int i = 0; i < n; i++){
        if(mp.count({x[i], y[i] - 2})){
            e.push_back({mp[{x[i], y[i] - 2}], i});
        }
        if(mp.count({x[i], y[i] + 2})){
            e.push_back({mp[{x[i], y[i] + 2}], i});
        }
        if(mp.count({x[i] - 2, y[i]})){
            e.push_back({mp[{x[i] - 2, y[i]}], i});
        }
        if(mp.count({x[i] + 2, y[i]})){
            e.push_back({mp[{x[i] + 2, y[i]}], i});
        }
        mp[{x[i], y[i]}] = i;
    }
    vector<int> par(n, -1);
    function<int(int)> getpar = [&](int x){
        return (par[x] < 0 ? x : par[x] = getpar(par[x]));
    };
    auto mrg = [&](int x, int y){
        x = getpar(x), y = getpar(y);
        if(x == y)return false;
        if(par[x] > par[y])swap(x, y);
        par[x] += par[y], par[y] = x;
        return true;
    };
    auto cmp = [&](pair<int, int> a, pair<int, int> b){
        auto [i1, j1] = a;
        auto [i2, j2] = b;
        if(x[i1] == x[j1]){
            if(x[i2] == x[j2]){
                return x[i1] < x[i2];
            }
            else{
                return x[i1] < max(x[i2], x[j2]);
            }
        }
        else{
            if(x[i2] == x[j2]){
                return min(x[i1], x[j1]) < x[i2];
            }
            else{
                return min(x[i1], x[j1]) < min(x[i2], x[j2]);
            }
        }
    };
    auto cmp2 = [&](pair<int, int> a, pair<int, int> b){
        auto [i1, j1] = a;
        auto [i2, j2] = b;
        if(x[i1] == x[j1]){
            if(x[i2] == x[j2]){
                return x[i1] < x[i2];
            }
            else{
                return true;
            }
        }
        else{
            if(x[i2] == x[j2]){
                return min(x[i1], x[j1]) < x[i2];
            }
            else{
                return min(x[i1], x[j1]) < min(x[i2], x[j2]);
            }
        }
    };
    auto op = e;
    sort(op.begin(), op.end(), cmp2);
    sort(e.begin(), e.end(), cmp);
    map<pair<int, int>, bool> vis;
    map<pair<int, int>, bool> tmp;
    for(auto [i, j]: op){
        tmp[{i, j}] = mrg(i, j);
    }
    for(auto [i, j]: e){
        if(tmp[{i, j}]){
            u.push_back(i), v.push_back(j);
            if(x[i] == x[j]){
                if(!vis.count({x[i] - 1, max(y[i], y[j]) - 1})){
                    vis[{x[i] - 1, max(y[i], y[j]) - 1}] = 1;
                    a.push_back(x[i] - 1);
                    b.push_back(max(y[i], y[j]) - 1);
                }
                else{
                    vis[{x[i] + 1, max(y[i], y[j]) - 1}] = 1;
                    a.push_back(x[i] + 1);
                    b.push_back(max(y[i], y[j]) - 1);
                }
            }
            else{
                if(!vis.count({max(x[i], x[j]) - 1, y[i] - 1})){
                    vis[{max(x[i], x[j]) - 1, y[i] - 1}] = 1;
                    a.push_back(max(x[i], x[j]) - 1);
                    b.push_back(y[i] - 1);
                }
                else{
                    vis[{max(x[i], x[j]) - 1, y[i] + 1}] = 1;
                    a.push_back(max(x[i], x[j]) - 1);
                    b.push_back(y[i] + 1);
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < n; i++)cnt += par[i] < 0;
    if(cnt > 1)return 0;
    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Execution timed out 3568 ms 21440 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Execution timed out 3568 ms 21440 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 764 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Runtime error 241 ms 42632 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
17 Execution timed out 3516 ms 21208 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 253 ms 27556 KB Output is correct
10 Correct 12 ms 3164 KB Output is correct
11 Correct 82 ms 14844 KB Output is correct
12 Correct 26 ms 4580 KB Output is correct
13 Correct 52 ms 10952 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 227 ms 27356 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Execution timed out 3568 ms 21440 KB Time limit exceeded
24 Halted 0 ms 0 KB -