Submission #751624

# Submission time Handle Problem Language Result Execution time Memory
751624 2023-06-01T02:29:09 Z guagua0407 The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
0 ms 340 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=2e3+5;
int a[mxn][mxn];
vector<int> vec;
int n,m;
int mn=1e9;
int mx=0;

bool ok(int mid){
    int l=upper_bound(all(vec),mn+mid)-vec.begin()-1;
    int r=lower_bound(all(vec),mx-mid)-vec.begin();
    if(l<r-1) return false;
    vector<vector<int>> vis(n,vector<int>(m,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i][j]<=min(mn+mid,mx-mid-1)){
                vis[i][j]=-1;
            }
            else if(a[i][j]>=max(mn+mid+1,mx-mid)){
                vis[i][j]=1;
            }
        }
    }
    for(int i=0;i<n;i++){
        int cur=0;
        int a=0;
        int b=0;
        for(int j=0;j<m;j++){
            if(vis[i][j]==-1){
                if(cur==1){
                    if(a>0) return false;
                    else{
                        cur=-1;
                        a++;
                    }
                }
                else{
                    cur=-1;
                    a++;
                }
            }
            else if(vis[i][j]==1){
                if(cur==-1){
                    if(b>0) return false;
                    else{
                        cur=1;
                        b++;
                    }
                }
                else{
                    cur=1;
                    b++;
                }
            }
        }
    }
    for(int i=0;i<m;i++){
        int cur=0;
        int a=0;
        int b=0;
        for(int j=0;j<n;j++){
            if(vis[j][i]==-1){
                if(cur==1){
                    if(a>0) return false;
                    else{
                        cur=-1;
                        a++;
                    }
                }
                else{
                    a++;
                }
            }
            else if(vis[j][i]==1){
                if(cur==-1){
                    if(b>0) return false;
                    else{
                        cur=1;
                        b++;
                    }
                }
                else{
                    b++;
                }
            }
        }
    }
    return true;
}

signed main() {_
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            vec.push_back(a[i][j]);
            mx=max(mx,a[i][j]);
            mn=min(mn,a[i][j]);
        }
    }
    sort(all(vec));
    int l=0,r=mx-mn;
    while(l<r){
        int mid=(l+r)/2;
        if(ok(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<l<<'\n';
    return 0;
}
//maybe its multiset not set

Compilation message

joioi.cpp: In function 'void setIO(std::string)':
joioi.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -