제출 #1122393

#제출 시각아이디문제언어결과실행 시간메모리
1122393deera축구 경기장 (IOI23_soccer)C++17
29.50 / 100
382 ms52352 KiB
#include "bits/stdc++.h" using namespace std; struct Point { int x, y; Point(int x, int y): x(x), y(y) {} }; int biggest_stadium(int N, vector<vector<int>> F) { int num_trees = 0; for (auto i: F) for (int j: i) num_trees += j; if (num_trees == 0) { return N*N; } if (num_trees == 1) { int x, y; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (F[i][j] == 1) { x = i, y = j; break; } return N*N - min(x + 1, N - x) * min(y + 1, N - y); } // for (auto row: F) { // bool beg = false, end = false; // for (int i: row) { // if (i == 0 && !beg) beg = true; // if (i == 1 && beg) end = true; // if (i == 0 && end) return 0; // } // } bool beg, end; for (int i = 0; i < N; i++) { beg = false, end = false; for (int j = 0; j < N; j++) { if (F[j][i] == 0 && !beg) beg = true; if (F[j][i] == 1 && beg) end = true; if (F[j][i] == 0 && end) return 0; } beg = false, end = false; for (int j = 0; j < N; j++) { if (F[i][j] == 0 && !beg) beg = true; if (F[i][j] == 1 && beg) end = true; if (F[i][j] == 0 && end) return 0; } } for (int i = 0; i < N; i++) { F[i].insert(F[i].begin(), 1); F[i].push_back(1); } F.insert(F.begin(), vector<int>(N + 2, 1)); F.push_back(vector<int>(N + 2, 1)); N += 2; auto valid = [&](int n) { return n >= 0 && n < N; }; int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; vector<vector<bool>> seen(N, vector<bool>(N, false)); queue<tuple<int, int, bool>> q; bool f1 = false, f0 = false; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (!f1 && F[i][j] == 1) q.push({i, j, 1}), f1 = 1, seen[i][j] = true; if (!f0 && F[i][j] == 0) q.push({i, j, 0}), f0 = 1, seen[i][j] = true; } while (!q.empty()) { auto [x, y, t] = q.front(); q.pop(); for (auto [dx, dy]: dirs) { int nx = x + dx, ny = y + dy; if (valid(nx) && valid(ny) && !seen[nx][ny] && F[nx][ny] == t) { q.push({nx, ny, t}); seen[nx][ny] = true; } } } for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (!seen[i][j]) return 0; // islands!!! // most extreme zeros // Point minx = {N, N}, maxx = {0, 0}, miny = {N, N}, maxy = {0, 0}; // for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { // if (F[i][j] == 0) { // if (i < minx.x) minx = {i, j}; // if (i > maxx.x) maxx = {i, j}; // if (j < miny.y) miny = {i, j}; // if (j > maxy.y) maxy = {i, j}; // } // } // Point points[4] = {minx, maxx, miny, maxy}; vector<Point> points; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (F[i][j] == 0) { int corners[4][2][2] = { {{1, 0}, {0, 1}}, {{1, 0}, {0, -1}}, {{-1, 0}, {0, 1}}, {{-1, 0}, {0, -1}} }; for (auto [a, b]: corners) { int ax = i + a[0], ay = j + a[1]; int bx = i + b[0], by = j + b[1]; if (F[ax][ay] + F[bx][by] == 2) { points.push_back(Point(i, j)); break; } } } } for (int i = 0; i < points.size(); i++) for (int j = i + 1; j < points.size(); j++) { if (F[points[i].x][points[j].y] + F[points[j].x][points[i].y] == 2) { return 0; // 3 or more kicks } } int zeros = 0; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (F[i][j] == 0) zeros++; } return zeros; }

컴파일 시 표준 에러 (stderr) 메시지

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:136:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for (int i = 0; i < points.size(); i++) for (int j = i + 1; j < points.size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
soccer.cpp:136:67: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for (int i = 0; i < points.size(); i++) for (int j = i + 1; j < points.size(); j++) {
      |                                                                 ~~^~~~~~~~~~~~~~~
soccer.cpp:25:48: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |         return N*N - min(x + 1, N - x) * min(y + 1, N - y);
      |                                              ~~^~~
soccer.cpp:25:28: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |         return N*N - min(x + 1, N - x) * min(y + 1, N - y);
      |                          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...