답안 #603000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603000 2022-07-23T14:06:19 Z FatihSolak 분수 공원 (IOI21_parks) C++17
5 / 100
636 ms 38868 KB
#include "parks.h"
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int par[N];
int find(int a){
    if(a == par[a])return a;
    return par[a] = find(par[a]);
}
bool merge(int a,int b){
    a = find(a);
    b = find(b);
    if(a == b)
        return 0;
    par[a] = b;
    return 1;
}
int construct_roads(vector<int> x, vector<int> y) {
    if (x.size() == 1) {
	    build({}, {}, {}, {});
        return 1;
    }
    int n = x.size();
    map<pair<int,int>,int> mp;
    for(int i = 0;i<n;i++){
        par[i] = i;
        mp[{x[i],y[i]}] = i;
    }
    vector<int> u, v, a, b;
    for(int i = 0;i<n;i++){
        for(auto dx:{-2,0,2}){
            for(auto dy:{-2,0,2}){
                if(abs(dx) + abs(dy) != 2)continue;
                if(!mp.count({x[i]+dx,y[i]+dy}))continue;
                if(merge(i,mp[{x[i]+dx,y[i]+dy}])){
                    u.push_back(i);
                    v.push_back(mp[{x[i]+dx,y[i]+dy}]);
                }
            }
        }
    }
    if(u.size() != n-1)
        return 0;
    map<pair<int,int>,int> used;
    for(int i = 0;i<n-1;i++){
        bool ok = 0;
        for(auto dx:{-1,1}){
            for(auto dy:{-1,1}){
                if(ok)continue;
                if(used.count({x[u[i]]+dx,y[u[i]]+dy}))continue;     
                if(abs(x[u[i]]+dx - x[v[i]]) != 1 || abs(y[u[i]]+dy - y[v[i]]) != 1)continue;
                used[{x[u[i]]+dx,y[u[i]]+dy}] = 1;
                a.push_back(x[u[i]] + dx);
                b.push_back(y[u[i]] + dy);
                ok = 1;
            }
        }
    }
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:42:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |     if(u.size() != n-1)
      |        ~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Incorrect 591 ms 35780 KB Wrong answer detected in grader
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Incorrect 591 ms 35780 KB Wrong answer detected in grader
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 308 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 572 ms 33820 KB Wrong answer detected in grader
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
17 Correct 636 ms 38868 KB Output is correct
18 Incorrect 513 ms 35772 KB Wrong answer detected in grader
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 226 ms 19732 KB Output is correct
10 Correct 14 ms 2496 KB Output is correct
11 Correct 95 ms 10832 KB Output is correct
12 Correct 22 ms 3516 KB Output is correct
13 Correct 44 ms 4680 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 217 ms 19744 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Incorrect 591 ms 35780 KB Wrong answer detected in grader
24 Halted 0 ms 0 KB -