0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00

P2254 [NOI2005] 瑰丽华尔兹

https://www.luogu.com.cn/record/77598294
This commit is contained in:
Baoshuo Ren 2022-06-19 11:41:41 +08:00
parent c1e854a2f1
commit 574de078bc
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 168 additions and 0 deletions

108
Luogu/P2254/P2254.cpp Normal file
View File

@ -0,0 +1,108 @@
#include <iostream>
#include <deque>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 205;
int n, m, x, y, k, s, t, d, f[N][N], ans;
bool g[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> x >> y >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
g[i][j] = c == 'x';
f[i][j] = -0x3f3f3f3f;
}
}
f[x][y] = 0;
for (int i = 1; i <= k; i++) {
cin >> s >> t >> d;
int len = t - s + 1;
switch (d) {
case 1: { // 上
for (int y = 1; y <= m; y++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, x = n; x; j++, x--) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 2: { // 下
for (int y = 1; y <= m; y++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, x = 1; x <= n; j++, x++) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 3: { // 左
for (int x = 1; x <= n; x++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, y = m; y; j++, y--) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 4: { // 右
for (int x = 1; x <= n; x++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, y = 1; y <= m; j++, y++) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
}
}
cout << ans << endl;
return 0;
}

BIN
Luogu/P2254/data/P2254_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2254/data/P2254_9.out (Stored with Git LFS) Normal file

Binary file not shown.