#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
#define in cin
#define out cout
#define all(v) v.begin(), v.end()
#define X first
#define Y second
int CNT[1010];
int main()
{
int n, m; in >> n >> m;
vector< pair<int, int> > v;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
int x; in >> x;
v.push_back(make_pair(x, i));
}
}
sort(all(v));
int q = 0;
int K = 0;
int res = 101010101;
for(int p=0; p<n*m; p++)
{
if(CNT[ v[p].Y ] == 0) K++;
CNT[ v[p].Y ]++;
while(K == n)
{
if(v[p].X - v[q].X < res) res = v[p].X - v[q].X;
CNT[ v[q].Y ]--;
if(CNT[ v[q].Y ] == 0) K--;
q++;
}
}
int p = n*m-1;
while(K == n)
{
if(v[p].X - v[q].X < res) res = v[p].X - v[q].X;
CNT[ v[q].Y ]--;
if(CNT[ v[q].Y ] == 0) K--;
q++;
}
out << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
0 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
0 KB |
Output isn't correct |
3 |
Correct |
2 ms |
0 KB |
Output is correct |
4 |
Incorrect |
2 ms |
0 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
0 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
0 KB |
Output is correct |
2 |
Correct |
16 ms |
0 KB |
Output is correct |
3 |
Correct |
47 ms |
2 KB |
Output is correct |
4 |
Correct |
116 ms |
5 KB |
Output is correct |
5 |
Correct |
140 ms |
7 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
12 KB |
Output is correct |
2 |
Correct |
164 ms |
15 KB |
Output is correct |
3 |
Correct |
229 ms |
17 KB |
Output is correct |
4 |
Correct |
256 ms |
21 KB |
Output is correct |
5 |
Correct |
282 ms |
26 KB |
Output is correct |
6 |
Correct |
333 ms |
36 KB |
Output is correct |
7 |
Correct |
407 ms |
41 KB |
Output is correct |
8 |
Correct |
441 ms |
47 KB |
Output is correct |
9 |
Correct |
487 ms |
55 KB |
Output is correct |
10 |
Correct |
545 ms |
64 KB |
Output is correct |