Submission #45848

# Submission time Handle Problem Language Result Execution time Memory
45848 2018-04-16T09:21:23 Z antimirage Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 620 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2005;

int n, m, u[N][N], pos[N], pw[N], ans = 1e9 + 7;

vector <int> vec[N];

queue <pair <int, int> > q;

main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &pos[i], &pw[i]);
        vec[pos[i]].pb(pw[i]);
    }
    for (auto to : vec[ pos[0] ])
    {
        q.push( mk(pos[0], to) );
        u[ pos[0] ][to] = 1;
    }
    vec[ pos[0] ].clear();

    while (!q.empty() )
    {
        int v = q.front().fr, cur_pow = q.front().sc;
        q.pop();

        for (auto it : vec[v])
        {
            if (!u[v][it])
            {
                u[v][it] = u[v][cur_pow];
                q.push( mk(v, it) );
            }
        }
        vec[v].clear();

        if ( v - cur_pow >= 0 && !u[v - cur_pow][cur_pow] )
        {
            u[v - cur_pow][cur_pow] = u[v][cur_pow] + 1;
            q.push( mk(v - cur_pow, cur_pow) );
        }
        if ( v + cur_pow < n && !u[v + cur_pow][cur_pow] )
        {
            u[v + cur_pow][cur_pow] = u[v][cur_pow] + 1;
            q.push( mk(v + cur_pow, cur_pow) );
        }
    }
    for (int i = 0; i < m; i++)
    {
        if (u[ pos[1] ][i])
            ans = min(ans, u[ pos[1] ][i] - 1);
    }
    if (ans == 1e9 + 7) ans = -1;
    cout << ans << endl;
}
/**
5 3
0 2
1 1
4 1
**/

Compilation message

skyscraper.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &pos[i], &pw[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Incorrect 2 ms 592 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Incorrect 2 ms 620 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Incorrect 2 ms 620 KB Output isn't correct
4 Halted 0 ms 0 KB -