Submission #471960

#TimeUsernameProblemLanguageResultExecution timeMemory
471960hidden1Jakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
2 ms1740 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #define endl "\n" typedef long long ll; template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;} template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;} template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1e9 + 7; #define out(x) "{" << (#x) << ": " << x << "} " const int MAX_N = 3e4 + 10; vector<pair<int, int> > g[MAX_N]; vector<int> bucket[MAX_N]; int currentSorter = 1; int n, m, q; bool cmp(const int a, const int b) { if(a % currentSorter == b % currentSorter) { return a < b; } return (a % currentSorter) < (b % currentSorter); } void genGraph() { for(int d = 0; d < MAX_N; d ++) { if(bucket[d].size() == 0) {continue;} currentSorter = d; sort(bucket[d].begin(), bucket[d].end(), cmp); for(int i = 0; i < bucket[d].size(); i ++) { int j = i; while(j + 1 < bucket[d].size() && bucket[d][j + 1] % d == bucket[d][i] % d) { j ++; } int lft = i - 1; int rght = i; for(int k = bucket[d][i] % d; k < n; k += d) { if(lft != i - 1) { g[bucket[d][lft]].push_back({k, abs(bucket[d][lft] - k) / d}); } while(rght != j + 1 && k == bucket[d][rght]) { lft = rght; rght ++; } if(rght != j + 1) { g[bucket[d][rght]].push_back({k, abs(bucket[d][rght] - k) / d}); } } i = j; } } } int dist[MAX_N]; int dijkstra() { for(int i = 0; i < n; i ++) { dist[i] = mod; } priority_queue<pair<int, int> > pq; pq.push({0, 0}); dist[0] = 0; while(!pq.empty()) { auto curr = pq.top(); pq.pop(); curr.first *= -1; for(auto it : g[curr.second]) { if(dist[it.first] > curr.first + it.second) { dist[it.first] = curr.first + it.second; pq.push({-dist[it.first], it.first}); } } } if(dist[1] == mod) { return -1; } else { return dist[1]; } } signed main() { //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for(int i = 0; i < m; i ++) { int a, b; cin >> a >> b; bucket[b].push_back(a); } genGraph(); cout << dijkstra() << endl; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void genGraph()':
skyscraper.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int i = 0; i < bucket[d].size(); i ++) {
      |                        ~~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             while(j + 1 < bucket[d].size() && bucket[d][j + 1] % d == bucket[d][i] % d) {
      |                   ~~~~~~^~~~~~~~~~~~~~~~~~
#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...