QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#405515 | #5414. Stop, Yesterday Please No More | FOY# | WA | 3ms | 3944kb | C++17 | 2.0kb | 2024-05-06 03:16:02 | 2024-05-06 03:16:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void rect_pref(vector<vector<ll>> &grid, ll top, ll bottom, ll left, ll right) {
grid[bottom][left] = 1;
grid[bottom][right + 1] = -1;
grid[top + 1][left] = -1;
grid[top + 1][right + 1] = 1;
}
void solve() {
ll rows, cols, k;
cin >> rows >> cols >> k;
string s;
cin >> s;
ll TOP = rows, BOTTOM = 1, LEFT = 1, RIGHT = cols;
ll top = rows, bottom = 1, left = 1, right = cols;
for (char c : s) {
if (c == 'U') {
top--; bottom--;
}
else if (c == 'D') {
top++;
bottom++;
}
else if (c == 'L') {
left++;
right++;
}
else {
left--;
right--;
}
TOP = min(TOP, top);
BOTTOM = max(BOTTOM, bottom);
LEFT = max(LEFT, left);
RIGHT = min(RIGHT, right);
}
// cout << TOP << " " << BOTTOM << " " << LEFT << " " << RIGHT << endl;
if (TOP < BOTTOM || LEFT > RIGHT) {
if (k == 0) {
cout << rows * cols << endl;
return;
}
cout << 0 << endl;
return;
}
ll target = (TOP - BOTTOM + 1) * (RIGHT - LEFT + 1) - k;
vector<vector<ll>> ps(rows + 2, vector<ll>(cols + 2));
vector<vector<bool>> visited(rows + 2, vector<bool>(cols + 2));
rect_pref(ps, TOP, BOTTOM, LEFT, RIGHT);
visited[BOTTOM][LEFT] = true;
for (char c : s) {
ll v = 0, h = 0;
if (c == 'U') v = 1;
else if (c == 'D') v = -1;
else if (c == 'L') h = -1;
else h = 1;
TOP += v; BOTTOM += v;
LEFT += h; RIGHT += h;
if (!visited[BOTTOM][LEFT]) {
rect_pref(ps, TOP, BOTTOM, LEFT, RIGHT);
visited[BOTTOM][LEFT] = true;
}
}
for (ll i = 1; i <= rows; i++) {
for (ll j = 1; j <= cols; j++) {
ps[i][j] = ps[i][j-1] + ps[i][j];
}
}
ll cnt = 0;
for (ll j = 1; j <= cols; j++) {
for (ll i = 1; i <= rows; i++) {
ps[i][j] = ps[i-1][j] + ps[i][j];
if (ps[i][j] == target) cnt++;
}
}
cout << cnt << endl;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll t;
cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
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: 3ms
memory: 3944kb
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 99 13 15 19 240 10 0 0 13 14 18 26 2 1 6 108 8 2 2 0 7 0 30 16 21 0 8 10 9 17 5 320 11 6 3 0 0 11 0 11 0 0 14 0 22 36 51 23 3 6 4 2 48 28 8 63 11 49 27 10 4 108 10 9 44 0 15 9 0 4 30 14 99 105 10 15 17 0 66 2 11 28 52 18 56 11 14 56 90 14 0 121 3 48 4 36 13 0 30 7 8 5 11 16 45 20 34 0 38 0...
result:
wrong answer 5th numbers differ - expected: '18', found: '13'