답안 #42130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42130 2018-02-22T18:43:41 Z XmtosX Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
3 ms 1260 KB
#include <bits/stdc++.h>
using namespace std;
int n,p[30004],b[30004],m;
priority_queue <pair<int,int> ,vector <pair<int,int> >,greater <pair<int,int> > > pq;
bool vis[30004];
vector <int> v[30004];
int cur[30004];
void dij()
{
    for (int i=0;i<n;i++)
        cur[i]=INT_MAX;
    cur[b[0]]=0;
    pq.push({0,b[0]});
    while (!pq.empty())
    {
        int x= (pq.top()).second;
        int y= (pq.top()).first;
        pq.pop();
        if (vis[x])
            continue;
        vis[x]=true;
        for (int i=0;i<v[x].size();i++)
        {
            for (int j=0;j*v[x][i]+x<n;j++)
            {
                int a= (j*v[x][i]+x);
                if (cur[a]>y+j)
                {
                    cur[a]=y+j;
                    pq.push({cur[a],a});
                }
            }
            for (int j=1;x-j*v[x][i]>=0;j++)
            {
                int a= (x-j*v[x][i]);
                if (cur[a]>y+j)
                {
                    cur[a]=y+j;
                    pq.push({cur[a],a});
                }
            }
        }
    }
}
int main()
{
    cin >>n>>m;
    for (int i=0;i<m;i++)
    {
        cin >>b[i]>>p[i];
        v[b[i]].push_back(p[i]);
    }
    dij();
    if (!vis[b[1]])
        cout <<-1;
    else
        cout <<cur[1];
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void dij()':
skyscraper.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<v[x].size();i++)
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Incorrect 2 ms 1116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Incorrect 2 ms 1260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
3 Incorrect 2 ms 1260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Incorrect 2 ms 1260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Incorrect 2 ms 1260 KB Output isn't correct
4 Halted 0 ms 0 KB -