답안 #447900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447900 2021-07-28T05:14:35 Z blue Road Construction (JOI21_road_construction) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
using namespace std;

long long abs_diff(long long a, long long b)
{
    return max(a-b, b-a);
}

int main()
{
    int N, K;
    cin >> N >> K;

    long long X[N], Y[N];
    for(int i = 0; i < N; i++) cin >> X[i] >> Y[i];


    vector<long long> res;
    for(int i = 0; i < N; i++)
        for(int j = i+1; j < N; j++)
            res.push_back(abs_diff(X[i], X[j]) + abs_diff(Y[i], Y[j]));

    sort(res.begin(), res.end());

    while(res.size() > K) res.pop_back();

    for(long long r:res) cout << r << ' ';
    cout << '\n';
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:18:5: error: 'vector' was not declared in this scope
   18 |     vector<long long> res;
      |     ^~~~~~
road_construction.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
road_construction.cpp:18:12: error: expected primary-expression before 'long'
   18 |     vector<long long> res;
      |            ^~~~
road_construction.cpp:21:13: error: 'res' was not declared in this scope
   21 |             res.push_back(abs_diff(X[i], X[j]) + abs_diff(Y[i], Y[j]));
      |             ^~~
road_construction.cpp:23:10: error: 'res' was not declared in this scope
   23 |     sort(res.begin(), res.end());
      |          ^~~
road_construction.cpp:23:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   23 |     sort(res.begin(), res.end());
      |     ^~~~
      |     qsort