제출 #602839

#제출 시각아이디문제언어결과실행 시간메모리
602839promaJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1095 ms16236 KiB
#include <bits/stdc++.h> //#define int long long #define see(x) cout<<#x<<"="<<x<<endl; #define endl "\n" using namespace std; const int N = 30005; const int INF = 1e9; int n, m, b[N], p[N], d[2005], used[2005]; int g[2005][2005]; vector <int> mp[2005]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); /* freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); */ cin >> n >> m; for (int i = 0; i < m; i ++) { cin >> b[i] >> p[i]; mp[b[i]].push_back(i); } for (int i = 0; i < n; i ++) { for (int j = i + 1; j < n; j ++) { g[i][j] = g[j][i] = INF; } } for (int i = 0; i < m; i ++) { for (int j = 0; j < n; j ++) { for (auto k: mp[j]) { if (k == i) continue; if (abs(b[k] - b[i]) % p[i] == 0) g[b[i]][b[k]] = min(g[b[i]][b[k]], abs(b[k] - b[i]) / p[i]); } } /* for (int j = b[i] - p[i]; j >= 0; j -= p[i]) { for (auto k: mp[j]) { if (k == i) continue; if (abs(b[k] - b[i]) % p[i] == 0) g[i].push_back({k, abs(b[k] - b[i]) / p[i]}); } } */ } for (int i = 0; i < n; i ++) { d[i] = INF; } d[b[0]] = 0; for (int i = 0; i < n; i ++) { int v = -1, mn; for (int j = 0; j < n; j ++) { if ((v == -1 or mn > d[j]) and !used[j]) { mn = d[j]; v = j; } } used[v] = 1; for (int j = 0; j < n; j ++) { if (d[j] > d[v] + g[v][j]) { d[j] = d[v] + g[v][j]; } } } if (d[b[1]] == INF) d[b[1]] = -1; cout << d[b[1]] << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...