Submission #1023601

# Submission time Handle Problem Language Result Execution time Memory
1023601 2024-07-15T03:34:47 Z LIF Soccer Stadium (IOI23_soccer) C++17
6 / 100
240 ms 55384 KB
#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
int FF[2005][2005];
bool vis[2005][2005];
int n;
bool dfs(int i,int j)
{
    vis[i][j] = true;
    if(i+1 <= n && vis[i+1][j] == false)dfs(i+1,j);
    if(j+1 <= n && vis[i][j+1] == false)dfs(i,j+1);
    if(i-1 >= 1 && vis[i-1][j] == false)dfs(i-1,j);
    if(j-1 >= 1 && vis[i][j-1] == false)dfs(i,j-1);
}
int biggest_stadium(int N, vector<vector<int>> F)
{
    n = N;
    for(int i=0;i<F.size();i++)
    {
        for(int j=0;j<F[i].size();j++)FF[i+1][j+1] = F[i][j];
    }
    int exis = 0;
    int ii = -1;
    int jj = -1;
    for(int i=1;i<=N;i++)
    {
        for(int j=1;j<=N;j++)
        {
            if(FF[i][j] == 1)
            {
                exis++;
                ii = i;
                jj = j;
            }
        }
    }
    if(exis == 0)return N*N;
    if(exis == 1)
    {
        int ans1 = 0;
        int ans2 = 0;
        int ans3 = 0;
        int ans4 = 0;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
                if((j > jj) || (i > ii))ans1++;
                if((j < jj) || (i < ii))ans2++;
                if((j > jj) || (i < ii))ans3++;
                if((j < jj) || (i > ii))ans4++;
            }
        }
        return max(max(ans1,ans2),max(ans3,ans4));
    }
    else
    {
        int all = 0;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)if(FF[i][j] == 0)all++;
        }
        int cnt1 = 0;
        //第一步,測試是否有多於一個連通塊
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(vis[i][j] == false && FF[i][j] == 0)
                {
                    cnt1++;
                    dfs(i,j);
                }
            }
        }
        if(cnt1 >= 2)return -1; // 即多於一個連通塊,隨便返回
        //第二步,測試同一行 / 同一列是否有多於一個連通塊
        bool flag2 = true;
        for(int i=1;i<=N;i++)
        {
            int cnt2 = 0;
            for(int j=1;j<=N;j++)
            {
                if(FF[i][j] == 1)continue;
                while(FF[i][j+1] == 0 && j+1 <= N)j++;
                cnt2++;
                if(cnt2 >= 2)flag2 = false;
            }
        }
        for(int j=1;j<=N;j++)
        {
            int cnt2 = 0;
            for(int i=1;i<=N;i++)
            {
                if(FF[i][j] == 1)continue;
                if(FF[i+1][j] == 0 && i+1 <= N)i++;
                cnt2++;
                if(cnt2 >= 2)flag2 = false;
            }
        }
        if(flag2 == false)return -1;
        //第三步,處理區間;
        vector<pair<int,int> > row;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
                if(FF[i][j] == 1)continue;
                int fir = j;
                if(FF[i][j+1] == 0 && j+1 <= N)j++;
                row.push_back(make_pair(fir,j));
            }
        }
        sort(row.begin(),row.end());
        bool flag3 = true;
        for(int i=1;i<row.size();i++)
        {
            if(row[i].second > row[i-1].second)flag3 = false;
        }
        if(flag3 == false)return -1;

        vector<pair<int,int> > column;
        for(int j=1;j<=n;j++)
        {
            for(int i=1;i<=n;i++)
            {
                if(FF[i][j] == 1)continue;
                int fir = i;
                while(FF[i+1][j] == 0 && i+1 <= n)i++;
                column.push_back(make_pair(fir,i));
            }
        }
        sort(column.begin(),column.end());
        bool flag4 = true;
        for(int i=1;i<column.size();i++)
        {
            if(column[i].second > column[i-1].second)flag4 = false;
        }
        if(flag4 == false)return -1;
        return all;
        

    }
    
}

Compilation message

soccer.cpp: In function 'bool dfs(int, int)':
soccer.cpp:14:1: warning: no return statement in function returning non-void [-Wreturn-type]
   14 | }
      | ^
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<F.size();i++)
      |                 ~^~~~~~~~~
soccer.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for(int j=0;j<F[i].size();j++)FF[i+1][j+1] = F[i][j];
      |                     ~^~~~~~~~~~~~
soccer.cpp:116:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for(int i=1;i<row.size();i++)
      |                     ~^~~~~~~~~~~
soccer.cpp:135:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |         for(int i=1;i<column.size();i++)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 ms 344 KB ok
3 Correct 0 ms 604 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 ms 860 KB ok
8 Correct 14 ms 5900 KB ok
9 Correct 240 ms 55384 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 ms 344 KB ok
3 Runtime error 1 ms 856 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -