记录编号 |
240944 |
评测结果 |
AAAAAAAAAA |
题目名称 |
定向越野 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.045 s |
提交时间 |
2016-03-24 09:31:27 |
内存使用 |
0.51 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int inf = 1e7;
const int maxn = 2e2;
int ma[maxn][maxn];
int line[maxn];
bool vis[maxn][maxn];
int x[5], y[5];
int n;
int top;
int tmax, tmin;
int ex[maxn];
inline int get_num() {
int ans = 0;
char tmp = getchar();
while(tmp < '0' || tmp > '9') tmp = getchar();
while(tmp <= '9' && tmp >= '0') {
ans = ans*10 + tmp-'0';
tmp = getchar();
}
return ans;
}
inline void make_table() {
x[1] = 1; y[1] = 0;
x[2] = 0; y[2] = 1;
x[3] = -1; y[3] = 0;
x[4] = 0; y[4] = -1;
}
inline bool find_path(int nowx, int nowy) {
if(nowx == n && nowy == n) return true;
vis[nowx][nowy] = true;
int tx, ty;
for(int i = 1; i <= 4; i++) {
tx = nowx+x[i]; ty = nowy+y[i];
if(tx > n || ty > n || tx < 1 || ty < 1) continue;
if(vis[tx][ty]) continue;
if(ma[tx][ty] < tmin || ma[tx][ty] > tmax) continue;
if(find_path(tx, ty)) return true;
}
return false;
}
inline void read() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
scanf("%d", &ma[i][j]);
top = max(top, ma[i][j]);
ex[ma[i][j]] = true;
}
}
}
inline bool judge(int d) {
int i = 0, j = d;
while(j <= top) {
if(ex[i] && ex[j] &&!(ma[1][1] < i || ma[1][1] > j)) {
tmax = j, tmin = i;
memset(vis, 0, sizeof(vis));
if(find_path(1, 1)) return true;
}
j++, i++;
}
return false;
}
inline void solve() {
int tmax, tmin;
int l = 0, r = top+1, mid;
while(l < r) {
mid = ((l+r)>>1);
if(judge(mid)) r = mid;
else l = mid+1;
}
printf("%d", l);
}
int main() {
freopen("adven.in", "r", stdin);
freopen("adven.out", "w", stdout);
read();
make_table();
solve();
return 0;
}