Submission #199262

# Submission time Handle Problem Language Result Execution time Memory
199262 2020-01-30T18:21:14 Z Mercenary The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
699 ms 16248 KB
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 2e3 + 5;
int n , m , a[maxn][maxn] , Mi = 1e9 , Ma = 0;
int res = 0;
bool check(int val){
    int L = 1 ,  R = m;
    bool ok = 1  , ok1 = 1;
    for(int i = 1 ; i <= n ; ++i){
        int l = m , r = 1;
        for( ; l >= 1 ; --l){
            if(a[i][l] - ::Mi > val)break;
        }
        for( ; r <= m ; ++r){
            if(::Ma - a[i][r] > val)break;
        }
        --r;++l;
        R = min(R , r);
        if(R < l - 1)ok = 0;
        L = max(L , l);
        if(r + 1 < L)ok1 = 0;
        if(!ok && !ok1)break;
//        cout << l << " " << r << endl;
    }
//    cout << endl;
    if(ok || ok1)return 1;
    ok = 1 , ok1 = 1;
    L = 1;R = m;
    for(int i = 1 ; i <= n ; ++i){
        int l = m , r = 1;
        for( ; l >= 1 ; --l){
            if(::Ma - a[i][l] > val)break;
        }
        for( ; r <= m ; ++r){
            if(a[i][r] - ::Mi > val)break;
        }
        --r;++l;
        R = min(R , r);
        if(R < l - 1)ok = 0;
        L = max(L , l);
        if(r + 1 < L)ok1 = 0;
        if(!ok && !ok1)break;
//        cout << l << " " << r << endl;
    }
    if(ok || ok1)return 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 1 ; i <= n ; ++i)for(int j = 1 ; j <= m ; ++j){
        cin >> a[i][j];
        Mi = min(Mi,a[i][j]);Ma = max(Ma,a[i][j]);
    }
//    return cout << check(1) , 0;
    int l = 0, h = Ma - Mi;
    while(l <= h){
        int mid = l + h >> 1;
        if(check(mid))h = mid - 1;
        else l = mid + 1;
    }
    cout << min(l , Ma - Mi);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:73:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + h >> 1;
                   ~~^~~
joioi.cpp:62:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 12 ms 1272 KB Output is correct
18 Correct 11 ms 1272 KB Output is correct
19 Correct 11 ms 1272 KB Output is correct
20 Correct 10 ms 1144 KB Output is correct
21 Correct 13 ms 1272 KB Output is correct
22 Correct 12 ms 1272 KB Output is correct
23 Correct 13 ms 1272 KB Output is correct
24 Correct 12 ms 1144 KB Output is correct
25 Correct 12 ms 1276 KB Output is correct
26 Correct 12 ms 1272 KB Output is correct
27 Correct 13 ms 1272 KB Output is correct
28 Correct 12 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 12 ms 1272 KB Output is correct
18 Correct 11 ms 1272 KB Output is correct
19 Correct 11 ms 1272 KB Output is correct
20 Correct 10 ms 1144 KB Output is correct
21 Correct 13 ms 1272 KB Output is correct
22 Correct 12 ms 1272 KB Output is correct
23 Correct 13 ms 1272 KB Output is correct
24 Correct 12 ms 1144 KB Output is correct
25 Correct 12 ms 1276 KB Output is correct
26 Correct 12 ms 1272 KB Output is correct
27 Correct 13 ms 1272 KB Output is correct
28 Correct 12 ms 1272 KB Output is correct
29 Correct 473 ms 15292 KB Output is correct
30 Correct 480 ms 16124 KB Output is correct
31 Correct 499 ms 15992 KB Output is correct
32 Correct 493 ms 16120 KB Output is correct
33 Correct 421 ms 14072 KB Output is correct
34 Correct 493 ms 16248 KB Output is correct
35 Correct 699 ms 16120 KB Output is correct
36 Correct 597 ms 15992 KB Output is correct
37 Correct 683 ms 15996 KB Output is correct