QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659548 | #5414. Stop, Yesterday Please No More | Zlin05 | WA | 5ms | 5856kb | C++23 | 2.7kb | 2024-10-19 20:38:06 | 2024-10-19 20:38:10 |
Judging History
answer
//
// Created by Zlin on 2024/10/19.
//
#include "bits/stdc++.h"
using namespace std;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int dif = 1005;
int n, m, k, lx, rx, ly, ry;
int sum[3020][3020];
inline void Zlin() {
cin >> n >> m >> k;
string s;
cin >> s;
int x = 0, y = 0;
lx = ly = 1, rx = m, ry = n;
for (auto it: s) {
if (it == 'U') {
y++;
ry = min(ry, n - y);
} else if (it == 'D') {
y--;
ly = max(ly, 1 - y);
} else if (it == 'L') {
x--;
lx = max(lx, 1 - x);
} else {
x++;
rx = min(rx, m - x);
}
}
// cout << lx << ' ' << rx << ' ' << ly << ' ' << ry << '\n';
x = 0, y = 0;
sum[dif][dif] = 1;
for (auto it: s) {
if (it == 'U') {
y--;
} else if (it == 'D') {
y++;
} else if (it == 'L') {
x++;
} else {
x--;
}
if (x < -m || x > m || y < -n || y > n) continue;
sum[x + dif][y + dif] = 1;
}
for (int i = dif - m; i <= dif + m; i++)
for (int j = dif - n; j <= dif + n; j++)
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
int ans = 0, now;
if (lx > rx || ly > ry) {
now = -k;
} else {
now = 1ll * (rx - lx + 1) * (ry - ly + 1) - k;
}
if (now == 0) {
ans = n * m;
} else if (now < 0) {
ans = 0;
} else {
for (int y = 1; y <= n; y++) {
for (int x = 1, ax, ay, bx, by, check; x <= m; x++) {
ax = rx - x + dif, ay = ry - y + dif;
bx = lx - x - 1 + dif, by = ly - y - 1 + dif;
ax = min(ax, dif + m), ay = min(ay, dif + n);
bx = max(bx, dif - m), by = max(by, dif - n);
check = sum[ax][ay] - sum[ax][by] - sum[bx][ay] + sum[bx][by];
if (check == now) ++ans;
}
}
}
// for (int i = dif - m; i <= dif + m; i++) {
// for (int j = dif - n; j <= dif + n; j++) {
// cout << sum[i][j] << ' ';
// }
// cout << '\n';
// }
// cout << now << ' ';
cout << ans << '\n';
for (int i = dif - n; i <= dif + n; i++)
for (int j = dif - m; j <= dif + m; j++)
sum[i][j] = 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int ttt = 1;
cin >> ttt;
while (ttt--) Zlin();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5856kb
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: 5748kb
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 20 40 18 15 6 240 15 0 0 7 11 18 1 16 42 9 84 8 2 2 3 121 8 8 16 21 0 8 5 9 13 5 320 11 7 3 2 0 12 0 4 0 0 14 0 22 4 51 11 7 6 2 1 48 28 8 2 22 22 9 8 4 28 10 16 44 0 6 4 0 4 30 13 19 105 10 8 17 0 66 10 11 28 35 34 56 33 7 49 90 5 0 121 3 48 16 18 10 0 30 6 8 1 11 16 18 18 17 0 38 0 18 0 72 ...
result:
wrong answer 4th numbers differ - expected: '99', found: '40'