#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,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: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:121: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]
121 | for(int i=1;i<row.size();i++)
| ~^~~~~~~~~~~
soccer.cpp:140: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]
140 | for(int i=1;i<column.size();i++)
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
440 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
968 KB |
ok |
8 |
Correct |
15 ms |
5844 KB |
ok |
9 |
Correct |
215 ms |
55380 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Partially correct |
1 ms |
344 KB |
partial |
4 |
Partially correct |
0 ms |
348 KB |
partial |
5 |
Partially correct |
0 ms |
348 KB |
partial |
6 |
Partially correct |
1 ms |
344 KB |
partial |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Partially correct |
0 ms |
348 KB |
partial |
11 |
Partially correct |
0 ms |
348 KB |
partial |
12 |
Partially correct |
0 ms |
348 KB |
partial |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Partially correct |
1 ms |
344 KB |
partial |
5 |
Partially correct |
0 ms |
348 KB |
partial |
6 |
Partially correct |
0 ms |
348 KB |
partial |
7 |
Partially correct |
1 ms |
344 KB |
partial |
8 |
Partially correct |
0 ms |
348 KB |
partial |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Partially correct |
0 ms |
348 KB |
partial |
12 |
Partially correct |
0 ms |
348 KB |
partial |
13 |
Partially correct |
0 ms |
348 KB |
partial |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Partially correct |
0 ms |
348 KB |
partial |
16 |
Partially correct |
0 ms |
348 KB |
partial |
17 |
Partially correct |
0 ms |
348 KB |
partial |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Partially correct |
0 ms |
348 KB |
partial |
23 |
Partially correct |
0 ms |
348 KB |
partial |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
1 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
392 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
1 ms |
344 KB |
partial |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Partially correct |
0 ms |
348 KB |
partial |
9 |
Partially correct |
1 ms |
344 KB |
partial |
10 |
Partially correct |
0 ms |
348 KB |
partial |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Partially correct |
0 ms |
348 KB |
partial |
14 |
Partially correct |
0 ms |
348 KB |
partial |
15 |
Partially correct |
0 ms |
348 KB |
partial |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Partially correct |
0 ms |
348 KB |
partial |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Partially correct |
0 ms |
348 KB |
partial |
21 |
Partially correct |
0 ms |
348 KB |
partial |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
1 ms |
348 KB |
partial |
28 |
Partially correct |
0 ms |
392 KB |
partial |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
604 KB |
partial |
31 |
Partially correct |
0 ms |
604 KB |
partial |
32 |
Partially correct |
0 ms |
604 KB |
partial |
33 |
Partially correct |
0 ms |
604 KB |
partial |
34 |
Correct |
1 ms |
604 KB |
ok |
35 |
Correct |
1 ms |
604 KB |
ok |
36 |
Partially correct |
1 ms |
604 KB |
partial |
37 |
Partially correct |
1 ms |
604 KB |
partial |
38 |
Partially correct |
0 ms |
604 KB |
partial |
39 |
Partially correct |
0 ms |
604 KB |
partial |
40 |
Partially correct |
0 ms |
604 KB |
partial |
41 |
Partially correct |
0 ms |
604 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
1 ms |
344 KB |
partial |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Partially correct |
0 ms |
348 KB |
partial |
9 |
Partially correct |
1 ms |
344 KB |
partial |
10 |
Partially correct |
0 ms |
348 KB |
partial |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Partially correct |
0 ms |
348 KB |
partial |
14 |
Partially correct |
0 ms |
348 KB |
partial |
15 |
Partially correct |
0 ms |
348 KB |
partial |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Partially correct |
0 ms |
348 KB |
partial |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Partially correct |
0 ms |
348 KB |
partial |
21 |
Partially correct |
0 ms |
348 KB |
partial |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
1 ms |
348 KB |
partial |
28 |
Partially correct |
0 ms |
392 KB |
partial |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
604 KB |
partial |
31 |
Partially correct |
0 ms |
604 KB |
partial |
32 |
Partially correct |
0 ms |
604 KB |
partial |
33 |
Partially correct |
0 ms |
604 KB |
partial |
34 |
Correct |
1 ms |
604 KB |
ok |
35 |
Correct |
1 ms |
604 KB |
ok |
36 |
Partially correct |
1 ms |
604 KB |
partial |
37 |
Partially correct |
1 ms |
604 KB |
partial |
38 |
Partially correct |
0 ms |
604 KB |
partial |
39 |
Partially correct |
0 ms |
604 KB |
partial |
40 |
Partially correct |
0 ms |
604 KB |
partial |
41 |
Partially correct |
0 ms |
604 KB |
partial |
42 |
Partially correct |
36 ms |
26452 KB |
partial |
43 |
Partially correct |
26 ms |
19548 KB |
partial |
44 |
Partially correct |
32 ms |
34392 KB |
partial |
45 |
Partially correct |
34 ms |
35152 KB |
partial |
46 |
Partially correct |
32 ms |
30804 KB |
partial |
47 |
Partially correct |
34 ms |
37644 KB |
partial |
48 |
Correct |
22 ms |
14940 KB |
ok |
49 |
Partially correct |
21 ms |
16472 KB |
partial |
50 |
Partially correct |
24 ms |
22356 KB |
partial |
51 |
Partially correct |
19 ms |
10832 KB |
partial |
52 |
Partially correct |
16 ms |
8284 KB |
partial |
53 |
Partially correct |
15 ms |
7004 KB |
partial |
54 |
Partially correct |
16 ms |
8332 KB |
partial |
55 |
Partially correct |
19 ms |
10076 KB |
partial |
56 |
Partially correct |
21 ms |
18264 KB |
partial |
57 |
Partially correct |
33 ms |
30032 KB |
partial |
58 |
Partially correct |
35 ms |
28676 KB |
partial |
59 |
Partially correct |
27 ms |
26632 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
440 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
968 KB |
ok |
9 |
Correct |
15 ms |
5844 KB |
ok |
10 |
Correct |
215 ms |
55380 KB |
ok |
11 |
Partially correct |
1 ms |
344 KB |
partial |
12 |
Partially correct |
0 ms |
348 KB |
partial |
13 |
Partially correct |
0 ms |
348 KB |
partial |
14 |
Partially correct |
1 ms |
344 KB |
partial |
15 |
Partially correct |
0 ms |
348 KB |
partial |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Partially correct |
0 ms |
348 KB |
partial |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Partially correct |
0 ms |
348 KB |
partial |
23 |
Partially correct |
0 ms |
348 KB |
partial |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Partially correct |
0 ms |
348 KB |
partial |
31 |
Partially correct |
0 ms |
348 KB |
partial |
32 |
Partially correct |
1 ms |
348 KB |
partial |
33 |
Partially correct |
0 ms |
392 KB |
partial |
34 |
Partially correct |
0 ms |
348 KB |
partial |
35 |
Partially correct |
0 ms |
604 KB |
partial |
36 |
Partially correct |
0 ms |
604 KB |
partial |
37 |
Partially correct |
0 ms |
604 KB |
partial |
38 |
Partially correct |
0 ms |
604 KB |
partial |
39 |
Correct |
1 ms |
604 KB |
ok |
40 |
Correct |
1 ms |
604 KB |
ok |
41 |
Partially correct |
1 ms |
604 KB |
partial |
42 |
Partially correct |
1 ms |
604 KB |
partial |
43 |
Partially correct |
0 ms |
604 KB |
partial |
44 |
Partially correct |
0 ms |
604 KB |
partial |
45 |
Partially correct |
0 ms |
604 KB |
partial |
46 |
Partially correct |
0 ms |
604 KB |
partial |
47 |
Partially correct |
36 ms |
26452 KB |
partial |
48 |
Partially correct |
26 ms |
19548 KB |
partial |
49 |
Partially correct |
32 ms |
34392 KB |
partial |
50 |
Partially correct |
34 ms |
35152 KB |
partial |
51 |
Partially correct |
32 ms |
30804 KB |
partial |
52 |
Partially correct |
34 ms |
37644 KB |
partial |
53 |
Correct |
22 ms |
14940 KB |
ok |
54 |
Partially correct |
21 ms |
16472 KB |
partial |
55 |
Partially correct |
24 ms |
22356 KB |
partial |
56 |
Partially correct |
19 ms |
10832 KB |
partial |
57 |
Partially correct |
16 ms |
8284 KB |
partial |
58 |
Partially correct |
15 ms |
7004 KB |
partial |
59 |
Partially correct |
16 ms |
8332 KB |
partial |
60 |
Partially correct |
19 ms |
10076 KB |
partial |
61 |
Partially correct |
21 ms |
18264 KB |
partial |
62 |
Partially correct |
33 ms |
30032 KB |
partial |
63 |
Partially correct |
35 ms |
28676 KB |
partial |
64 |
Partially correct |
27 ms |
26632 KB |
partial |
65 |
Partially correct |
449 ms |
373332 KB |
partial |
66 |
Partially correct |
251 ms |
59220 KB |
partial |
67 |
Partially correct |
226 ms |
59220 KB |
partial |
68 |
Partially correct |
534 ms |
524308 KB |
partial |
69 |
Partially correct |
542 ms |
501652 KB |
partial |
70 |
Partially correct |
520 ms |
478036 KB |
partial |
71 |
Partially correct |
509 ms |
529496 KB |
partial |
72 |
Partially correct |
602 ms |
557324 KB |
partial |
73 |
Correct |
339 ms |
181840 KB |
ok |
74 |
Correct |
347 ms |
182608 KB |
ok |
75 |
Partially correct |
331 ms |
182092 KB |
partial |
76 |
Partially correct |
382 ms |
309520 KB |
partial |
77 |
Partially correct |
422 ms |
308560 KB |
partial |
78 |
Partially correct |
317 ms |
124184 KB |
partial |
79 |
Partially correct |
215 ms |
59172 KB |
partial |
80 |
Partially correct |
207 ms |
59284 KB |
partial |
81 |
Partially correct |
213 ms |
59420 KB |
partial |
82 |
Partially correct |
232 ms |
59728 KB |
partial |
83 |
Partially correct |
230 ms |
59216 KB |
partial |
84 |
Partially correct |
229 ms |
78676 KB |
partial |
85 |
Partially correct |
228 ms |
70292 KB |
partial |
86 |
Partially correct |
259 ms |
92240 KB |
partial |
87 |
Partially correct |
250 ms |
104788 KB |
partial |
88 |
Partially correct |
341 ms |
257296 KB |
partial |
89 |
Partially correct |
517 ms |
497236 KB |
partial |
90 |
Partially correct |
463 ms |
373756 KB |
partial |
91 |
Partially correct |
439 ms |
362580 KB |
partial |
92 |
Partially correct |
218 ms |
59216 KB |
partial |
93 |
Partially correct |
229 ms |
59216 KB |
partial |
94 |
Partially correct |
213 ms |
59216 KB |
partial |
95 |
Partially correct |
213 ms |
59240 KB |
partial |
96 |
Partially correct |
203 ms |
59220 KB |
partial |
97 |
Partially correct |
208 ms |
59220 KB |
partial |
98 |
Partially correct |
218 ms |
59216 KB |
partial |
99 |
Partially correct |
264 ms |
75344 KB |
partial |
100 |
Partially correct |
547 ms |
434480 KB |
partial |
101 |
Partially correct |
415 ms |
240724 KB |
partial |
102 |
Partially correct |
459 ms |
246932 KB |
partial |
103 |
Partially correct |
534 ms |
408468 KB |
partial |
104 |
Partially correct |
443 ms |
242708 KB |
partial |
105 |
Partially correct |
457 ms |
239440 KB |
partial |
106 |
Partially correct |
501 ms |
348136 KB |
partial |
107 |
Partially correct |
480 ms |
314008 KB |
partial |
108 |
Partially correct |
273 ms |
77396 KB |
partial |
109 |
Partially correct |
288 ms |
104020 KB |
partial |