Submission #905667

#TimeUsernameProblemLanguageResultExecution timeMemory
905667Muhammad_AneeqJakarta Skyscrapers (APIO15_skyscraper)C++17
Compilation error
0 ms0 KiB
/* بسم الله الرحمن الرحيم Author: (:Muhammad Aneeq:) */ #include <iostream> #include <queue> #include <vector> using namespace std; void solve() { int n,m; cin>>n>>m; pair<int,int>a[m]; set<int>lo[n]; for (auto& i:a) { cin>>i.first>>i.second; lo[i.first].insert(i.second); } int dp[n]={}; for (int i=0;i<n;i++) dp[i]=1e9+10; dp[a[0].first]=0; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq; pq.push({0,a[0].first}); bool vis[n]={}; while (pq.size()) { int loc=pq.top().second; pq.pop(); if (vis[loc]) continue; vis[loc]=1; for (auto j:lo[loc]) { int z=0; for (int k=loc-j;k>=0;k-=j) { z++; if (dp[k]>dp[loc]+z) { dp[k]=dp[loc]+z; pq.push({dp[k],k}); } } z=0; for (int k=loc+j;k<n;k+=j) { z++; if (dp[k]>dp[loc]+z) { dp[k]=dp[loc]+z; pq.push({dp[k],k}); } } } } cout<<(dp[a[1].first]!=1e9+10?dp[a[1].first]:-1); } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); solve(); }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:15:2: error: 'set' was not declared in this scope
   15 |  set<int>lo[n];
      |  ^~~
skyscraper.cpp:8:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    7 | #include <queue>
  +++ |+#include <set>
    8 | #include <vector>
skyscraper.cpp:15:6: error: expected primary-expression before 'int'
   15 |  set<int>lo[n];
      |      ^~~
skyscraper.cpp:19:3: error: 'lo' was not declared in this scope
   19 |   lo[i.first].insert(i.second);
      |   ^~
skyscraper.cpp:35:15: error: 'lo' was not declared in this scope; did you mean 'loc'?
   35 |   for (auto j:lo[loc])
      |               ^~
      |               loc