QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#879607 | #5414. Stop, Yesterday Please No More | jzhong0821 | WA | 2ms | 3712kb | C++14 | 2.8kb | 2025-02-02 07:45:52 | 2025-02-02 07:45:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int n, m, k;
cin >> n >> m >> k;
string s;
cin >> s;
int l = s.size();
vector<int> dx(l + 1, 0);
vector<int> dy(l + 1, 0);
for (int i = 1; i <= l; ++i) {
dx[i] = dx[i - 1];
dy[i] = dy[i - 1];
char c = s[i - 1];
if (c == 'U') dx[i]--;
else if (c == 'D') dx[i]++;
else if (c == 'L') dy[i]--;
else dy[i]++;
}
int min_dx = *min_element(dx.begin(), dx.end());
int max_dx = *max_element(dx.begin(), dx.end());
int min_dy = *min_element(dy.begin(), dy.end());
int max_dy = *max_element(dy.begin(), dy.end());
int x_min = 1 - min_dx;
int x_max = n - max_dx;
int y_min = 1 - min_dy;
int y_max = m - max_dy;
int valid_count = 0;
if (x_min <= x_max && y_min <= y_max) {
valid_count = (x_max - x_min + 1) * (y_max - y_min + 1);
} else {
valid_count = 0;
}
if (valid_count == 0) {
cout << (k == 0 ? n * m : 0) << "\n";
continue;
}
vector<vector<int>> diff(n + 2, vector<int>(m + 2, 0));
for (int t = 0; t <= l; ++t) {
int dx_t = dx[t];
int dy_t = dy[t];
int min_x = x_min + dx_t;
int max_x = x_max + dx_t;
int min_y = y_min + dy_t;
int max_y = y_max + dy_t;
if (min_x < 1 || max_x > n || min_y < 1 || max_y > m)
continue;
diff[min_x][min_y]++;
if (max_y + 1 <= m)
diff[min_x][max_y + 1]--;
if (max_x + 1 <= n)
diff[max_x + 1][min_y]--;
if (max_x + 1 <= n && max_y + 1 <= m)
diff[max_x + 1][max_y + 1]++;
}
for (int i = 1; i <= n; ++i) {
int current = 0;
for (int j = 1; j <= m; ++j) {
current += diff[i][j];
diff[i][j] = current;
}
}
for (int j = 1; j <= m; ++j) {
int current = 0;
for (int i = 1; i <= n; ++i) {
current += diff[i][j];
diff[i][j] = current;
}
}
int required = valid_count - k;
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (diff[i][j] == required) {
ans++;
}
}
}
cout << ans << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 2ms
memory: 3712kb
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 17 9 18 15 21 240 14 0 0 5 1 18 3 16 1 31 108 8 1 2 3 7 0 29 4 20 0 8 10 9 6 5 320 3 5 3 0 0 7 0 11 0 0 8 128 22 18 51 23 5 6 3 9 48 28 8 1 22 49 13 10 2 12 6 18 44 0 14 5 0 4 30 14 99 105 2 27 17 0 66 10 11 28 52 32 8 22 14 0 90 15 0 22 3 48 29 20 9 0 30 6 8 3 10 16 45 16 17 0 20 0 21 0 6 0 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '17'