답안 #1024146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024146 2024-07-15T13:41:35 Z LIF 축구 경기장 (IOI23_soccer) C++17
52 / 100
607 ms 575068 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;
bool vis2[2005][2005];
struct dg
{
    int prei;
    int prej;
    int prec;
    int pred;
};
dg pre[11][11][11][11];
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;
}
struct node
{
    int maxi;
    int mini;
    int maxj;
    int minj;
};
node temp;
node dfs2(int i,int j)
{
    temp.maxi = max(temp.maxi,i);
    temp.mini = min(temp.mini,i);
    temp.maxj = max(temp.maxj,j);
    temp.minj = min(temp.minj,j);
    vis2[i][j] = true;
    if(i+1 <= n && vis2[i+1][j] == false && FF[i+1][j] == 0)dfs2(i+1,j);
    if(j+1 <= n && vis2[i][j+1] == false && FF[i][j+1] == 0)dfs2(i,j+1);
    if(i-1 >= 1 && vis2[i-1][j] == false && FF[i-1][j] == 0)dfs2(i-1,j);
    if(j-1 >= 1 && vis2[i][j-1] == false && FF[i][j-1] == 0)dfs2(i,j-1);
    return temp;
}
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] = -1e9;
                }
            }
        }
        vector<node> last;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
                if(vis2[i][j] == false && FF[i][j] == 0)
                {
                    temp.maxi = -1;
                    temp.mini = 1e9;
                    temp.maxj = -1;
                    temp.minj = 1e9;
                    dfs2(i,j);
                    last.push_back(temp);
                }
            }
        }
       // for(auto it : last)cout<<it.mini<<" "<<it.maxi<<" "<<it.minj<<" "<<it.maxj<<endl;
       int maxn = -1;
        for(auto it : last)
        {
            for(int len = 1;len <= N;len++)
            {
                for(int i=1;i+len-1 <= N;i++)
                {
                    int j = i+len-1;
                    if(j > it.maxi || i < it.mini)continue;
                    for(int c = 1;c <= N;c++)
                    {
                        for(int d = c;d<=N;d++) //計算dp[i][j][c][d];
                        {
                            if(c < it.minj || d > it.maxj)continue;
                            for(int e = 1;e<=N;e++)
                            {
                                for(int f = e;f<=N;f++) // 當且僅當e f 可以完全包含c,d: //即e <= c && f >= d
                                {
                                    if(e < it.minj || f > it.maxj)continue;
                                    if(e > c || f < d)continue;
                                    if(i == j)
                                    {
                                        if(su[i][d] - su[i][c-1] != 0)
                                        {
                                            dp[i][j][c][d] = - 1e9;
                                        }
                                        else dp[i][j][c][d] = d - c + 1;
                                    }
                                    else
                                    {
                                        if(su[i][d] - su[i][c-1] == 0)//同時,必須保證c,d可以取到 , 即第i行可以取到
                                        {
                                            if(dp[i+1][j][e][f] + d - c + 1 >= dp[i][j][c][d])
                                            {
                                                dp[i][j][c][d] = max(dp[i][j][c][d],dp[i+1][j][e][f] + d - c + 1);
                                                pre[i][j][c][d] = dg{i+1,j,e,f};
                                            }
                                            
                                        } 
                                        if(su[j][d] - su[j][c-1] == 0)
                                        {
                                            if(dp[i][j-1][e][f] + d - c + 1 >= dp[i][j][c][d])
                                            {
                                                dp[i][j][c][d] = max(dp[i][j][c][d],dp[i][j-1][e][f] + d - c + 1);
                                                pre[i][j][c][d] = dg{i,j-1,e,f};
                                            }
                                        }
                                    }
                                    
                                }
                            }
                        }
                    }
                }
            }
        }
        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]);

                    }
                }
            }
        }
        int firi = 1;
        int firj = 7;
        int firc = 3;
        int fird = 3;
        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:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0;i<F.size();i++)
      |                 ~^~~~~~~~~
soccer.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j=0;j<F[i].size();j++)FF[i+1][j+1] = F[i][j];
      |                     ~^~~~~~~~~~~~
soccer.cpp:170:13: warning: unused variable 'firi' [-Wunused-variable]
  170 |         int firi = 1;
      |             ^~~~
soccer.cpp:171:13: warning: unused variable 'firj' [-Wunused-variable]
  171 |         int firj = 7;
      |             ^~~~
soccer.cpp:172:13: warning: unused variable 'firc' [-Wunused-variable]
  172 |         int firc = 3;
      |             ^~~~
soccer.cpp:173:13: warning: unused variable 'fird' [-Wunused-variable]
  173 |         int fird = 3;
      |             ^~~~
soccer.cpp:259: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]
  259 |         for(int i=1;i<row.size();i++)
      |                     ~^~~~~~~~~~~
