답안 #1024097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024097 2024-07-15T11:57:11 Z LIF 축구 경기장 (IOI23_soccer) C++17
1.5 / 100
210 ms 65056 KB
#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
int FF[2005][2005];
bool vis[2005][2005];
int dp[11][11][11][11];
int su[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++)
        {
            su[i][j] = su[i][j-1] + FF[i][j];
            if(FF[i][j] == 1)
            {
                exis++;
                ii = i;
                jj = j;
            }
        }
    }
    if(N <= 7)
    {
        for(int i=1;i<=10;i++)
        {
            for(int j=1;j<=10;j++)
            {
                for(int k=1;k<=10;k++)
                {
                    for(int p=1;p<=10;p++)dp[i][j][k][p] = 0;
                }
            }
        }
        for(int len = 1;len <= N;len++)
        {
            for(int i=1;i+len-1 <= N;i++)
            {
                int j = i+len-1;
                for(int c = 1;c <= N;c++)
                {
                    for(int d = 1;d<=N;d++) //計算dp[i][j][c][d];
                    {
                        for(int e = 1;e<=N;e++)
                        {
                            for(int f = 1;f<=N;f++) // 當且僅當e f 可以完全包含c,d: //即e <= c && f >= d
                            {
                                if(e > c || f < d)continue;
                                if(su[i][d] - su[i][c-1] == 0)//同時,必須保證c,d可以取到 , 即第i行可以取到
                                {
                                    dp[i][j][c][d] = max(dp[i][j][c][d],dp[i+1][j][e][f] + d - c + 1);
                                } 
                                if(su[j][d] - su[j][c-1] == 0)
                                {
                                    dp[i][j][c][d] = max(dp[i][j][c][d],dp[i][j-1][e][f] + d - c + 1);
                                }
                                dp[i][j][c][d] = max(dp[i][j][c][d],dp[i+1][j][c][d]);
                                dp[i][j][c][d] = max(dp[i][j][c][d],dp[i][j-1][c][d]);
                            }
                        }
                    }
                }
            }
        }
        int maxn = -1;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
                for(int k=1;k<=N;k++)
                {
                    for(int p=1;p<=N;p++)maxn = max(maxn,dp[i][j][k][p]);
                }
            }
        }
        return maxn;
    }
    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,0-j));
            }
        }
        sort(row.begin(),row.end());
        /*for(int i=0;i<row.size();i++)cout<<row[i].first<<" "<<row[i].second<<endl;
        cout<<endl;*/

        bool flag3 = true;
        for(int i=1;i<row.size();i++)
        {
            if((0-row[i].second) > (0-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,0-i));
            }
        }
        sort(column.begin(),column.end());
        bool flag4 = true;
        for(int i=1;i<column.size();i++)
        {
            if((0-column[i].second) > (0-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:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<F.size();i++)
      |                 ~^~~~~~~~~
soccer.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int j=0;j<F[i].size();j++)FF[i+1][j+1] = F[i][j];
      |                     ~^~~~~~~~~~~~
soccer.cpp:179: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]
  179 |         for(int i=1;i<row.size();i++)
      |                     ~^~~~~~~~~~~
soccer.cpp:198: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]
  198 |         for(int i=1;i<column.size();i++)
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 2396 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 4444 KB ok
6 Partially correct 1 ms 4444 KB partial
7 Correct 2 ms 2908 KB ok
8 Correct 15 ms 11356 KB ok
9 Correct 210 ms 65056 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 4440 KB ok
5 Correct 1 ms 4600 KB ok
6 Correct 1 ms 4444 KB ok
7 Correct 1 ms 4440 KB ok
8 Correct 1 ms 4444 KB ok
9 Correct 0 ms 4444 KB ok
10 Correct 0 ms 4444 KB ok
11 Incorrect 1 ms 4444 KB wrong
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4444 KB ok
4 Correct 1 ms 4440 KB ok
5 Correct 1 ms 4440 KB ok
6 Correct 1 ms 4600 KB ok
7 Correct 1 ms 4444 KB ok
8 Correct 1 ms 4440 KB ok
9 Correct 1 ms 4444 KB ok
10 Correct 0 ms 4444 KB ok
11 Correct 0 ms 4444 KB ok
12 Incorrect 1 ms 4444 KB wrong
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4444 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 2396 KB ok
6 Correct 1 ms 4440 KB ok
7 Correct 1 ms 4440 KB ok
8 Correct 1 ms 4600 KB ok
9 Correct 1 ms 4444 KB ok
10 Correct 1 ms 4440 KB ok
11 Correct 1 ms 4444 KB ok
12 Correct 0 ms 4444 KB ok
13 Correct 0 ms 4444 KB ok
14 Incorrect 1 ms 4444 KB wrong
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4444 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 2396 KB ok
6 Correct 1 ms 4440 KB ok
7 Correct 1 ms 4440 KB ok
8 Correct 1 ms 4600 KB ok
9 Correct 1 ms 4444 KB ok
10 Correct 1 ms 4440 KB ok
11 Correct 1 ms 4444 KB ok
12 Correct 0 ms 4444 KB ok
13 Correct 0 ms 4444 KB ok
14 Incorrect 1 ms 4444 KB wrong
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4444 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 2396 KB ok
6 Correct 1 ms 4444 KB ok
7 Partially correct 1 ms 4444 KB partial
8 Correct 2 ms 2908 KB ok
9 Correct 15 ms 11356 KB ok
10 Correct 210 ms 65056 KB ok
11 Correct 1 ms 4440 KB ok
12 Correct 1 ms 4440 KB ok
13 Correct 1 ms 4600 KB ok
14 Correct 1 ms 4444 KB ok
15 Correct 1 ms 4440 KB ok
16 Correct 1 ms 4444 KB ok
17 Correct 0 ms 4444 KB ok
18 Correct 0 ms 4444 KB ok
19 Incorrect 1 ms 4444 KB wrong
20 Halted 0 ms 0 KB -