답안 #966826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966826 2024-04-20T12:49:13 Z elesis Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
1 ms 500 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});
            }
        }
    }
    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 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Incorrect 1 ms 500 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -