제출 #419093

#제출 시각아이디문제언어결과실행 시간메모리
419093FlippenFazRectangles (IOI19_rect)C++14
15 / 100
5068 ms1048580 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define SIZE 4096 vector<vector<ll>> gridSegCol; vector<vector<ll>> gridSegRow; vector<vector<vector<int>>> checkCol; vector<vector<vector<int>>> checkRow; bool isRowValid(int left, int right, int rowNum) { if (checkRow[left][right][rowNum] != 0) { return checkRow[left][right][rowNum] == 1; } ll mx = -1; int l = left + SIZE; int r = right + SIZE; while (l <= r) { if (l%2 == 1) { mx = max(mx,gridSegRow[rowNum][l++]); } if (r%2 == 0) { mx = max(mx,gridSegRow[rowNum][r--]); } l/=2; r/=2; } //cerr << endl; //cerr << "VALUES FOR " << left << " " << right << " FOR ROW: " << rowNum << endl; //cerr << "MX: " << mx << " LEFT AND RIGHT: " << gridSegRow[rowNum][left+SIZE-1] << " " << gridSegRow[rowNum][right+SIZE+1] << endl; //cerr << "VALID?: " << ( (mx < gridSegRow[rowNum][left+SIZE-1]) && (mx < gridSegRow[rowNum][right+SIZE+1])) << endl; if ( (mx < gridSegRow[rowNum][left+SIZE-1]) && (mx < gridSegRow[rowNum][right+SIZE+1]) ) { checkRow[left][right][rowNum] = 1; return true; } else { checkRow[left][right][rowNum] = 0; return false; } return ( (mx < gridSegRow[rowNum][left+SIZE-1]) && (mx < gridSegRow[rowNum][right+SIZE+1])); } bool isColValid(int left, int right, int colNum) { if (checkCol[left][right][colNum] != 0) { return checkCol[left][right][colNum] == 1; } ll mx = -1; int l = left + SIZE; int r = right + SIZE; while (l <= r) { if (l%2 == 1) { mx = max(mx,gridSegCol[colNum][l++]); } if (r%2 == 0) { mx = max(mx,gridSegCol[colNum][r--]); } l/=2; r/=2; } //cerr << endl; //cerr << "VALUES FOR " << left << " " << right << " FOR COL: " << colNum << endl; //cerr << "MX: " << mx << " LEFT AND RIGHT: " << gridSegCol[colNum][left+SIZE-1] << " " << gridSegCol[colNum][right+SIZE+1] << endl; //cerr << "VALID?: " << ((mx < gridSegCol[colNum][left+SIZE-1]) && (mx < gridSegCol[colNum][right+SIZE+1])) << endl; if ((mx < gridSegCol[colNum][left+SIZE-1]) && (mx < gridSegCol[colNum][right+SIZE+1])) { checkCol[left][right][colNum] = 1; return true; } else { checkCol[left][right][colNum] = 2; return false; } } // 1 1 1 2 // 1 1 1 3 // 1 1 2 1 bool isBoxValid(int topRow, int leftCol, int botRow, int rightCol) { for (int i = topRow; i <= botRow; i++) { if (!isRowValid(leftCol, rightCol, i)) { return false; } } for (int i = leftCol; i <= rightCol; i++) { if (!isColValid(topRow, botRow, i)) { return false; } } return true; } ll count_rectangles(std::vector<std::vector<int> > a) { //cout << "ROWS A.size: " << a.size() << endl; //cout << "COLS a[0].size: " << a[0].size() << endl; ll big = max(a.size(),a[0].size()); ll cnt = 0; vector<ll> temp; temp.resize(SIZE*2); vector<int> t1; t1.resize(big); vector<vector<int>> t2; t2.resize(big, t1); checkRow.resize(big, t2); checkCol.resize(big, t2); gridSegRow.resize(a.size(), temp); gridSegCol.resize(a[0].size(), temp); //cerr << "HERE" << endl; for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[0].size(); j++) { gridSegRow[i][j+SIZE] = a[i][j]; gridSegCol[j][i+SIZE] = a[i][j]; } } //cerr << "Done" << endl; for (int i = 0; i < a.size(); i++) { for (int j = SIZE-1; j > 0; j--) { gridSegRow[i][j] = max( gridSegRow[i][j*2], gridSegRow[i][j*2+1]); } } for (int i = 0; i < a[0].size(); i++) { for (int j = SIZE-1; j > 0; j--) { gridSegCol[i][j] = max( gridSegCol[i][j*2], gridSegCol[i][j*2+1]); } } //cerr << gridSegCol[2][3+SIZE] << " SHOULD BE " << a[2][3]; for (int i = 1; i < a.size()-1; i++) { for (int j = 1; j < a[0].size()-1; j++) { for (int k = i; k < a.size()-1; k++) { for (int l = j; l < a[0].size()-1; l++) { //cerr << endl; //cerr << endl; //cerr << "Testing: " << i << " " << j << " " << k << " " << l << endl; bool isValid = isBoxValid(i, j, k, l); if (isValid) { //cerr << "BOX DIMENSIONS: " << i << " " << j << " " << k << " " << l << endl; cnt++; } } } } } return cnt; }

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

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:135:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
rect.cpp:136:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |   for (int j = 0; j < a[0].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
rect.cpp:144:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
rect.cpp:150:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |  for (int i = 0; i < a[0].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
rect.cpp:158:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |  for (int i = 1; i < a.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~
rect.cpp:159:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |   for (int j = 1; j < a[0].size()-1; j++) {
      |                   ~~^~~~~~~~~~~~~~~
rect.cpp:160:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |    for (int k = i; k < a.size()-1; k++) {
      |                    ~~^~~~~~~~~~~~
rect.cpp:161:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |     for (int l = j; l < a[0].size()-1; l++) {
      |                     ~~^~~~~~~~~~~~~~~
#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...