#include "dzialka.h"
#include "message.h"
#include <iostream>
using namespace std;
const int rows = GetFieldHeight();
const int cols = GetFieldWidth();
bool usable(bool ** tab, int x, int y) {
return x >= 0 && x < rows && y >= 0 && y < cols && tab[x][y];
}
bool fits(bool ** tab, int x, int y, int px, int py) {
for (int i = 0; i < px; i++) {
for (int j = 0; j < py; j++) {
if (!usable(tab, x + i, y + j)) return false;
}
}
return true;
}
int main() {
if (MyNodeId() > 0) return 0;
bool** tab = new bool*[rows];
for(int i = 0; i < rows; ++i)
tab[i] = new bool[cols];
for (int x = 0; x < rows; x++)
for (int y = 0; y < cols; y++)
tab[x][y] = IsUsableCell(x, y);
long long result = 0;
long long xyresult = 0;
int max[cols+1];
for (int i = 0; i < cols+1; i++) max[i] = -1;
for (int px = 1; px <= rows; px++) {
for (int py = 1; py <= cols; py++) {
if (max[py] != -1 && px > max[py]) {
// cout << "py: " << py << " maxpy: " << max[py] << endl;
break;
}
for (int x = 0; x < rows; x++) {
if (x + px > rows) break;
for (int y = 0; y < cols; y++) {
if (y + py > cols) break;
// cout << "fits: x: " << x << " y: " << y << " px: " << px << " py: " << py << " | tab: " << tab[x][y] << " | usable: " << usable(tab, x, y) << " | fits: " << fits(tab, x, y, px, py) << endl;
if (fits(tab, x, y, px, py)) xyresult++;
}
}
if (xyresult == 0) {
max[py] = px;
} else {
result += xyresult;
xyresult = 0;
}
}
}
cout << result << "\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include "dzialka.h" #include "message.h" #include <iostream> using namespace std; const int rows = GetFieldHeight(); const int cols = GetFieldWidth(); bool usable(bool ** tab, int x, int y) { return x >= 0 && x < rows && y >= 0 && y < cols && tab[x][y]; } bool fits(bool ** tab, int x, int y, int px, int py) { for (int i = 0; i < px; i++) { for (int j = 0; j < py; j++) { if (!usable(tab, x + i, y + j)) return false; } } return true; } int main() { if (MyNodeId() > 0) return 0; bool** tab = new bool*[rows]; for(int i = 0; i < rows; ++i) tab[i] = new bool[cols]; for (int x = 0; x < rows; x++) for (int y = 0; y < cols; y++) tab[x][y] = IsUsableCell(x, y); long long result = 0; long long xyresult = 0; int max[cols+1]; for (int i = 0; i < cols+1; i++) max[i] = -1; for (int px = 1; px <= rows; px++) { for (int py = 1; py <= cols; py++) { if (max[py] != -1 && px > max[py]) { // cout << "py: " << py << " maxpy: " << max[py] << endl; break; } for (int x = 0; x < rows; x++) { if (x + px > rows) break; for (int y = 0; y < cols; y++) { if (y + py > cols) break; // cout << "fits: x: " << x << " y: " << y << " px: " << px << " py: " << py << " | tab: " << tab[x][y] << " | usable: " << usable(tab, x, y) << " | fits: " << fits(tab, x, y, px, py) << endl; if (fits(tab, x, y, px, py)) xyresult++; } } if (xyresult == 0) { max[py] = px; } else { result += xyresult; xyresult = 0; } } } cout << result << "\n"; return 0; } |
English