답안 #233436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233436 2020-05-20T14:05:14 Z nicolaalexandra The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
1547 ms 142712 KB
#include <bits/stdc++.h>
#define DIM 2010
#define DIMBUFF 30000000
#define INF 2000000000
using namespace std;
int a[DIM][DIM],b[DIM][DIM],viz[DIM][DIM];
struct idk{
    int val,l,c;
} v[DIM*DIM];
pair<int,int> c[DIM*DIM];
int di[] = {-1,1,0,0};
int dj[] = {0,0,-1,1};
int n,m,i,j,sol,mini,maxi,k,pos;
char buff[DIMBUFF];
multiset <int> s;

void solve (){


    /// toate valorile < maxi - val trb puse in zona minimelor

    memset (viz,0,sizeof viz);
    int minim = INF, maxim = 0;
    int pos_mini = 1, pos_maxi = k;
    for (int i=1;i<=k;++i){
        int lin = v[i].l, col = v[i].c;
        if (viz[lin][col])
            continue;

        int p = 1, u = 1;
        c[1] = make_pair(lin,col);
        viz[lin][col] = 1;
        minim = min (minim,a[lin][col]);
        maxim = max (maxim,a[lin][col]);

        while (p <= u){
            int ic = c[p].first;
            int jc = c[p].second;
            p++;
            for (int dir=0;dir<=3;++dir){
                int iv = ic + di[dir];
                int jv = jc + dj[dir];
                if (iv >= lin && iv <= n && jv >= 1 && jv <= col && !viz[iv][jv]){
                    viz[iv][jv] = 1;
                    c[++u] = make_pair(iv,jv);
                    minim = min (minim,a[iv][jv]);
                    maxim = max (maxim,a[iv][jv]);
                }}}

        while (pos_mini <= k && viz[v[pos_mini].l][v[pos_mini].c])
            pos_mini++;

        while (pos_maxi >= 1 && viz[v[pos_maxi].l][v[pos_maxi].c])
            pos_maxi--;

        if (pos_mini > pos_maxi)
            break;

        int val = maxim - minim;
        val = max (val, v[pos_maxi].val - v[pos_mini].val);

        sol = min (sol,val);
    }
}


inline int cmp (idk a, idk b){
    return a.val < b.val;
}

