답안 #1021031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021031 2024-07-12T13:05:08 Z mdn2002 분수 공원 (IOI21_parks) C++17
컴파일 오류
0 ms 0 KB
/*
Mayoeba Yabureru
*/
#include<bits/stdc++.h>
using namespace std;
static vector<int> _u, _v, _a, _b;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
    _u = u;
    _v = v;
    _a = a;
    _b = b;
}

int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    if (n == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    x.insert(x.begin(), 0);
    y.insert(y.begin(), 0);
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; i ++) mp[{x[i], y[i]}] = i;
    vector<int> u, v, a, b;

    map<pair<pair<int, int>, pair<int, int>>, int> connected;
    map<pair<int, int>, int> taken;
    for (int i = 1; i <= n; i ++) {
        if (x[i] == 2 && mp[{x[i], y[i] + 2}]) {
            connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
            u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
            a.push_back(x[i] - 1), b.push_back(y[i] + 1);
            taken[{x[i] - 1, y[i] + 1}] = 1;
        }
        else if (x[i] == 6 && mp[{x[i], y[i] + 2}]) {
            connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
            u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
            a.push_back(x[i] + 1), b.push_back(y[i] + 1);
            taken[{x[i] + 1, y[i] + 1}] = 1;
        }
        else if (x[i] == 4 && mp[{x[i], y[i] + 2}]) {
            connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
            u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);

            if (y[i] % 4 == 2) a.push_back(x[i] + 1);
            else a.push_back(x[i] - 1);
            b.push_back(y[i] + 1);
            taken[{a.back(), b.back()}] = 1;
        }
    }
    for (int i = 1; i <= n; i ++) {
        if (x[i] == 2 && mp[{x[i] + 2, y[i]}]) {
            if (connected[{{x[i], y[i] - 2}, {x[i] + 2, y[i] - 2}}] == 1) continue;
            u.push_back(i), v.push_back(mp[{x[i] + 2, y[i]}]);
            if (taken[{x[i] + 1, y[i] + 1}] == 0) a.push_back(x[i] + 1), b.push_back(y[i] + 1);
            else if (taken[{x[i] + 1, y[i] - 1}] == 0) a.push_back(x[i] + 1), b.push_back(y[i] - 1);
            else assert(0);
        }
        else if (x[i] == 6 && mp[{x[i] - 2, y[i]}]) {
            if (connected[{{x[i], y[i] - 2}, {x[i] - 2, y[i] - 2}}] == 1) continue;
            u.push_back(i), v.push_back(mp[{x[i] - 2, y[i]}]);
            if (taken[{x[i] - 1, y[i] + 1}] == 0) a.push_back(x[i] - 1), b.push_back(y[i] + 1);
            else if (taken[{x[i] - 1, y[i] - 1}] == 0) a.push_back(x[i] - 1), b.push_back(y[i] - 1);
            else assert(0);
        }
    }
    for (int i = 0; i < u.size(); i ++) {
        u[i] --;
        v[i] --;
    }
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i = 0; i < u.size(); i ++) {
      |                     ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cc8Y1SUI.o: in function `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x270): multiple definition of `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccCEh0ZH.o:parks.cpp:(.text+0x4f0): first defined here
collect2: error: ld returned 1 exit status