답안 #966827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966827 2024-04-20T12:50:46 Z elesis Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
123 ms 262144 KB
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod=1e9+7;
const int inf=1e18+7;
const int ninf=(-1)*inf;
const int N=2e3+7;
vector <pii> adj[N];
void solve()
{
    int n,m;
    cin>>n>>m;
    vector <int> b(m),p(m);
    for(int i=0;i<m;i++)
    {
        cin>>b[i]>>p[i];
    }
    vector <vector <int>> dist(m,vector <int>(m,inf));
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i==j)
            {
                dist[i][i] = 0;
                continue;
            }
            if(abs(b[i]-b[j])%p[i]==0)
            {
                dist[i][j] = min(dist[i][j],abs(b[i]-b[j])/p[i]);
                adj[i].push_back({j,dist[i][j]});
            }
        }
    }
    vector <int> d(m,inf);
    d[0] = 0;
    priority_queue <pii,vector <pii> , greater <pii>> pq;
    pq.push({0,0});
    while(!pq.empty())
    {
        pii cur = pq.top();
        pq.pop();
        int u = cur.ss;
        int du = cur.ff;
        for(auto it:adj[u])
        {
            if(du + it.ss < d[it.ff])
            {
                d[it.ff] = du + it.ss;
                pq.push({d[it.ff],it.ff});
            }
        }
    }
    if(d[1] == inf)
    {
        cout << -1 << "\n";
        return;
    }
    cout << d[1] << "\n";
}
signed main(){
    fast
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 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 2 ms 1884 KB Output is correct
11 Correct 39 ms 36176 KB Output is correct
12 Correct 88 ms 95772 KB Output is correct
13 Correct 86 ms 96036 KB Output is correct
14 Correct 37 ms 34640 KB Output is correct
15 Correct 37 ms 34732 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 344 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 372 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 41 ms 36088 KB Output is correct
12 Correct 86 ms 95572 KB Output is correct
13 Correct 89 ms 96160 KB Output is correct
14 Correct 40 ms 34644 KB Output is correct
15 Correct 38 ms 34852 KB Output is correct
16 Correct 6 ms 6492 KB Output is correct
17 Correct 28 ms 26644 KB Output is correct
18 Correct 8 ms 8536 KB Output is correct
19 Correct 3 ms 2908 KB Output is correct
20 Correct 85 ms 95920 KB Output is correct
21 Correct 11 ms 11356 KB Output is correct
22 Correct 4 ms 4444 KB Output is correct
23 Correct 7 ms 7772 KB Output is correct
24 Correct 29 ms 28792 KB Output is correct
25 Correct 31 ms 32092 KB Output is correct
26 Correct 81 ms 90120 KB Output is correct
27 Correct 82 ms 91968 KB Output is correct
28 Correct 31 ms 32336 KB Output is correct
29 Correct 5 ms 5372 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 38 ms 34848 KB Output is correct
34 Correct 38 ms 34904 KB Output is correct
# 결과 실행 시간 메모리 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 372 KB Output is correct
5 Correct 1 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 508 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 1880 KB Output is correct
11 Correct 39 ms 36180 KB Output is correct
12 Correct 85 ms 95572 KB Output is correct
13 Correct 85 ms 96084 KB Output is correct
14 Correct 38 ms 34640 KB Output is correct
15 Correct 37 ms 34788 KB Output is correct
16 Correct 6 ms 6492 KB Output is correct
17 Correct 32 ms 26448 KB Output is correct
18 Correct 8 ms 8288 KB Output is correct
19 Correct 3 ms 2908 KB Output is correct
20 Correct 85 ms 96084 KB Output is correct
21 Correct 12 ms 11356 KB Output is correct
22 Correct 5 ms 4440 KB Output is correct
23 Correct 7 ms 7772 KB Output is correct
24 Correct 28 ms 28764 KB Output is correct
25 Correct 30 ms 32216 KB Output is correct
26 Correct 80 ms 90096 KB Output is correct
27 Correct 84 ms 91888 KB Output is correct
28 Correct 33 ms 32340 KB Output is correct
29 Correct 5 ms 5464 KB Output is correct
30 Correct 1 ms 608 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 38 ms 34644 KB Output is correct
34 Correct 37 ms 34664 KB Output is correct
35 Runtime error 123 ms 262144 KB Execution killed with signal 9
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 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 344 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 38 ms 35952 KB Output is correct
12 Correct 85 ms 95768 KB Output is correct
13 Correct 85 ms 96084 KB Output is correct
14 Correct 38 ms 34644 KB Output is correct
15 Correct 40 ms 34644 KB Output is correct
16 Correct 6 ms 6492 KB Output is correct
17 Correct 27 ms 26460 KB Output is correct
18 Correct 8 ms 8192 KB Output is correct
19 Correct 3 ms 2904 KB Output is correct
20 Correct 85 ms 96084 KB Output is correct
21 Correct 11 ms 11352 KB Output is correct
22 Correct 4 ms 4444 KB Output is correct
23 Correct 8 ms 7716 KB Output is correct
24 Correct 29 ms 28764 KB Output is correct
25 Correct 31 ms 32336 KB Output is correct
26 Correct 79 ms 89928 KB Output is correct
27 Correct 84 ms 91728 KB Output is correct
28 Correct 31 ms 32340 KB Output is correct
29 Correct 5 ms 5468 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 37 ms 34644 KB Output is correct
34 Correct 38 ms 34908 KB Output is correct
35 Runtime error 93 ms 262144 KB Execution killed with signal 9
36 Halted 0 ms 0 KB -