답안 #50264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50264 2018-06-08T18:02:57 Z gs13105 The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1090 ms 265212 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int mn, mx, h, w;
int arr[2010][2010];

bool solve(int lt, int gt)
{
    int p = w, i, j;
    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w && j < p; j++)
            if(arr[i][j] > lt)
                break;
        p = j;
        for(j = p; j < w; j++)
            if(arr[i][j] < gt)
                return 0;
    }
    return 1;
}

void horflip()
{
    for(int i = 0; i < h; i++)
        reverse(arr[i], arr[i] + w);
}

void valflip()
{
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            arr[i][j] = mx - arr[i][j];
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int i, j;
    scanf("%d%d", &h, &w);
    for(i = 0; i < h; i++)
        for(j = 0; j < w; j++)
            scanf("%d", &arr[i][j]);

    mn = mx = arr[0][0];
    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j++)
        {
            mn = min(mn, arr[i][j]);
            mx = max(mx, arr[i][j]);
        }
    }

    mx -= mn;
    for(i = 0; i < h; i++)
        for(j = 0; j < w; j++)
            arr[i][j] -= mn;

    int s, g;
    s = 0;
    g = mx;
    while(s < g)
    {
        int x = (s + g) / 2;

        if(solve(x, mx - x))
        {
            g = x;
            continue;
        }

        valflip();

        if(solve(x, mx - x))
        {
            g = x;
            continue;
        }

        horflip();

        if(solve(x, mx - x))
        {
            g = x;
            continue;
        }

        valflip();

        if(solve(x, mx - x))
        {
            g = x;
            continue;
        }

        s = x + 1;
    }
    printf("%d\n", s);
    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &h, &w);
     ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &arr[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 3 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 3 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 7 ms 1596 KB Output is correct
17 Correct 11 ms 1944 KB Output is correct
18 Correct 14 ms 2216 KB Output is correct
19 Correct 11 ms 2540 KB Output is correct
20 Correct 11 ms 2660 KB Output is correct
21 Correct 16 ms 3156 KB Output is correct
22 Correct 16 ms 3600 KB Output is correct
23 Correct 18 ms 3944 KB Output is correct
24 Correct 14 ms 4204 KB Output is correct
25 Correct 14 ms 4676 KB Output is correct
26 Correct 14 ms 5064 KB Output is correct
27 Correct 22 ms 5452 KB Output is correct
28 Correct 14 ms 5900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 3 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 7 ms 1596 KB Output is correct
17 Correct 11 ms 1944 KB Output is correct
18 Correct 14 ms 2216 KB Output is correct
19 Correct 11 ms 2540 KB Output is correct
20 Correct 11 ms 2660 KB Output is correct
21 Correct 16 ms 3156 KB Output is correct
22 Correct 16 ms 3600 KB Output is correct
23 Correct 18 ms 3944 KB Output is correct
24 Correct 14 ms 4204 KB Output is correct
25 Correct 14 ms 4676 KB Output is correct
26 Correct 14 ms 5064 KB Output is correct
27 Correct 22 ms 5452 KB Output is correct
28 Correct 14 ms 5900 KB Output is correct
29 Correct 916 ms 42092 KB Output is correct
30 Correct 835 ms 64412 KB Output is correct
31 Correct 862 ms 87352 KB Output is correct
32 Correct 880 ms 110692 KB Output is correct
33 Correct 861 ms 128728 KB Output is correct
34 Correct 886 ms 153900 KB Output is correct
35 Correct 1084 ms 192544 KB Output is correct
36 Correct 954 ms 226248 KB Output is correct
37 Correct 1090 ms 265212 KB Output is correct