Submission #8963204
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
template <typename M>
class segment_tree {
using T = typename M::type;
const int n;
vector<T> data;
int expand(int x) {
int res;
for (res = 1; res < x; res <<= 1);
return res;
}
public:
segment_tree(int n_) : n(expand(n_)), data(n * 2, M::id()) {}
segment_tree(int n_, T val) : n(expand(n_)), data(n * 2, val) {}
void init(const vector<T>& data_) {
for (int i = 0; i < (int)data_.size(); i++)
data[i + n] = data_[i];
for (int i = n - 1; i >= 0; i--)
data[i] = M::op(data[i * 2], data[i * 2 + 1]);
}
void update(int p, T val) {
data[p += n] = val;
while (p >>= 1) data[p] = M::op(data[p * 2], data[p * 2 + 1]);
}
T find(int l, int r) {
l += n; r += n + 1;
T res1 = M::id(), res2 = M::id();
while (l < r) {
if (l & 1) res1 = M::op(res1, data[l++]);
if (r & 1) res2 = M::op(data[--r], res2);
l >>= 1; r >>= 1;
}
return M::op(res1, res2);
}
};
int main()
{
int H, W, K;
cin >> H >> W >> K;
vector<vector<int>> a(H, vector<int>(W, 1));
for (int i = 0; i < K; i++) {
int x, y;
cin >> x >> y; --x, --y;
a[x][y] = 0;
}
if (K == H * W) {
cout << 0 << endl;
return 0;
}
vector<vector<int>> dp1(H, vector<int>(W, 0)), dp2(H, vector<int>(W, 0));
auto dp3 = dp1;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) if (a[i][j]) {
dp1[i][j] = i == 0 ? 1 : dp1[i - 1][j] + 1;
}
}
for (int i = H - 1; i >= 0; i--) {
for (int j = 0; j < W; j++) if (a[i][j]) {
dp2[i][j] = i + 1 == H ? 1 : dp2[i + 1][j] + 1;
}
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) if (a[i][j]) {
dp3[i][j] = i == 0 || j == 0 ? 1 : dp3[i - 1][j - 1] + 1;
}
}
int res = 1;
for (int i = 0; i < W; i++) {
vector<vector<int>> ad(H + 1);
for (int j = 0; i + j < W && j < H; j++) {
int x = j, y = i + j;
if (!a[x][y]) continue;
int v = min(dp1[x][y], dp3[x][y]);
assert(0 <= j + 1 - v);
ad[j + 1 - v].push_back(j + 1);
}
set<int> st;
for (int j = 0; i + j < W && j < H; j++) {
if (st.count(j)) st.erase(j);
for (auto v : ad[j]) {
st.insert(v);
}
int x = j, y = i + j;
if (!a[x][y]) {
st.clear();
continue;
}
int v = dp2[x][y];
auto it = st.upper_bound(j + v);
if (it == st.begin()) continue;
res = max(res, *prev(it) - j);
}
}
for (int i = 1; i < H; i++) {
vector<vector<int>> ad(W + 1);
for (int j = 0; i + j < H && j < W; j++) {
int x = i + j, y = j;
if (!a[x][y]) continue;
int v = min(dp1[x][y], dp3[x][y]);
assert(0 <= j + 1 - v);
ad[j + 1 - v].push_back(j + 1);
}
set<int> st;
for (int j = 0; i + j < H && j < W; j++) {
if (st.count(j)) st.erase(j);
for (auto v : ad[j]) {
st.insert(v);
}
int x = i + j, y = j;
if (!a[x][y]) {
st.clear();
continue;
}
int v = dp2[x][y];
auto it = st.upper_bound(j + v);
if (it == st.begin()) continue;
res = max(res, *prev(it) - j);
}
}
cout << res << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Largest N |
| User | kazuma |
| Language | C++14 (GCC 5.4.1) |
| Score | 600 |
| Code Size | 3096 Byte |
| Status | AC |
| Exec Time | 3119 ms |
| Memory | 143560 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt, s4.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt, s3.txt, s4.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 3 ms | 384 KiB |
| 02.txt | AC | 5 ms | 384 KiB |
| 03.txt | AC | 1 ms | 256 KiB |
| 04.txt | AC | 3 ms | 384 KiB |
| 05.txt | AC | 4 ms | 384 KiB |
| 06.txt | AC | 3 ms | 384 KiB |
| 07.txt | AC | 1 ms | 256 KiB |
| 08.txt | AC | 2 ms | 256 KiB |
| 09.txt | AC | 2 ms | 256 KiB |
| 10.txt | AC | 3 ms | 384 KiB |
| 11.txt | AC | 9 ms | 768 KiB |
| 12.txt | AC | 1 ms | 256 KiB |
| 13.txt | AC | 3 ms | 384 KiB |
| 14.txt | AC | 2 ms | 384 KiB |
| 15.txt | AC | 9 ms | 1024 KiB |
| 16.txt | AC | 34 ms | 1536 KiB |
| 17.txt | AC | 33 ms | 1536 KiB |
| 18.txt | AC | 31 ms | 1408 KiB |
| 19.txt | AC | 3005 ms | 141604 KiB |
| 20.txt | AC | 2588 ms | 143560 KiB |
| 21.txt | AC | 2781 ms | 141616 KiB |
| 22.txt | AC | 3119 ms | 141528 KiB |
| 23.txt | AC | 3027 ms | 143468 KiB |
| 24.txt | AC | 2696 ms | 141616 KiB |
| 25.txt | AC | 6 ms | 256 KiB |
| 26.txt | AC | 2736 ms | 136320 KiB |
| 27.txt | AC | 2742 ms | 135936 KiB |
| 28.txt | AC | 61 ms | 4224 KiB |
| 29.txt | AC | 19 ms | 1664 KiB |
| 30.txt | AC | 12 ms | 1920 KiB |
| 31.txt | AC | 32 ms | 2816 KiB |
| 32.txt | AC | 2966 ms | 136996 KiB |
| 33.txt | AC | 2877 ms | 136400 KiB |
| 34.txt | AC | 2993 ms | 137368 KiB |
| 35.txt | AC | 2949 ms | 136212 KiB |
| 36.txt | AC | 2550 ms | 138244 KiB |
| 37.txt | AC | 2684 ms | 136288 KiB |
| 38.txt | AC | 2596 ms | 136292 KiB |
| 39.txt | AC | 2638 ms | 138252 KiB |
| 40.txt | AC | 2589 ms | 136288 KiB |
| s1.txt | AC | 1 ms | 256 KiB |
| s2.txt | AC | 1 ms | 256 KiB |
| s3.txt | AC | 1 ms | 256 KiB |
| s4.txt | AC | 1 ms | 256 KiB |