Submission #398419

#TimeUsernameProblemLanguageResultExecution timeMemory
398419tengiz05Jakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1091 ms225256 KiB
#include <bits/stdc++.h> using namespace std; inline long long msb(long long val){return 63-__builtin_clzll(val);} inline int msb(int val){return 31-__builtin_clz(val);} //~ #define int long long #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define PI acos(-1) #define ld long double template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;} template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;} const int mod = 1e9+7, N = 30000, M = 30000; int n, m, k; bitset<M> used[N]; bitset<N> vis[N]; int len[N]; vector<int> who_is_here[N]; void solve(int test_case){ int i, j; cin >> n >> m; int start; for(i=0;i<m;i++){ int pos; cin >> pos >> len[i]; if(i){ who_is_here[pos].pb(i); }else { start = pos; } } priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> q; //~ deque<tuple<int,int,int>> q; q.emplace(0,start,0); used[start][0] = 1; vis[start][len[0]] = 1; while(!q.empty()){ auto [dist, pos, i] = q.top(); q.pop(); if(i == 1){ cout << dist << '\n'; return; } while(who_is_here[pos].size()){ auto x = who_is_here[pos].back(); who_is_here[pos].pop_back(); if(x == 1){ cout << dist << '\n'; return; } if(vis[pos][len[x]])continue; used[pos][x] = 1; vis[pos][len[x]] = 1; q.emplace(dist,pos,x); } for(int p=pos-len[i],d=dist+1;p>=0;p-=len[i],d++){ if(!used[p][i] && !vis[p][len[i]]){ used[p][i] = 1; vis[p][len[i]] = 1; q.emplace(d,p,i); } } for(int p=pos+len[i],d=dist+1;p<n;p+=len[i],d++){ if(!used[p][i] && !vis[p][len[i]]){ used[p][i] = 1; vis[p][len[i]] = 1; q.emplace(d,p,i); } } } cout << -1 << '\n'; return; } signed main(){ FASTIO; //~ #define MULTITEST 1 #if MULTITEST int _T; cin >> _T; for(int T_CASE = 1; T_CASE <= _T; T_CASE++) solve(T_CASE); #else solve(1); #endif return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve(int)':
skyscraper.cpp:23:9: warning: unused variable 'j' [-Wunused-variable]
   23 |  int i, j;
      |         ^
skyscraper.cpp:25:6: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |  int start;
      |      ^~~~~
#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...