답안 #468947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468947 2021-08-30T09:14:39 Z Josia Building Bridges (CEOI17_building) C++14
0 / 100
60 ms 8700 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")


#include <bits/stdc++.h>

#define int int64_t

using namespace std;




int dijkstra(vector<pair<int, int>> pillars) {
    priority_queue<pair<int, int>> pq;

    pq.push({0, 0});

    vector<bool> visited(pillars.size());


    while (!pq.empty()) {
        int price = -pq.top().first;
        int v = pq.top().second;

        pq.pop();

        if (v==pillars.size()-1) return price;

        if (visited[v]) continue;
        visited[v] = 1;


        int destroyCost = 0;
        for (int i = v+1; i<pillars.size(); i++) {
            if (!visited[i]) pq.push({-price - destroyCost - (pillars[v].first-pillars[i].first)*(pillars[v].first-pillars[i].first), i});

            destroyCost += pillars[i].second;
        }

    }
    assert(false);
    return -1;


}




signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n; cin >> n;


    vector<pair<int, int>> pillars(n);

    for (int i = 0; i<n; i++) {
        cin >> pillars[i].first;
    }
    for (int i = 0; i<n; i++) {
        cin >> pillars[i].second;
    }

    pillars[0].second = 0;

    pillars.back().second = 0;


    cout << dijkstra(pillars) << "\n";


    return 0;
}

Compilation message

building.cpp: In function 'int64_t dijkstra(std::vector<std::pair<long int, long int> >)':
building.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (v==pillars.size()-1) return price;
      |             ~^~~~~~~~~~~~~~~~~~
building.cpp:36:28: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int i = v+1; i<pillars.size(); i++) {
      |                           ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 60 ms 8628 KB Output is correct
5 Incorrect 47 ms 8700 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 6604 KB Output is correct
2 Incorrect 25 ms 6600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 60 ms 8628 KB Output is correct
5 Incorrect 47 ms 8700 KB Output isn't correct