제출 #398368

#제출 시각아이디문제언어결과실행 시간메모리
398368tengiz05Jakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1084 ms90048 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 = 30005, M = 30005;
int n, m, k;
bitset<M> used[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;
	q.push({0,start,0});
	used[start][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();
			used[pos][x] = 1;
			q.push({dist,pos,x});
			who_is_here[pos].pop_back();
		}
		if(pos - len[i] >= 0 && !used[pos-len[i]][i]){
			used[pos-len[i]][i] = 1;
			q.push({dist+1,pos-len[i],i});
		}
		if(pos + len[i] < n && !used[pos+len[i]][i]){
			used[pos+len[i]][i] = 1;
			q.push({dist+1,pos+len[i],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;
}




컴파일 시 표준 에러 (stderr) 메시지

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