Submission #841558

# Submission time Handle Problem Language Result Execution time Memory
841558 2023-09-01T16:55:34 Z Lawliet Soccer Stadium (IOI23_soccer) C++17
Compilation error
0 ms 0 KB
#include "soccer.h"
// #include <bits/stdc++.h>
 
using namespace std;

int size(pair<int,int> a) { return a.second - a.first + 1; }
bool checkIntervals(pair<int,int> a, pair<int,int> b) { return (b.first <= a.first && a.second <= b.second); }
 
bool isGood(int N, vector<vector<int>>& F)
{
    vector<pair<int,int>> intervals;
 
    for(int i = 0 ; i < N ; i++)
    {
        int numCells = 0;
        int minCell = N, maxCell = -1;
 
        for(int j = 0 ; j < N ; j++)
        {
            if( F[i][j] == 0 )
            {
                numCells++;
                minCell = min( minCell , j );
                maxCell = max( maxCell , j );
            }
        }
 
        if( numCells == 0 )
            continue;
 
        if( numCells != maxCell - minCell + 1 )
            return false;
 
        intervals.push_back( { minCell , maxCell } );
    }

    int p = 0;

    while( p + 1 < (int)intervals.size() && size(intervals[p]) <= size(intervals[p + 1]) )
        p++;

    while( p + 1 < (int)intervals.size() && size(intervals[p]) >= size(intervals[p + 1]) )
        p++;

    if( p != (int)intervals.size() - 1 )
        return false;
 
    sort( intervals.begin() , intervals.end() , [&](pair<int,int> a, pair<int,int> b){
        return size(a) < size(b);
    });
 
    for(int i = 0 ; i + 1 < (int)intervals.size() ; i++)
        if( !checkIntervals( intervals[i] , intervals[i + 1] ) ) return false;
 
    return true;
}
 
int biggest_stadium(int N, vector<vector<int>> F)
{
    if( !isGood(N, F) )
        return -1;
 
    int sum = 0;
 
    for(int i = 0 ; i < N ; i++)
        for(int j = 0 ; j < N ; j++)
            sum += 1 - F[i][j];
 
    return sum;
}

Compilation message

soccer.cpp: In function 'bool isGood(int, std::vector<std::vector<int> >&)':
soccer.cpp:48:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   48 |     sort( intervals.begin() , intervals.end() , [&](pair<int,int> a, pair<int,int> b){
      |     ^~~~
      |     short