-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlargestBlock.cpp
80 lines (72 loc) · 1.8 KB
/
largestBlock.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("largestBlock.in");
ofstream fout("largestBlock.out");
int main()
{
int testCase;
fin >> testCase;
for (int c = 1; c <= testCase; ++c)
{
int s, n;
fin >> s >> n;
vector<vector<int>> a(s + 2, vector<int>(s + 2, 1));
vector<vector<int>> dp(s + 2, vector<int>(s + 2));
for (int i = 1; i <= n; ++i)
{
int y1, x1, y2, x2;
fin >> y1 >> x1 >> y2 >> x2;
for (int y = y1; y <= y2; ++y)
{
for (int x = x1; x <= x2; ++x)
{
a[y][x] = -10001;
}
}
}
for (int y = 1; y <= s; ++y)
{
int sum = 0;
dp[y][0] = 0;
for (int x = 1; x <= s + 1; ++x)
{
sum += a[y][x];
dp[y][x] = sum;
}
}
int maxSum = -2147483646;
for (int y0 = 1; y0 <= s; ++y0)
{
for (int x0 = 1; x0 <= s; ++x0)
{
for (int x1 = x0; x1 <= s; ++x1)
{
int sum = 0;
for (int y1 = y0; y1 <= s; ++y1)
{
sum += dp[y1][x1] - dp[y1][x0 - 1];
maxSum = max(maxSum , sum);
}
}
}
}
if (maxSum < 0)
{
fout << "0\n";
}
else
{
fout << maxSum << '\n';
}
}
return 0;
}