Submission #971302

#TimeUsernameProblemLanguageResultExecution timeMemory
971302LOLOLOJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms388 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 1e5 + 10; int d[N], p[N], used[N]; ll solve() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> p[i] >> d[i]; } priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> pq; for (int i = 0; i < m; i++) { if (abs(p[i] - p[1]) % d[i] == 0) { pq.push({abs(p[i] - p[1]) / d[i], i}); } } used[1] = 1; ll all = 0; while (sz(pq)) { auto t = pq.top(); pq.pop(); if (used[t.s]) continue; all += t.f; used[t.s] = 1; for (int i = 0; i < m; i++) { if (abs(p[i] - p[t.s]) % d[i] == 0 && used[i] == 0) { pq.push({abs(p[i] - p[t.s]) / d[i], i}); } } } return all; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << solve() << '\n'; 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...