soccer.cpp:278: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]
  278 |         for(int i=1;i<column.size();i++)
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 6492 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 344 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 1 ms 6492 KB ok
7 Correct 1 ms 4892 KB ok
8 Correct 17 ms 10332 KB ok
9 Correct 227 ms 72788 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 6492 KB ok
3 Correct 1 ms 2396 KB ok
4 Correct 1 ms 348 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 0 ms 448 KB ok
9 Correct 1 ms 344 KB ok
10 Correct 1 ms 2396 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 1 ms 348 KB ok
13 Correct 0 ms 444 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB ok
2 Correct 1 ms 6488 KB ok
3 Correct 1 ms 6492 KB ok
4 Correct 1 ms 2396 KB ok
5 Correct 1 ms 348 KB ok
6 Correct 1 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 0 ms 448 KB ok
10 Correct 1 ms 344 KB ok
11 Correct 1 ms 2396 KB ok
12 Correct 1 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 444 KB ok
15 Correct 0 ms 604 KB ok
16 Correct 1 ms 604 KB ok
17 Correct 1 ms 604 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 0 ms 344 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 604 KB ok
22 Correct 0 ms 604 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 1 ms 4444 KB ok
25 Correct 1 ms 600 KB ok
26 Correct 1 ms 604 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB ok
2 Correct 1 ms 6488 KB ok
3 Correct 1 ms 6492 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 2396 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 0 ms 448 KB ok
12 Correct 1 ms 344 KB ok
13 Correct 1 ms 2396 KB ok
14 Correct 1 ms 348 KB ok
15 Correct 1 ms 348 KB ok
16 Correct 0 ms 444 KB ok
17 Correct 0 ms 604 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 1 ms 604 KB ok
20 Correct 1 ms 604 KB ok
21 Correct 0 ms 344 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 0 ms 604 KB ok
24 Correct 0 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 1 ms 4444 KB ok
27 Correct 1 ms 600 KB ok
28 Correct 1 ms 604 KB ok
29 Correct 1 ms 604 KB ok
30 Partially correct 1 ms 604 KB partial
31 Partially correct 1 ms 604 KB partial
32 Partially correct 1 ms 4444 KB partial
33 Partially correct 1 ms 4444 KB partial
34 Correct 1 ms 2652 KB ok
35 Correct 1 ms 604 KB ok
36 Partially correct 1 ms 600 KB partial
37 Partially correct 1 ms 604 KB partial
38 Partially correct 1 ms 2904 KB partial
39 Partially correct 1 ms 2652 KB partial
40 Partially correct 1 ms 2652 KB partial
41 Partially correct 1 ms 604 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB ok
2 Correct 1 ms 6488 KB ok
3 Correct 1 ms 6492 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 2396 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 0 ms 448 KB ok
12 Correct 1 ms 344 KB ok
13 Correct 1 ms 2396 KB ok
14 Correct 1 ms 348 KB ok
15 Correct 1 ms 348 KB ok
16 Correct 0 ms 444 KB ok
17 Correct 0 ms 604 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 1 ms 604 KB ok
20 Correct 1 ms 604 KB ok
21 Correct 0 ms 344 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 0 ms 604 KB ok
24 Correct 0 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 1 ms 4444 KB ok
27 Correct 1 ms 600 KB ok
28 Correct 1 ms 604 KB ok
29 Correct 1 ms 604 KB ok
30 Partially correct 1 ms 604 KB partial
31 Partially correct 1 ms 604 KB partial
32 Partially correct 1 ms 4444 KB partial
33 Partially correct 1 ms 4444 KB partial
34 Correct 1 ms 2652 KB ok
35 Correct 1 ms 604 KB ok
36 Partially correct 1 ms 600 KB partial
37 Partially correct 1 ms 604 KB partial
38 Partially correct 1 ms 2904 KB partial
39 Partially correct 1 ms 2652 KB partial
40 Partially correct 1 ms 2652 KB partial
41 Partially correct 1 ms 604 KB partial
42 Partially correct 30 ms 29528 KB partial
43 Partially correct 28 ms 22620 KB partial
44 Partially correct 34 ms 39192 KB partial
45 Partially correct 36 ms 41860 KB partial
46 Partially correct 38 ms 37468 KB partial
47 Partially correct 38 ms 44636 KB partial
48 Correct 24 ms 21592 KB ok
49 Partially correct 24 ms 23132 KB partial
50 Partially correct 25 ms 29020 KB partial
51 Partially correct 19 ms 17500 KB partial
52 Partially correct 20 ms 15192 KB partial
53 Partially correct 17 ms 13660 KB partial
54 Partially correct 18 ms 15240 KB partial
55 Partially correct 20 ms 16916 KB partial
56 Partially correct 26 ms 25336 KB partial
57 Partially correct 36 ms 36944 KB partial
58 Partially correct 33 ms 35664 KB partial
59 Partially correct 40 ms 33556 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB ok
2 Correct 1 ms 6488 KB ok
3 Correct 1 ms 6492 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 344 KB ok
6 Correct 1 ms 348 KB ok
7 Correct 1 ms 6492 KB ok
8 Correct 1 ms 4892 KB ok
9 Correct 17 ms 10332 KB ok
10 Correct 227 ms 72788 KB ok
11 Correct 1 ms 2396 KB ok
12 Correct 1 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 1 ms 348 KB ok
16 Correct 0 ms 448 KB ok
17 Correct 1 ms 344 KB ok
18 Correct 1 ms 2396 KB ok
19 Correct 1 ms 348 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 444 KB ok
22 Correct 0 ms 604 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 1 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 0 ms 344 KB ok
27 Correct 1 ms 348 KB ok
28 Correct 0 ms 604 KB ok
29 Correct 0 ms 604 KB ok
30 Correct 1 ms 604 KB ok
31 Correct 1 ms 4444 KB ok
32 Correct 1 ms 600 KB ok
33 Correct 1 ms 604 KB ok
34 Correct 1 ms 604 KB ok
35 Partially correct 1 ms 604 KB partial
36 Partially correct 1 ms 604 KB partial
37 Partially correct 1 ms 4444 KB partial
38 Partially correct 1 ms 4444 KB partial
39 Correct 1 ms 2652 KB ok
40 Correct 1 ms 604 KB ok
41 Partially correct 1 ms 600 KB partial
42 Partially correct 1 ms 604 KB partial
43 Partially correct 1 ms 2904 KB partial
44 Partially correct 1 ms 2652 KB partial
45 Partially correct 1 ms 2652 KB partial
46 Partially correct 1 ms 604 KB partial
47 Partially correct 30 ms 29528 KB partial
48 Partially correct 28 ms 22620 KB partial
49 Partially correct 34 ms 39192 KB partial
50 Partially correct 36 ms 41860 KB partial
51 Partially correct 38 ms 37468 KB partial
52 Partially correct 38 ms 44636 KB partial
53 Correct 24 ms 21592 KB ok
54 Partially correct 24 ms 23132 KB partial
55 Partially correct 25 ms 29020 KB partial
56 Partially correct 19 ms 17500 KB partial
57 Partially correct 20 ms 15192 KB partial
58 Partially correct 17 ms 13660 KB partial
59 Partially correct 18 ms 15240 KB partial
60 Partially correct 20 ms 16916 KB partial
61 Partially correct 26 ms 25336 KB partial
62 Partially correct 36 ms 36944 KB partial
63 Partially correct 33 ms 35664 KB partial
64 Partially correct 40 ms 33556 KB partial
65 Partially correct 475 ms 391048 KB partial
66 Partially correct 331 ms 76884 KB partial
67 Partially correct 247 ms 76832 KB partial
68 Partially correct 560 ms 541748 KB partial
69 Partially correct 607 ms 519248 KB partial
70 Partially correct 536 ms 495756 KB partial
71 Partially correct 584 ms 547152 KB partial
72 Partially correct 588 ms 575068 KB partial
73 Correct 372 ms 199568 KB ok
74 Correct 383 ms 199828 KB ok
75 Partially correct 371 ms 199756 KB partial
76 Partially correct 489 ms 327252 KB partial
77 Partially correct 414 ms 326224 KB partial
78 Partially correct 338 ms 141708 KB partial
79 Partially correct 233 ms 76888 KB partial
80 Partially correct 226 ms 76940 KB partial
81 Partially correct 221 ms 77136 KB partial
82 Partially correct 247 ms 77392 KB partial
83 Partially correct 244 ms 76880 KB partial
84 Partially correct 262 ms 96340 KB partial
85 Partially correct 247 ms 88204 KB partial
86 Partially correct 263 ms 109904 KB partial
87 Partially correct 305 ms 123536 KB partial
88 Partially correct 391 ms 276112 KB partial
89 Partially correct 573 ms 514900 KB partial
90 Partially correct 533 ms 391508 KB partial
91 Partially correct 508 ms 380556 KB partial
92 Partially correct 231 ms 77016 KB partial
93 Partially correct 248 ms 76824 KB partial
94 Partially correct 234 ms 76880 KB partial
95 Partially correct 234 ms 76880 KB partial
96 Partially correct 233 ms 76944 KB partial
97 Partially correct 216 ms 76820 KB partial
98 Partially correct 222 ms 76884 KB partial
99 Partially correct 274 ms 92876 KB partial
100 Partially correct 514 ms 452176 KB partial
101 Partially correct 457 ms 258384 KB partial
102 Partially correct 468 ms 264532 KB partial
103 Partially correct 557 ms 425816 KB partial
104 Partially correct 467 ms 260488 KB partial
105 Partially correct 464 ms 257172 KB partial
106 Partially correct 537 ms 365476 KB partial
107 Partially correct 566 ms 331860 KB partial
108 Partially correct 289 ms 95056 KB partial
109 Partially correct 309 ms 121612 KB partial