Submission #1023799

# Submission time Handle Problem Language Result Execution time Memory
1023799 2024-07-15T06:42:13 Z LIF Soccer Stadium (IOI23_soccer) C++17
6 / 100
206 ms 56916 KB
#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
int FF[2005][2005];
bool vis[2005][2005];
int n;
void dfs(int i,int j)
{
    vis[i][j] = true;
    if(i+1 <= n && vis[i+1][j] == false && FF[i+1][j] == 0)dfs(i+1,j);
    if(j+1 <= n && vis[i][j+1] == false && FF[i][j+1] == 0)dfs(i,j+1);
    if(i-1 >= 1 && vis[i-1][j] == false && FF[i-1][j] == 0)dfs(i-1,j);
    if(j-1 >= 1 && vis[i][j-1] == false && FF[i][j-1] == 0)dfs(i,j-1);
    return;
}
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;
            }
        }
        if(flag2 == false)return -2;
        for(int j=1;j<=N;j++)
        {
            int cnt2 = 0;
            for(int i=1;i<=N;i++)
            {
                if(FF[i][j] == 1)continue;
                while(FF[i+1][j] == 0 && i+1 <= N)i++;
                cnt2++;
                if(cnt2 >= 2)flag2 = false;
            }
        }
        if(flag2 == false)return -3;
        //第三步,處理區間;
        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;
                while(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 && row[i].first != row[i-1].first)flag3 = false;
        }
        if(flag3 == false)return -4;

        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 && column[i].first != column[i-1].first)flag4 = false;
        }
        if(flag4 == false)return -5;
        return all;


    }
    
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<F.size();i++)
      |                 ~^~~~~~~~~
soccer.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int j=0;j<F[i].size();j++)FF[i+1][j+1] = F[i][j];
      |                     ~^~~~~~~~~~~~
soccer.cpp:118: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]
  118 |         for(int i=1;i<row.size();i++)
      |                     ~^~~~~~~~~~~
soccer.cpp:137: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]
  137 |         for(int i=1;i<column.size();i++)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB partial
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 1 ms 2652 KB ok
3 Correct 0 ms 2396 KB ok
4 Correct 1 ms 2552 KB ok
5 Correct 0 ms 2396 KB ok
6 Correct 1 ms 2392 KB ok
7 Correct 1 ms 4444 KB ok
8 Correct 13 ms 8844 KB ok
9 Correct 206 ms 56916 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB ok
2 Correct 1 ms 2652 KB ok
3 Partially correct 0 ms 2396 KB partial
4 Partially correct 0 ms 2396 KB partial
5 Partially correct 0 ms 2396 KB partial
6 Incorrect 0 ms 2496 KB wrong
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB partial
2 Correct 1 ms 2392 KB ok
3 Correct 1 ms 2652 KB ok
4 Partially correct 0 ms 2396 KB partial
5 Partially correct 0 ms 2396 KB partial
6 Partially correct 0 ms 2396 KB partial
7 Incorrect 0 ms 2496 KB wrong
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB partial
2 Correct 1 ms 2392 KB ok
3 Correct 1 ms 2652 KB ok
4 Correct 0 ms 2396 KB ok
5 Correct 1 ms 2552 KB ok
6 Partially correct 0 ms 2396 KB partial
7 Partially correct 0 ms 2396 KB partial
8 Partially correct 0 ms 2396 KB partial
9 Incorrect 0 ms 2496 KB wrong
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB partial
2 Correct 1 ms 2392 KB ok
3 Correct 1 ms 2652 KB ok
4 Correct 0 ms 2396 KB ok
5 Correct 1 ms 2552 KB ok
6 Partially correct 0 ms 2396 KB partial
7 Partially correct 0 ms 2396 KB partial
8 Partially correct 0 ms 2396 KB partial
9 Incorrect 0 ms 2496 KB wrong
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB partial
2 Correct 1 ms 2392 KB ok
3 Correct 1 ms 2652 KB ok
4 Correct 0 ms 2396 KB ok
5 Correct 1 ms 2552 KB ok
6 Correct 0 ms 2396 KB ok
7 Correct 1 ms 2392 KB ok
8 Correct 1 ms 4444 KB ok
9 Correct 13 ms 8844 KB ok
10 Correct 206 ms 56916 KB ok
11 Partially correct 0 ms 2396 KB partial
12 Partially correct 0 ms 2396 KB partial
13 Partially correct 0 ms 2396 KB partial
14 Incorrect 0 ms 2496 KB wrong
15 Halted 0 ms 0 KB -