답안 #244800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244800 2020-07-05T04:47:40 Z knightron0 Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
7 ms 3508 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int INF = 2e10 + 10;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

vector<pair<int, int> > adj[MAXN];
int dist[MAXN];
int vis[MAXN] = {false};

void dstra(){
    for(int i = 0;i<MAXN;i++){
        dist[i] = INF;
    }
    priority_queue<pair<int, int> > q;
    q.push(mp(0, 1));
    dist[1] = 0;

    while(!q.empty()){
        int a = q.top().sc;
        q.pop();
        if(vis[a]){
            continue;
        }
        vis[a] = true;
        for(auto v: adj[a]){
            int b = v.fr;
            int w = v.sc;
            if(dist[a]+w < dist[b]){
                dist[b] = dist[a]+w;
                q.push(mp(-dist[b], b));
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m;
    cin>>n>>m;
    vector<pair<int, int> > vec;
    for(int i= 0;i<m;i++){
    	int t1, t2;
    	cin>>t1>>t2;
    	vec.pb(mp(t1, t2));
    }
    for(int i = 1;i<=m;i++){
    	for(int j= i+1;j<=m;j++){
    		if(abs(vec[i-1].fr-vec[j-1].fr) % vec[i-1].sc == 0){
                adj[i].pb(mp(j, abs(vec[i-1].fr-vec[j-1].fr)/vec[i-1].sc));
    		} 
    		if(abs(vec[i-1].fr-vec[j-1].fr) % vec[j-1].sc == 0){
                adj[j].pb(mp(i, abs(vec[i-1].fr-vec[j-1].fr)/vec[j-1].sc));	
    		} 
    	}
    }
    dstra();
    cout<<dist[2]<<endl;
    
    return 0;
}



# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Incorrect 6 ms 3456 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Incorrect 6 ms 3456 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3508 KB Output is correct
2 Correct 7 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Incorrect 6 ms 3456 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Incorrect 6 ms 3456 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Incorrect 6 ms 3488 KB Output isn't correct
5 Halted 0 ms 0 KB -