Submission #674469

#TimeUsernameProblemLanguageResultExecution timeMemory
674469AmirHJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1081 ms13132 KiB
#include<iostream> #include<algorithm> #include<math.h> #include<vector> #include<bitset> #include<queue> #include<queue> #include<deque> #include<set> #include<map> #include<unordered_map> #include<list> #include<utility> #include<stack> using namespace std; typedef long long ll; typedef long double ld; typedef pair <ll, ll> pll; typedef pair <int, int> pii; #define cl clear #define F first #define S second #define pb push_back #define Sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) const int MAX_N = 2e5 + 25; const ll INF = 1e18; const int inf = 1e9; const int mod = 1e9 + 7; void free() { #ifndef ONLINE_JUDGE freopen("inputi.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int n, m; int dist[MAX_N]; set<int> v[MAX_N]; pii ar[MAX_N]; void dij(int pos) { set<pii> s; s.insert({0, pos}); dist[pos] = 0; while(s.size()) { int x = s.begin()->first; int y = s.begin()->second; v[ar[y].first].erase(y); s.erase(s.begin()); int d = 0; for(int i = ar[y].first; i < n; i+= ar[y].second) { for(auto j : v[i]) { if(x + d < dist[j]) { s.erase({dist[j], j}); dist[j] = x + d; s.insert({dist[j], j}); } } d++; } d = 0; for(int i = ar[y].first; i >= 0; i-= ar[y].second) { for(auto j : v[i]) { if(x + d < dist[j]) { s.erase({dist[j], j}); dist[j] = x + d; s.insert({dist[j], j}); } } d++; } } } int main() { faster; //free(); cin >> n >> m; for(int i = 1; i <= m; i++) dist[i] = inf; for(int i = 1; i <= m; i++) { cin >> ar[i].first >> ar[i].second; v[ar[i].first].insert(i); } dij(1); if(dist[2] == inf) cout << -1; else cout << dist[2]; }

Compilation message (stderr)

skyscraper.cpp: In function 'void free()':
skyscraper.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("inputi.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...