Submission #1056276

#TimeUsernameProblemLanguageResultExecution timeMemory
1056276perekopskadSoccer Stadium (IOI23_soccer)C++17
18 / 100
4531 ms31832 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define el '\n'
#define ff first
#define ss second
#define pii pair <ll, ll>
#define pb push_back
#define mkp make_pair
#define fr(i, l, r) for(ll i = l; i <= r; i++)
#define debug(x) \
    { cout << #x << " = " << x << el; }

template<class T, class S>
inline bool chmax(T &a, const S &b) {
    return (a < b ? a = b, 1 : 0);
}

template<class T, class S>
inline bool chmin(T &a, const S &b) {
    return (a > b ? a = b, 1 : 0);
}

const ll N = 2e3 + 10;
const ll M = 1e5 + 10;
const ll K = 400;
const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll LOG = 20;
const ll mod = 1000002022;
mt19937 rnd(time(0));

/*
5
0 0 0 1 1
0 0 0 1 1
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1
*/
ll pref[N][N], n;

ll get(ll x1, ll y1, ll x2, ll y2) {
    ll res = pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
    return res;
}

int biggest_stadium(int N, std::vector<std::vector<int>> F) {
    int cnt = 0; n = N;
    fr(i, 0, N - 1)
        fr(j, 0, N - 1)
            cnt += F[i][j];

    if(cnt > 1) {
        fr(i, 1, n)
            fr(j, 1, n)
                pref[i][j] = F[i - 1][j - 1] + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];

        ll ans = 0;
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                if(F[i - 1][j - 1]) continue;
                ans++;
                for(int i2 = i; i2 <= N; i2++) {
                    for(int j2 = 1; j2 <= N; j2++) {
                        if(F[i2 - 1][j2 - 1]) continue;
                        ll f = get(i, j, i2, j) + get(i2, min(j, j2), i2, max(j, j2));
                        ll s = get(i, j2, i2, j2) + get(i, min(j, j2), i, max(j, j2));
                        if(f && s)
                            return 1;
                    }
                }
            }
        }
        return ans;
    }

    ll ans = N * N;
    fr(i, 0, N - 1) {
        fr(j, 0, N - 1) {
            if(F[i][j]) {
                ll x = min(i + 1, N - i);
                ll y = min(j + 1, N - j);
                chmin(ans, N * N - x * y);
            }
        }
    }

    return ans;
}

/*
int main()
{
    int N;
    assert(1 == scanf("%d", &N));
    std::vector<std::vector<int>> F(N, std::vector<int>(N));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            assert(1 == scanf("%d", &F[i][j]));
        }
    }
    fclose(stdin);

    int res = biggest_stadium(N, F);

    printf("%d\n", res);
    fclose(stdout);
    return 0;
}
*/
#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...