QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216631 | #5414. Stop, Yesterday Please No More | dd | WA | 6ms | 8144kb | C++20 | 2.1kb | 2023-10-15 20:40:02 | 2023-10-15 20:40:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10, M = 2e3 + 10;
int n, m, k;
set<pair<int, int> > a;
char st[N];
int sum[M][M];
int main() {
int T; scanf("%d", &T);
while (T--) {
a.clear();
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j)
sum[i][j] = 0;
scanf("%s", st + 1);
int U = 0, D = 0, L = 0, R = 0, x = 0, y = 0;
int len = strlen(st + 1);
for (int i = 1; i <= len; ++i) {
if (st[i] == 'D')
++x;
if (st[i] == 'U')
--x;
if (st[i] == 'L')
--y;
if (st[i] == 'R')
++y;
a.insert(make_pair(-x, -y));
U = max(U, -x);
D = max(D, x);
L = max(L, -y);
R = max(R, y);
}
// cout << U << ' ' << D <<' ' <<L << ' ' << R << endl;
if (U + D >= n || L + R >= m) {
if (k == 0)
printf("%d\n", n * m);
else
printf("0\n");
continue;
}
// cout << U << ' ' << D << ' ' << L << ' ' << R << endl;
++sum[U + 1][L + 1];
--sum[n - D + 1][L + 1];
--sum[U + 1][m - R + 1];
++sum[n - D + 1][m - R + 1];
for (set<pair<int,int> >::iterator it = a.begin(); it != a.end(); it++) {
int xx1 = U + 1 - it->first, yy1 = L + 1 - it->second;
int xx2 = n - D - it->first, yy2 = m - R - it->second;
xx1 = max(xx1, 1);
yy1 = max(yy1, 1);
xx2 = min(xx2, n);
yy2 = min(yy2, m);
if (xx1 > n || yy1 > m || xx2 < 1 || yy2 < 1)
continue;
// cout << it->first <<' ' <<it->second << endl;
// cout << xx1 << ' ' << yy1 <<' ' << xx2 << ' ' << yy2 << endl;
++sum[xx1][yy1];
--sum[xx2 + 1][yy1];
--sum[xx1][yy2 + 1];
++sum[xx2 + 1][yy2 + 1];
}
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
if ((n - U - D) * (m - L - R) - sum[i][j] == k)
++ans;
}
/* for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j)
cout << (n - U - D) * (m - L - R) - sum[i][j] << ' ';
cout << endl;
}*/
printf("%d\n", ans);
}
return 0;
}
/*
2
4 5 15
U
4 5 14
U
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5848kb
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: 8144kb
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 19 0 18 15 34 240 15 0 0 13 14 18 26 16 1 19 108 8 1 2 3 7 0 29 14 21 0 8 1 9 13 5 320 3 7 3 0 0 12 0 11 0 0 14 0 22 36 51 23 5 6 3 11 48 28 8 7 22 49 13 10 2 0 4 18 44 0 14 9 0 4 30 14 99 105 5 14 17 0 66 10 11 28 52 34 8 33 14 0 90 0 0 11 3 48 30 36 12 0 30 7 8 3 11 16 45 20 34 0 20 0 21 0 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '19'