Submission #956786

# Submission time Handle Problem Language Result Execution time Memory
956786 2024-04-02T13:05:57 Z Nelt Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1 ms 456 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, 0));
    while (!q.empty())
    {
        auto [w, i] = q.top();
        q.pop();
        if (dist[i] < w)
            continue;
        if (i == 1)
        {
            cout << dist[1] << endl;
            return;
        }
        for (ll j : eq[i])
        {
            for (ll k = i - j, cur = 0; k >= 0; k -= j)
            {
                cur++;
                if (dist[k] > dist[i] + cur)
                    q.push(make_pair(dist[k] = dist[i] + cur, k));
            }
            for (ll k = i + j, cur = 0; k < n; k += j)
            {
                cur++;
                if (dist[k] > dist[i] + cur)
                    q.push(make_pair(dist[k] = dist[i] + cur, k));
            }
        }
    }
    if (dist[1] == 1e18)
        dist[1] = -1;
    cout << dist[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 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -