QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879893 | #5414. Stop, Yesterday Please No More | The_8th_Horcrux | WA | 334ms | 12520kb | C++23 | 1.9kb | 2025-02-02 17:14:29 | 2025-02-02 17:14:30 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define int long long
using namespace std;
constexpr int N = 1005;
string op;
int n, m, k;
int U, D, L, R, U_, D_, L_, R_;
bool st[N][N];
int g[N][N];
void add(int x1, int y1, int x2, int y2){
if (st[x1][y1])
return;
st[x1][y1] = true;
g[x1][y1]++, g[x2 + 1][y1]--, g[x1][y2 + 1]--, g[x2 + 1][y2 + 1]++;
}
void solve() {
cin >> n >> m >> k >> op;
U_ = L_ = U = L = 1, R_ = R = m, D_ = D = n;
memset(st, false, sizeof st), memset(g, 0, sizeof g);
//确定边界
for (auto i: op){
if (i == 'L')
L_++, R_++;
else if (i == 'R')
L_--, R_--;
else if (i == 'U')
U_++, D_++;
else
U_--, D_--;
L = max(L, L_), R = min(R, R_), U = max(U, U_), D = min(D, D_);
}
//无袋鼠剩余情况
if (U > D || L > R){
if (k)
puts("0");
else
cout << n * m << endl;
return;
}
//统计袋鼠经过格子的情况
int x = (D - U + 1) * (R - L + 1), cnt = 0;
add(U, L, D, R);
for (auto i: op){
if (i == 'L')
L--, R--;
else if (i == 'R')
L++, R++;
else if (i == 'U')
U--, D--;
else
U++, D++;
add(U, L, D, R);
}
//二位前缀和+统计答案
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
if (x - g[i][j] == k)
cnt++;
cout << cnt << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int _;
cin >> _;
while (_ --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 12500kb
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: 334ms
memory: 12520kb
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 18 15 34 240 15 0 0 13 14 18 26 16 1 19 108 8 2 2 3 7 0 30 16 21 0 8 10 9 15 5 320 11 7 3 0 0 12 0 11 0 0 14 0 22 36 51 23 7 6 4 2 48 28 8 63 22 49 13 10 4 108 10 18 44 15 9 0 4 30 14 99 105 10 14 17 0 66 10 11 28 52 34 56 33 14 56 90 14 0 121 3 48 30 36 13 0 30 7 8 3 11 16 45 20 34 0 3...
result:
wrong answer 69th numbers differ - expected: '0', found: '15'