QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704879 | #5414. Stop, Yesterday Please No More | RWeakest | WA | 6ms | 13948kb | C++17 | 2.2kb | 2024-11-02 21:23:08 | 2024-11-02 21:23:08 |
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: 100
Accepted
time: 1ms
memory: 9760kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
2 20 0
result:
ok 3 number(s): "2 20 0"
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 13948kb
input:
1060 19 12 0 UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL 11 1 0 UR 3 18 33 UDRLR 17 11 132 RLDRDLDRUU 6 10 13 UULUDDLRDLUUDLDD 1 15 0 D 6 20 50 D...
output:
228 11 1 99 5 15 16 240 6 0 0 1 11 18 13 0 12 16 108 4 1 1 3 48 1 1 3 4 0 7 10 9 4 5 320 8 5 3 0 0 3 0 11 0 0 6 0 22 36 51 12 5 6 1 2 48 28 8 63 11 49 13 4 2 108 7 9 44 0 1 8 0 4 30 12 99 105 5 1 17 0 66 8 11 28 52 15 56 11 5 56 90 14 0 121 3 48 1 16 10 0 30 1 3 3 7 16 45 9 32 0 19 0 4 0 39 0 20 12 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '1'