Submission #1241906

#TimeUsernameProblemLanguageResultExecution timeMemory
1241906candi_ositosSoccer Stadium (IOI23_soccer)C++20
14 / 100
4562 ms531732 KiB
#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
int test(int N, vector <vector <int> > F){
    int lmt=-1, rmt=-1, umt=-1, dmt=-1;
    vector <int> ums, dms, rms, lms;
    ums.assign(N, -1);
    dms.assign(N, -1);
    rms.assign(N, -1);
    lms.assign(N, -1);
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(F[i][j]==1){
                if(i>0){
                    if(F[i-1][j]==0 && umt==-1){
                        umt=i;
                    }
                }
                if(j>0){
                    if(F[i][j-1]==0 && (lmt==-1 || lmt>j)){
                        lmt=j;
                    }
                }
                if(i<N-1){
                    if(F[i+1][j]==0){
                        dmt=i;
                    }
                }
                if(j<N-1){
                    if(F[i][j+1]==0 && rmt<j){
                        rmt=j;
                    }
                }
            }
            else if(F[i][j]==0){
                if(ums[j]==-1){
                    ums[j]=i;
                }
                if(lms[i]==-1){
                    lms[i]=j;
                }
                rms[i]=j;
                dms[j]=i;
            }
            else{
                break;
            }
        }
    }
    if((umt<=dmt+1 && (umt!=-1 && dmt!=-1)) || (lmt<=rmt+1 && (lmt!=-1 && rmt!=-1))){
        return 0;
    }
    for(int i=0; i<N; ++i){
        if(ums[i]!=-1){
            for(int j=0; j<N; ++j){
                if(dms[j]!=-1){
                    if(F[ums[i]][j]==1 && F[dms[j]][i]==1){
                        return 0;
                    }
                }
            }
        }
    }
    for(int i=0; i<N; ++i){
        if(lms[i]!=-1){
            for(int j=0; j<N; ++j){
                if(rms[j]!=-1){
                    if(F[j][lms[i]]==1 && F[i][rms[j]]==1){
                        return 0;
                    }
                }
            }
        }
    }
    int bsc=0;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(F[i][j]==0){
                ++bsc;
            }
        }
    }
    if(bsc==0){
        bsc=-1;
    }
    return bsc;
}
int biggest_stadium(int N, vector <vector <int> > F)
{
    int nosirvo=test(N, F);
    if(nosirvo>0){
        return nosirvo;
    }
    int tc=0;
    int x=-1;
    int y=-1;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(F[i][j]){
                ++tc;
                x=i;
                y=j;
            }
        }
    }
    if(tc==0){
        return N*N;
    }
    if(tc==1){
        if(x>N-x-1){
            x=N-x-1;
        }
        if(y>N-y-1){
            y=N-y-1;
        }
        return N*N-(x+1)*(y+1);
    }
    if(tc==N*N-1){
        return 1;
    }
    if(N>7){
        return 0;
    }
    vector <vector <vector <int> > > TQ;
    TQ.assign(1, vector <vector <int> >(N, vector <int>(N, -1)));
    TQ[0][0][0]=1;
    if(!F[0][0]){
        TQ.push_back(TQ[0]);
        TQ[1][0][0]=0;
    }
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(j>0 || i>0){
                int k=TQ.size();
                if(!F[i][j]){
                    for(int l=0; l<k; ++l){
                        TQ.push_back(TQ[l]);
                        TQ[TQ.size()-1][i][j]=0;
                        if(test(N, TQ[TQ.size()-1])==0){
                            TQ.pop_back();
                        }
                    }
                }
                for(int l=0; l<k; ++l){
                    TQ[l][i][j]=1;
                }
            }
        }
    }
    int mx=0;
    for(unsigned int i=0; i<TQ.size(); ++i){
        int aux=test(N, TQ[i]);
        if(aux>mx){
            mx=aux;
        }
    }
    return mx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...