#include "treasure.h"
#include <bits/stdc++.h>
using namespace std;
int ask(int r1, int c1, int r2, int c2)
{
if (r1 > r2 || c1 > c2)
{
return 0;
}
return countTreasure(r1, c1, r2, c2);
}
const int N = 100 + 7;
int ul[N][N];
int ur[N][N];
int dl[N][N];
int dr[N][N];
void findTreasurePar(int n)
{
int half = (n) / 2;
for (int i = 1; i <= half; i++)
{
for (int j = 1; j <= half; j++)
{
dr[i][j] = ask(i, j, n, n); /// pe [1, half] and [1, half]
}
}
for (int j = 1; j <= half; j++)
{
ur[n][j] = dr[1][j];
}
for (int i = half; i < n; i++)
{
for (int j = 1; j <= half; j++)
{
ur[i][j] = ask(1, j, i, n); /// pe [half + 1, n] and [1, half]
}
}
for (int i = half; i <= n; i++)
{
for (int j = half; j < n; j++)
{
ul[i][j] = ask(1, 1, i, j); /// pe [half + 1, n] and [half + 1, n]
}
}
for (int i = half; i <= n; i++)
{
ul[i][n] = ur[i][1];
}
for (int i = 2; i <= half; i++)
{
for (int j = half; j < n; j++)
{
dl[i][j] = ask(i, 1, n, j); /// pe [1, half] and [half + 1, n]
}
}
for (int j = half; j < n; j++)
{
dl[1][j] = ul[n][j];
}
for (int i = 1; i <= half; i++)
{
dl[i][n] = dr[i][1];
}
for (int i = 1; i <= half; i++)
{
for (int j = 1; j < half; j++)
{
dl[i][j] = dl[i][n] - dr[i][j + 1];
}
}
for (int i = half; i <= n; i++)
{
for (int j = 1; j < half; j++)
{
ul[i][j] = ul[i][n] - ur[i][j + 1];
}
}
for (int i = 1; i <= half - 1; i++)
{
for (int j = 1; j <= n; j++)
{
ul[i][j] = ul[n][j] - dl[i + 1][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
int val_ij = ul[i][j] - ul[i - 1][j] - ul[i][j - 1] + ul[i - 1][j - 1];
if (val_ij)
{
Report(i, j);
}
}
}
}
void findTreasure(int n)
{
if (n % 2 == 0)
{
findTreasurePar(n);
return;
}
int total = ask(1, 1, n, n);
int half = (n) / 2 + 1;
for (int i = 1; i <= half; i++)
{
for (int j = 1; j <= half; j++)
{
dr[i][j] = ask(i, j, n, n); /// pe [1, half] and [1, half]
}
}
for (int j = 1; j <= half; j++)
{
ur[n][j] = dr[1][j];
}
for (int i = half; i < n; i++)
{
for (int j = 1; j <= half; j++)
{
ur[i][j] = ask(1, j, i, n); /// pe [half + 1, n] and [1, half]
}
}
for (int i = half; i <= n; i++)
{
for (int j = half; j < n; j++)
{
ul[i][j] = ask(1, 1, i, j); /// pe [half + 1, n] and [half + 1, n]
}
}
for (int i = half; i <= n; i++)
{
ul[i][n] = ur[i][1];
}
for (int i = 2; i <= half; i++)
{
for (int j = half; j < n; j++)
{
dl[i][j] = ask(i, 1, n, j); /// pe [1, half] and [half + 1, n]
}
}
for (int j = half; j < n; j++)
{
dl[1][j] = ul[n][j];
}
for (int i = 1; i <= half; i++)
{
dl[i][n] = dr[i][1];
}
for (int i = 1; i <= half; i++)
{
for (int j = 1; j < half; j++)
{
dl[i][j] = dl[i][n] - dr[i][j + 1];
}
}
for (int i = half; i <= n; i++)
{
for (int j = 1; j < half; j++)
{
ul[i][j] = ul[i][n] - ur[i][j + 1];
}
}
for (int i = 1; i <= half - 1; i++)
{
for (int j = 1; j <= n; j++)
{
ul[i][j] = ul[n][j] - dl[i + 1][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
int val_ij = ul[i][j] - ul[i - 1][j] - ul[i][j - 1] + ul[i - 1][j - 1];
if (val_ij)
{
Report(i, j);
}
}
}
}
Compilation message
treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:120:7: warning: unused variable 'total' [-Wunused-variable]
120 | int total = ask(1, 1, n, n);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct - N = 5, K = 290, score = 10 |
2 |
Correct |
1 ms |
340 KB |
Output is correct - N = 10, K = 4475, score = 10 |
3 |
Correct |
0 ms |
340 KB |
Output is correct - N = 15, K = 22290, score = 10 |
4 |
Correct |
0 ms |
340 KB |
Output is correct - N = 16, K = 28928, score = 10 |
5 |
Correct |
1 ms |
340 KB |
Output is correct - N = 55, K = 4005290, score = 10 |
6 |
Correct |
0 ms |
340 KB |
Output is correct - N = 66, K = 8305803, score = 10 |
7 |
Correct |
0 ms |
340 KB |
Output is correct - N = 77, K = 15383162, score = 10 |
8 |
Correct |
1 ms |
468 KB |
Output is correct - N = 88, K = 26244416, score = 10 |
9 |
Correct |
1 ms |
468 KB |
Output is correct - N = 99, K = 42032202, score = 10 |
10 |
Correct |
1 ms |
468 KB |
Output is correct - N = 100, K = 43760000, score = 10 |