Submission #1079555

#TimeUsernameProblemLanguageResultExecution timeMemory
1079555idasSoccer Stadium (IOI23_soccer)C++17
25 / 100
317 ms55632 KiB
#include "bits/stdc++.h"
#include "soccer.h"

#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define pb push_back
#define s second
#define f first

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int N=2e3+10;
int n, f[N][N], cn[N];
pii rn[N];

bool ok(int i, int j) {
    return (rn[i].f<=rn[j].f && rn[j].s<=rn[i].s) || (rn[j].f<=rn[i].f && rn[i].s<=rn[j].s);
}

int biggest_stadium(int N, std::vector<std::vector<int>> F) {
    n=N; FOR(i, 0, n) FOR(j, 0, n) f[i][j]=F[i][j];

    FOR(i, 0, n) {
        bool ended=false;
        FOR(j, 1, n) {
            if(f[i][j] && !f[i][j-1]) ended|=true;
            if(!f[i][j] && ended) return 0;
        }
        FOR(j, 0, n) cn[i]+=!f[i][j];
        FOR(j, 0, n) {
            if(!f[i][j]) {
                rn[i].f=j;
                break;
            }
        }
        for(int j=n-1; j>=0; j--) {
            if(!f[i][j]) {
                rn[i].s=j;
                break;
            }
        }
    }

    int st, nd;
    FOR(i, 0, n) {
        if(cn[i]!=0) {
            st=i;
            break;
        }
    }
    for(int i=n-1; i>=0; i--) {
        if(cn[i]!=0) {
            nd=i;
            break;
        }
    }
    FOR(i, st, nd+1) {
        if(cn[i]==0) return 0;
    }

    FOR(i, st, nd+1) {
        FOR(j, i+1, nd+1) {
            // cout << rn[i].f << " " << rn[i].s << "; " << rn[j].f << " " << rn[j].s << endl;
            if(!ok(i, j)) return 0;
        }
    }

    bool dec=false;
    FOR(i, 1, n) {
        if(cn[i]>cn[i-1] && dec) return 0;
        if(cn[i]<cn[i-1]) dec=true;
    }

    int tot=0;
    FOR(i, 0, n) tot+=cn[i];

    return tot;
}
/*
5
1 1 0 1 1
1 0 0 0 1
1 0 0 0 0
1 0 0 0 1
0 0 0 0 0

4
1 1 1 0
0 0 0 0
0 0 0 0
1 1 1 1
*/

Compilation message (stderr)

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:45:9: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     int st, nd;
      |         ^~
soccer.cpp:4:48: warning: 'nd' may be used uninitialized in this function [-Wmaybe-uninitialized]
    4 | #define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
      |                                                ^
soccer.cpp:45:13: note: 'nd' was declared here
   45 |     int st, nd;
      |             ^~
#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...