QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704859 | #7733. Cool, It’s Yesterday Four Times More | RWeakest | WA | 0ms | 7808kb | C++17 | 2.2kb | 2024-11-02 21:18:27 | 2024-11-02 21:18:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e3 + 10;
const int ind = 1.5e3;
ll T, n, m, k, a[N];
string str;
int vis[N][N];
ll sum[N][N];
void solve() {
cin >> n >> m >> k;
cin >> str;
for (int i = -n - 1 + ind; i <= n + 1 + ind; i++) {
for (int j = -m - 1 + ind; j <= m + 1 + ind; j++) {
sum[i][j] = 0;
vis[i][j] = 0;
}
}
ll u = n, d = 0, l = m, r = 0;
ll ut = n, dt = 0, lt = m, rt = 0;
int holex = ind, holey = ind;
vis[holex][holey] = 1;
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'U') ut--, dt--, holex++;
if (str[i] == 'D') ut++, dt++, holex--;
if (str[i] == 'L') lt--, rt--, holey++;
if (str[i] == 'R') lt++, rt++, holey--;
vis[holex][holey] = 1;
u = min(u, ut), l = min(l, lt);
d = max(d, dt), r = max(r, rt);
if (d >= u || r >= l) break;
}
ll res = (u - d) * (l - r);
if (res < k) {
cout << "0\n";
return;
}
if (res <= 0) {
if (k == 0) cout << m * n << "\n";
else cout << "0\n";
return;
}
ll dis = res - k, ans = 0;
//printf("dis:%lld\n", dis);
ll lx = max(0ll, u - d), ly = max(0ll, l - r), dx = n - u, dy = m - l;
for (int i = -n - 1 + ind; i <= n + 1 + ind; i++) {
for (int j = -m - 1 + ind; j <= m + 1 + ind; j++) {
// printf("%d ", vis[i][j]);
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + vis[i][j];
}
// printf("\n");
}
for (int i = 0 + ind; i < n + ind; i++) {
for (int j = 0 + ind; j < m + ind; j++) {
ll cut = sum[i - dx][j - dy] - sum[i - dx - lx][j - dy] - sum[i - dx][j - dy - ly] +
sum[i - dx - lx][j - dy - ly];
// printf("x:%d y:%d cut:%lld\n", i, j, cut);
if (cut == dis) ans++;
}
}
cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7808kb
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO
output:
0 0 0 0
result:
wrong answer 1st lines differ - expected: '3', found: '0'