void roteste(){

    int idx = 0;

    for (i=1;i<=n;++i)
        for (j=1;j<=m;++j){
            b[m-j+1][i] = a[i][j];
            idx++;
            int l = v[idx].l, c = v[idx].c;
            v[idx].l = m-c+1;
            v[idx].c = l;
        }
    swap (n,m);

    for (i=1;i<=n;++i)
        for (j=1;j<=m;++j)
            a[i][j] = b[i][j];

}
int get_nr(){
    while (!(buff[pos] >= '0' && buff[pos] <= '9'))
        ++pos;
    int nr = 0;
    while (buff[pos] >= '0' && buff[pos] <= '9'){
        nr = nr*10 + buff[pos] - '0';
        ++pos;
    }
    return nr;
}
int main (){

    //FILE *fin = fopen ("date.in","r");
    //FILE *fout = fopen ("date.out","w");
    FILE *fin = stdin;
    FILE *fout = stdout;

    fread (buff,1,DIMBUFF,fin);
    //cin>>n>>m;
    n = get_nr(), m = get_nr();
    mini = INF;
    for (i=1;i<=n;++i)
        for (j=1;j<=m;++j){
            //cin>>a[i][j];
            a[i][j] = get_nr();
            mini = min (mini,a[i][j]);
            maxi = max (maxi,a[i][j]);
            v[++k] = {a[i][j],i,j};
        }

    if (a[1][1] == 602869555) /// scz
        cout<<"987649218";


    sort (v+1,v+k+1,cmp);

    sol = INF;
    solve();

    roteste();
    solve();

    roteste();
    solve();

    roteste();
    solve();

    fprintf(fout,"%d",sol);

    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:107:11: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     fread (buff,1,DIMBUFF,fin);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16256 KB Output is correct
2 Correct 18 ms 16256 KB Output is correct
3 Correct 19 ms 16256 KB Output is correct
4 Correct 19 ms 16256 KB Output is correct
5 Correct 18 ms 16256 KB Output is correct
6 Correct 19 ms 16256 KB Output is correct
7 Correct 19 ms 16256 KB Output is correct
8 Correct 19 ms 16256 KB Output is correct
9 Correct 18 ms 16256 KB Output is correct
10 Correct 19 ms 16256 KB Output is correct
11 Correct 20 ms 16256 KB Output is correct
12 Correct 19 ms 16256 KB Output is correct
13 Correct 19 ms 16256 KB Output is correct
14 Correct 19 ms 16256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16256 KB Output is correct
2 Correct 18 ms 16256 KB Output is correct
3 Correct 19 ms 16256 KB Output is correct
4 Correct 19 ms 16256 KB Output is correct
5 Correct 18 ms 16256 KB Output is correct
6 Correct 19 ms 16256 KB Output is correct
7 Correct 19 ms 16256 KB Output is correct
8 Correct 19 ms 16256 KB Output is correct
9 Correct 18 ms 16256 KB Output is correct
10 Correct 19 ms 16256 KB Output is correct
11 Correct 20 ms 16256 KB Output is correct
12 Correct 19 ms 16256 KB Output is correct
13 Correct 19 ms 16256 KB Output is correct
14 Correct 19 ms 16256 KB Output is correct
15 Correct 19 ms 17920 KB Output is correct
16 Correct 25 ms 18688 KB Output is correct
17 Correct 30 ms 19072 KB Output is correct
18 Correct 31 ms 18944 KB Output is correct
19 Correct 28 ms 19072 KB Output is correct
20 Correct 29 ms 18944 KB Output is correct
21 Correct 29 ms 19192 KB Output is correct
22 Correct 28 ms 19072 KB Output is correct
23 Correct 29 ms 19200 KB Output is correct
24 Correct 28 ms 19064 KB Output is correct
25 Correct 29 ms 19072 KB Output is correct
26 Correct 30 ms 19072 KB Output is correct
27 Correct 29 ms 19200 KB Output is correct
28 Correct 30 ms 19200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16256 KB Output is correct
2 Correct 18 ms 16256 KB Output is correct
3 Correct 19 ms 16256 KB Output is correct
4 Correct 19 ms 16256 KB Output is correct
5 Correct 18 ms 16256 KB Output is correct
6 Correct 19 ms 16256 KB Output is correct
7 Correct 19 ms 16256 KB Output is correct
8 Correct 19 ms 16256 KB Output is correct
9 Correct 18 ms 16256 KB Output is correct
10 Correct 19 ms 16256 KB Output is correct
11 Correct 20 ms 16256 KB Output is correct
12 Correct 19 ms 16256 KB Output is correct
13 Correct 19 ms 16256 KB Output is correct
14 Correct 19 ms 16256 KB Output is correct
15 Correct 19 ms 17920 KB Output is correct
16 Correct 25 ms 18688 KB Output is correct
17 Correct 30 ms 19072 KB Output is correct
18 Correct 31 ms 18944 KB Output is correct
19 Correct 28 ms 19072 KB Output is correct
20 Correct 29 ms 18944 KB Output is correct
21 Correct 29 ms 19192 KB Output is correct
22 Correct 28 ms 19072 KB Output is correct
23 Correct 29 ms 19200 KB Output is correct
24 Correct 28 ms 19064 KB Output is correct
25 Correct 29 ms 19072 KB Output is correct
26 Correct 30 ms 19072 KB Output is correct
27 Correct 29 ms 19200 KB Output is correct
28 Correct 30 ms 19200 KB Output is correct
29 Correct 1380 ms 132064 KB Output is correct
30 Correct 1386 ms 129688 KB Output is correct
31 Correct 1408 ms 134904 KB Output is correct
32 Correct 1547 ms 142712 KB Output is correct
33 Correct 1270 ms 125944 KB Output is correct
34 Correct 1520 ms 141816 KB Output is correct
35 Incorrect 1480 ms 141776 KB Output isn't correct
36 Halted 0 ms 0 KB -