| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 837174 | unnick | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 1 ms | 212 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct {
int d;
short x;
short y;
} edge_t;
int main() {
int w,h;
cin >> h >> w;
vector<edge_t> edges;
{
vector<int> alts(w*h);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
cin >> alts[x+y*w];
}
}
for (int y = 0; y < h; y++) {
for (int x = 0; x < w-1; x++) {
edges.push_back({.d = abs(alts[x+y*w]-alts[x+1+y*w]), .x = (short) (x*2+1), .y = (short) (y*2)});
}
}
for (int y = 0; y < h-1; y++) {
for (int x = 0; x < w; x++) {
edges.push_back({.d = abs(alts[x+y*w]-alts[x+(y+1)*w]), .x = (short) (x*2), .y = (short) (y*2+1)});
}
}
sort(edges.begin(), edges.end(), [](edge_t a, edge_t b){
return a.d > b.d;
});
}
int i;
for (i = 0; i < edges.size(); i++) {
edge_t ei = edges[i];
bool valid = true;
int clx = ((int) ei.x) & ~1;
int cly = ((int) ei.y) & ~1;
int chx = (((int) ei.x)+1) & ~1;
int chy = (((int) ei.y)+1) & ~1;
for (int j = 0; j < i; j++) {
edge_t ej = edges[j];
if (ej.x <= clx && ej.y <= cly || ej.x >= chx && ej.y >= chy) {
valid = false;
break;
}
}
if (!valid) break;
}
int i1 = i;
for (i = 0; i < edges.size(); i++) {
edge_t ei = edges[i];
bool valid = true;
int clx = ((int) ei.x) & ~1;
int cly = (((int) ei.y)+1) & ~1;
int chx = (((int) ei.x)+1) & ~1;
int chy = ((int) ei.y) & ~1;
for (int j = 0; j < i; j++) {
edge_t ej = edges[j];
if (ej.x <= clx && ej.y >= cly || ej.x >= chx && ej.y <= chy) {
valid = false;
break;
}
}
if (!valid) break;
}
int i2 = i;
i = max(i1, i2);
// for (auto edge : edges) {
// cout << edge.x << "," << edge.y << "|" << edge.d << " ";
// }
// cout << "\n";
// cout << i1 << " " << i2 << "\n";
cout << edges[i].d << "\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
