QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267515 | #5414. Stop, Yesterday Please No More | jrjyy# | WA | 5ms | 3764kb | C++20 | 1.5kb | 2023-11-27 13:43:00 | 2023-11-27 13:43:00 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, m, k;
std::cin >> n >> m >> k;
std::string s;
std::cin >> s;
int x = 0, y = 0, u = 0, d = n, l = 0, r = m;
std::vector<std::vector<int>> a(2 * n + 1, std::vector<int>(2 * m + 1));
a[x + n][y + m] = 1;
for (auto c : s) {
if (c == 'U') {
x += 1;
} else if (c == 'D') {
x -= 1;
} else if (c == 'L') {
y += 1;
} else if (c == 'R') {
y -= 1;
}
u = std::max(u, x);
d = std::min(d, n + x);
l = std::max(l, y);
r = std::min(r, m + y);
if (u >= d || l >= r) {
std::cout << (k == 0 ? n * m : 0) << "\n";
return;
}
a[x + n][y + m] = 1;
}
for (int i = 2 * n - 1; i >= 0; --i) {
for (int j = 2 * m - 1; j >= 0; --j) {
a[i][j] += a[i][j + 1] + a[i + 1][j] - a[i + 1][j + 1];
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int nu = u - i + n, nd = d - i + n, nl = l - j + m, nr = r - j + m;
if (a[nu][nl] - a[nu][nr] - a[nd][nl] + a[nd][nr] == k) {
++ans;
}
}
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3468kb
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: 5ms
memory: 3764kb
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 0 0 0 15 0 240 0 0 0 0 0 18 0 0 0 0 0 0 2 2 3 0 0 0 0 0 0 0 0 9 9 0 320 0 0 3 0 0 0 0 0 0 0 0 0 22 0 51 0 10 6 0 0 48 28 8 0 0 0 0 0 0 0 0 0 44 0 0 0 0 4 30 0 0 105 0 0 17 0 66 0 11 28 0 0 0 0 0 0 90 0 0 0 6 48 0 0 0 0 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 225 0 0 0 0 11 0 90 0 0 228 0 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '0'