Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <tuple>
- using namespace std;
- int main()
- {
- ifstream fin("schior.in");
- ofstream fout("schior.out");
- int maxx,maxy,startx,starty;
- fin>>maxy;fin>>maxx;
- fin>>starty;fin>>startx;
- int harta[maxx][maxy];
- bool checked[maxx][maxy];
- for(int y=0;y<maxy;y++)
- {
- for(int x=0;x<maxx;x++)
- {
- fin>>harta[x][y];
- checked[x][y]=false;
- }
- }
- vector<tuple<int,int,int>> last,curr;
- last.push_back(make_tuple(harta[startx-1][starty-1],startx-1,starty-1));
- while(!last.empty())
- {
- //push_heap(last.begin(),last.end());
- curr.clear();
- for(auto i : last)
- {
- int alti=get<0>(i), x=get<1>(i), y=get<2>(i);
- checked[x][y]=true;
- if(x>0){
- if(y>0)
- {
- if(!checked[x-1][y-1]&&harta[x-1][y-1]<=alti){
- curr.push_back(make_tuple(harta[x-1][y-1],x-1,y-1));
- }
- }
- if(!checked[x-1][y]&&harta[x-1][y]<=alti){
- curr.push_back(make_tuple(harta[x-1][y],x-1,y));
- }
- if(y<maxy-1)
- {
- if(!checked[x-1][y+1]&&harta[x-1][y+1]<=alti){
- curr.push_back(make_tuple(harta[x-1][y+1],x-1,y+1));
- }
- }
- }
- if(x<maxx-1){
- if(y>0)
- {
- if(!checked[x+1][y-1]&&harta[x+1][y-1]<=alti){
- curr.push_back(make_tuple(harta[x+1][y-1],x+1,y-1));
- }
- }
- if(!checked[x+1][y]&&harta[x+1][y]<=alti){
- curr.push_back(make_tuple(harta[x+1][y],x+1,y));
- }
- if(y<maxy-1)
- {
- if(!checked[x+1][y+1]&&harta[x+1][y+1]<=alti){
- curr.push_back(make_tuple(harta[x+1][y+1],x+1,y+1));
- }
- }
- }
- if(y>0){
- if(!checked[x][y-1]&&harta[x][y-1]<=alti){
- curr.push_back(make_tuple(harta[x][y-1],x,y-1));
- }
- }
- if(y<maxy-1){
- if(!checked[x][y+1]&&harta[x][y+1]<=alti){
- curr.push_back(make_tuple(harta[x][y+1],x,y+1));
- }
- }
- }
- last=curr;
- }
- //cout<<get<0>(last[0])<<"X: "<<get<1>(last[0])<<" Y: "<<get<2>(last[0]);
- fout<<get<0>(last[0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement