Submission #61741

# Submission time Handle Problem Language Result Execution time Memory
61741 2018-07-26T13:49:30 Z ansol4328 None (KOI16_gas) C++
18 / 100
1440 ms 66560 KB
#include<stdio.h>
#include<vector>
#include<queue>
#include<memory.h>

using namespace std;
typedef pair<long long,long long> P;

int n, gas[2502];
vector<P> lst[2502];
priority_queue<P, vector<P>, greater<P> > PQ;
long long dxy[2502][2502];

void make_dxy(int s)
{
    int v;
    bool check[2502];
    for(int i=1 ; i<=n ; i++) dxy[s][i]=1e18;
    dxy[s][s]=0;
    memset(check,false,sizeof(check));
    PQ.push(P(0,s));
    while(!PQ.empty())
    {
        do
        {
            v=PQ.top().second;
            PQ.pop();
        }while(!PQ.empty() && check[v]);
        check[v]=true;
        for(int i=0 ; i<lst[v].size() ; i++)
        {
            if(dxy[s][lst[v][i].first]>dxy[s][v]+lst[v][i].second*gas[s] && !check[lst[v][i].first])
            {
                dxy[s][lst[v][i].first]=dxy[s][v]+lst[v][i].second*gas[s];
                PQ.push(P(dxy[s][lst[v][i].first],lst[v][i].first));
            }
        }
    }
}

long long dijkstra()
{
    int v;
    long long dist[2502];
    bool check[2502];
    for(int i=1 ; i<=n ; i++) dist[i]=1e18;
    dist[1]=0;
    memset(check,false,sizeof(check));
    PQ.push(P(0,1));
    while(!PQ.empty())
    {
        do
        {
            v=PQ.top().second;
            PQ.pop();
        }while(!PQ.empty() && check[v]);
        if(v==n) break;
        check[v]=true;
        for(int i=0 ; i<lst[v].size() ; i++)
        {
            if(dist[lst[v][i].first]>dist[v]+lst[v][i].second && !check[lst[v][i].first])
            {
                dist[lst[v][i].first]=dist[v]+lst[v][i].second;
                PQ.push(P(dist[lst[v][i].first],lst[v][i].first));
            }
        }
    }
    return dist[n];
}

int main()
{
    int m, a, b, c;
    scanf("%d %d",&n,&m);
    for(int i=1 ; i<=n ; i++) scanf("%d",&gas[i]);
    for(int i=0 ; i<m ; i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        lst[a].push_back(P(b,c));
        lst[b].push_back(P(a,c));
    }
    for(int i=1 ; i<=n ; i++) make_dxy(i);
    for(int i=1 ; i<=n ; i++)
    {
        lst[i].clear();
        for(int j=1 ; j<=n ; j++)
        {
            if(i!=j) lst[i].push_back(P(j,dxy[i][j]));
        }
    }
    printf("%lld",dijkstra());
    return 0;
}

Compilation message

gas.cpp: In function 'void make_dxy(int)':
gas.cpp:30:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0 ; i<lst[v].size() ; i++)
                       ~^~~~~~~~~~~~~~
gas.cpp: In function 'long long int dijkstra()':
gas.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0 ; i<lst[v].size() ; i++)
                       ~^~~~~~~~~~~~~~
gas.cpp: In function 'int main()':
gas.cpp:74: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:75: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",&gas[i]);
                               ~~~~~^~~~~~~~~~~~~~
gas.cpp:78: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 496 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 648 KB Output is correct
5 Correct 3 ms 648 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 744 KB Output is correct
8 Correct 3 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 2 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1433 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1440 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 496 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 648 KB Output is correct
5 Correct 3 ms 648 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 744 KB Output is correct
8 Correct 3 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 2 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Runtime error 31 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 496 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 2 ms 648 KB Output is correct
5 Correct 3 ms 648 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 744 KB Output is correct
8 Correct 3 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 2 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Runtime error 1433 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
15 Halted 0 ms 0 KB -