Submission #31138

# Submission time Handle Problem Language Result Execution time Memory
31138 2017-08-11T03:18:26 Z nibnalin Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
0 ms 2048 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

const int inf = int(1e9)+5, maxn = int(2e3)+5;

int B[maxn], P[maxn], D[maxn];

int dist(int x, int y)
{
    int ret = abs(B[x]-B[y]);
    if(ret%P[x] == 0) return ret/P[x];
    else return inf;
}

int main(void)
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0;i < m;i++) scanf("%d%d", &B[i], &P[i]), D[i] = inf;

    set<pair<int, int>> Q;
    D[0] = 0;
    Q.insert({0, 0});

    while(!Q.empty())
    {
        pair<int, int> top = *Q.begin();
        Q.erase(Q.begin());
        //cout << top.second << "\n";

        for(int i = 0;i < m;i++)
        {
            if(i == top.second) continue;

            int c = dist(top.second, i);
            if(top.first+c < D[i])
            {
                if(D[i] != inf) Q.erase({D[i], i});
                D[i] = top.first+c;
                Q.insert({D[i], i});
            }
        }
    }

    printf("%d\n", D[1]);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
skyscraper.cpp:23:69: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0;i < m;i++) scanf("%d%d", &B[i], &P[i]), D[i] = inf;
                                                                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Incorrect 0 ms 2048 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Incorrect 0 ms 2048 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Incorrect 0 ms 2048 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Incorrect 0 ms 2048 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Incorrect 0 ms 2048 KB Output isn't correct
5 Halted 0 ms 0 KB -