이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Code by @marlov
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
#define maxV 30000
int N,M;
pair<int,int> doge[maxV];
//map< int,map<int,bool> > visited;
bool visited[maxV][maxV];
queue<int> cnts[maxV];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>M;
int b,p;
for(int i=0;i<M;i++){
cin>>doge[i].first>>doge[i].second;
cnts[doge[i].first].push(i);
}
//bfs
queue< pair< int,pair<int,int> > > q;
q.push(make_pair(0,make_pair(0,doge[0].first)));
visited[0][doge[0].first]=true;
while(!q.empty()){
int cd=q.front().first;
int ci=q.front().second.first;
int cl=q.front().second.second;
q.pop();
//solution
if(ci==1){
cout<<cd<<'\n';
return 0;
}
while(!cnts[cl].empty()){
q.push(make_pair(cd,make_pair(cnts[cl].front(),cl)));
cnts[cl].pop();
}
if(cl-doge[ci].second>=0&&visited[ci][cl-doge[ci].second]==false){
q.push(make_pair(cd+1,make_pair(ci,cl-doge[ci].second)));
visited[ci][cl-doge[ci].second]=true;
}
if(cl+doge[ci].second<N&&visited[ci][cl+doge[ci].second]==false){
q.push(make_pair(cd+1,make_pair(ci,cl+doge[ci].second)));
visited[ci][cl+doge[ci].second]=true;
}
}
cout<<-1<<'\n';
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1,n=0?)
* do smth instead of nothing and stay organized
*/
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:9: warning: unused variable 'b' [-Wunused-variable]
int b,p;
^
skyscraper.cpp:36:11: warning: unused variable 'p' [-Wunused-variable]
int b,p;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |