이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<algorithm>
using namespace std;
#define N_ 1000
int N, M;
struct S1{
int x, dat;
bool operator< (const S1 &t) const { return dat < t.dat; }
}D[N_*N_+1];
int Chk [N_+1], cnt;
int res = 2147483647;
int main(){
int i, j;
scanf("%d%d",&N,&M);
for(i=1; i<=N; i++){
for(j=1; j<=M; j++){
int v = (i-1) * M + j;
scanf("%d",&D[v].dat);
D[v].x = i;
}
}
sort(D+1, D+N*M+1);
Chk[D[1].x] ++; cnt ++;
for(i=j=1; i<=N*M && j<=N*M; ){
if(cnt == N){
if(D[j].dat - D[i].dat < res) res = D[j].dat - D[i].dat;
if(Chk[D[i].x] == 1) cnt --;
Chk[D[i].x] --; i++;
continue;
}
if(Chk[D[i].x] > 1 && i+1 <= j){ Chk[D[i].x] --; i++; }
else{
j++; if(!Chk[D[j].x]) cnt++;
Chk[D[j].x]++;
}
}
printf("%d\n",res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |