답안 #86571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
86571 2018-11-26T15:53:10 Z tjdgus4384 주유소 (KOI16_gas) C++14
0 / 100
1284 ms 66560 KB
#include<cstdio>
#include<vector>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int, int> pi;
typedef pair<pair<int, int>, int> ppi;
int p[2501], dist[2501];
vector<pi> v[2501];
priority_queue<ppi , vector<ppi>, greater<ppi> > pq;

int main()
{
    int n, m, a, b, c;
    scanf("%d %d", &n, &m);
    for(int i = 1;i <= n;i++) scanf("%d", &p[i]);
    for(int i = 0;i < m;i++)
    {
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back({b, c});
        v[b].push_back({a, c});
    }
    //dijkstra
    //(지금까지돈, 도시, 지금까지최소기름값)
    pq.push({{0, 1}, p[1]});
    memset(dist, -1, sizeof(dist));
    dist[1] = 0;
    while(!pq.empty())
    {
        int s = pq.top().first.first;
        int f = pq.top().first.second;
        int t = pq.top().second;
        pq.pop();
        if(dist[f] == -1) dist[f] = s;
        else dist[f] = min(dist[f], s);
        if(f == n)
        {
            printf("%d", dist[f]);
            return 0;
        }
        for(int i = 0;i < v[f].size();i++)
        {
            pq.push({{s + t * v[f][i].second, v[f][i].first}, min(t, p[v[f][i].first])});
        }
    }
}

Compilation message

gas.cpp: In function 'int main()':
gas.cpp:42:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i < v[f].size();i++)
                       ~~^~~~~~~~~~~~~
gas.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
gas.cpp:17:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i <= n;i++) scanf("%d", &p[i]);
                               ~~~~~^~~~~~~~~~~~~
gas.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Runtime error 605 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1284 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1272 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Runtime error 605 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 2 ms 424 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Runtime error 605 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -