# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1028722 | DeltaStruct | 산악 구조대 (JOI13_mountain) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
/*
vector<vector<int>> high; vector<pair<int,int>> ans;
int Measure(int RM,int CM){ return high[RM-1][CM-1]; }
void Pinpoint(int RP,int CP){ ans.emplace_back(RP,CP); }
void Rescue(int R,int C,int MR,int MC,int X);
int main(){
int q; cin >> q; while(q--){
int R,C,MR,MC,X; cin >> R >> C >> MR >> MC >> X;
high.resize(R);
for (auto& a:high){
a.resize(C); for (int& b:a) cin >> b;
}
Rescue(R,C,MR,MC,X);
}
for (auto [a,b]:ans) cout << a << ' ' << b << endl;
}
//*/
void Rescue(int R,int C,int MR,int MC,int X){
--MR;
int x = 0,y = MC-1;
while(x!=MR+1&&y!=-1){
int r = Measure(x+1,y+1);
if (r==X){
Pinpoint(x+1,y+1);
return;
}
if (r<X) ++x;
else --y;
}
x = 0,y = MC-1;
while(x!=MR+1&&y!=C){
int r = Measure(x+1,y+1);
if (r==X){
Pinpoint(x+1,y+1);
return;
}
if (r<X) ++x;
else ++y;
}
x = R-1,y = MC-1;
while(x!=MR+1&&y!=-1){
int r = Measure(x+1,y+1);
if (r==X){
Pinpoint(x+1,y+1);
return;
}
if (r<X) --x;
else --y;
}
x = R-1,y = MC-1;
while(x!=MR-1&&y!=C){
int r = Measure(x+1,y+1);
if (r==X){
Pinpoint(x+1,y+1);
return;
}
if (r<X) --x;
else ++y;
}
}