Submission #956797

# Submission time Handle Problem Language Result Execution time Memory
956797 2024-04-02T13:20:32 Z Nelt Jakarta Skyscrapers (APIO15_skyscraper) C++17
22 / 100
3 ms 612 KB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
 
void solve()
{
    ll n, m;
    cin >> n >> m;
    ll b[m], p[m];
    vector<ll> eq[n];
    for (ll i = 0; i < m; i++)
        cin >> b[i] >> p[i], eq[b[i]].push_back(p[i]);
    for (ll i = 0; i < n; i++)
        sort(eq[i].begin(), eq[i].end(), greater());
    ll dist[n];
    for (ll i = 0; i < n; i++)
        dist[i] = 1e18;
    dist[0] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
    q.push(make_pair(0, b[0]));
    while (!q.empty())
    {
        auto [w, i] = q.top();
        q.pop();
        if (dist[i] < w)
            continue;
        for (ll j : eq[i])
        {
            for (ll k = i - j, cur = 0; k >= 0; k -= j)
            {
                cur++;
                if (dist[k] > w + cur)
                    q.push(make_pair(dist[k] = w + cur, k));
            }
            for (ll k = i + j, cur = 0; k < n; k += j)
            {
                cur++;
                if (dist[k] > w + cur)
                    q.push(make_pair(dist[k] = w + cur, k));
            }
        }
    }
    if (dist[b[1]] == 1e18)
        dist[b[1]] = -1;
    cout << dist[b[1]] << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // precomp();
    // cin >> t;
    for (ll i = 1; i <= t; i++)
        solve();
    cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 536 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 3 ms 612 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Incorrect 1 ms 604 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Incorrect 1 ms 604 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 356 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 608 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 352 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 608 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 3 ms 608 KB Output is correct
27 Correct 3 ms 608 KB Output is correct
28 Incorrect 1 ms 604 KB Output isn't correct
29 Halted 0 ms 0 KB -