답안 #837174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837174 2023-08-25T07:01:06 Z unnick The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 212 KB
#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

joioi.cpp: In function 'int main()':
joioi.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge_t>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (i = 0; i < edges.size(); i++) {
      |                 ~~^~~~~~~~~~~~~~
joioi.cpp:48:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   48 |             if (ej.x <= clx && ej.y <= cly || ej.x >= chx && ej.y >= chy) {
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~~
joioi.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge_t>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for (i = 0; i < edges.size(); i++) {
      |                 ~~^~~~~~~~~~~~~~
joioi.cpp:65:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   65 |             if (ej.x <= clx && ej.y >= cly || ej.x >= chx && ej.y <= chy) {
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -