Submission #839786

# Submission time Handle Problem Language Result Execution time Memory
839786 2023-08-30T15:51:23 Z model_code Soccer Stadium (IOI23_soccer) C++17
8 / 100
4500 ms 280 KB
// failed/sol_db_brute_force.cpp

#include "soccer.h"
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cassert>
#define xx first
#define yy second

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

bool is_convenient(int N, vector<vector<int>> C)
{
    auto prow = C, pcol = C;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            prow[i][j] += (j ? prow[i][j - 1] : 0);
            pcol[i][j] += (i ? pcol[i - 1][j] : 0);
        }
    }
    vector<pii> pos;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            if (!C[i][j])
                pos.push_back({i, j});
        }
    }
    for (int i = 0; i < pos.size(); ++i)
    {
        for (int j = 0; j < i; ++j)
        {
            auto p = pos[i], q = pos[j];
            if (p.xx != q.xx && p.yy != q.yy)
            {
                if (C[p.xx][q.yy] && C[q.xx][p.yy])
                {
                    return false;
                }
                continue;
            }
            if (p > q)
                swap(p, q);
            if (p.xx == q.xx && prow[p.xx][q.yy] - (p.yy ? prow[p.xx][p.yy - 1] : 0) > 0)
            {
                return false;
            }
            if (p.yy == q.yy && pcol[q.xx][p.yy] - (p.xx ? pcol[p.xx - 1][p.yy] : 0) > 0)
            {
                return false;
            }
        }
    }
    return true;
}

int biggest_stadium(int N, vector<vector<int>> C)
{
    int ans = 0;
    for (int mask = 0; mask < (1 << N * N); ++mask)
    {
        auto subset = C;
        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < N; ++j)
            {
                int ind = N * i + j, active = mask >> ind & 1;
                if (!active && C[i][j])
                {
                    goto skip;
                }
                subset[i][j] = active;
            }
        }
        if (is_convenient(N, subset))
        {
            ans = max(ans, N * N - __builtin_popcount(mask));
        }
    skip:;
    }
    return ans;
}

Compilation message

soccer.cpp: In function 'bool is_convenient(int, std::vector<std::vector<int> >)':
soccer.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = 0; i < pos.size(); ++i)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4581 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ok
2 Correct 1 ms 212 KB ok
3 Incorrect 124 ms 212 KB wrong
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB ok
2 Correct 1 ms 212 KB ok
3 Correct 1 ms 212 KB ok
4 Correct 1 ms 212 KB ok
5 Correct 1 ms 280 KB ok
6 Correct 1 ms 212 KB ok
7 Correct 1 ms 212 KB ok
8 Correct 1 ms 212 KB ok
9 Correct 1 ms 212 KB ok
10 Correct 0 ms 212 KB ok
11 Correct 1 ms 212 KB ok
12 Correct 1 ms 212 KB ok
13 Correct 1 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Execution timed out 4581 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4581 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4581 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4581 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -