This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
bool checkcell(int i, int j, int n, vector<vector<int>>& f){
if (i < 0 || i >= n || j < 0 || j >= n || f[i][j] == 1){
return false;
}
return true;
}
int dfs(int i, int j, int n, vector<vector<int>>& f){
int t = 1;
f[i][j] = 1;
if (checkcell(i + 1, j, n, f)){
t += dfs(i + 1, j, n, f);
}
if (checkcell(i - 1, j, n, f)){
t += dfs(i - 1, j, n, f);
}
if (checkcell(i, j + 1, n, f)){
t += dfs(i, j + 1, n, f);
}
if (checkcell(i, j - 1, n, f)){
t += dfs(i, j - 1, n, f);
}
return t;
}
int biggest_stadium(int n, vector<vector<int>> f)
{
int t = 0;
int si, sj;
for (int i = 0; i < n; ++i){
for (int j = 0; j < n; ++j){
t += 1 - f[i][j];
if (f[i][j] == 0){
si = i;
sj = j;
}
}
}
vector<vector<int>> f2 = f;
if (dfs(si, sj, n, f2) != t){
return 1;
}
for (int i = 0; i < n; ++i){
for (int j = 0; j < n; ++j){
if (f[i][j] == 1){
if (checkcell(i + 1, j, n, f) && checkcell(i - 1, j, n, f)){
return 1;
}
if (checkcell(i, j + 1, n, f) && checkcell(i, j - 1, n, f)){
return 1;
}
}
}
}
return t;
}
Compilation message (stderr)
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:44:12: warning: 'si' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | if (dfs(si, sj, n, f2) != t){
| ~~~^~~~~~~~~~~~~~~
soccer.cpp:44:12: warning: 'sj' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |