QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879864 | #5414. Stop, Yesterday Please No More | Horcrux# | RE | 2ms | 12528kb | C++23 | 1.9kb | 2025-02-02 16:57:20 | 2025-02-02 16:57:21 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int MAXN = 1005;
string op;
int n, m, k;
int U, D, L, R;
int U0, D0, L0, R0;
bool st[MAXN][MAXN];
int g[MAXN][MAXN];
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;
U0 = L0 = U = L = 1;
R0 = R = m, D0 = D = n;
memset(st, 0, sizeof(st));
memset(g, 0, sizeof(g));
for(char c : op) {
if(c == 'L') {
L0++, R0++;
} else if(c == 'R') {
L0--, R0--;
} else if(c == 'U') {
U0++, D0++;
} else {
U0--, D0--;
}
L = max(L, L0);
R = min(R, R0);
U = max(U, U0);
D = min(D, D0);
}
if(U > D || L >> R) {
if(k) {
cout << 0 << '\n';
} else {
cout << n * m << '\n';
}
return ;
}
int x = (D - U + 1) * (R - L + 1);
int ans = 0;
add(U, L, D, R);
for(char c : op) {
if(c == 'L') {
L++, R++;
} else if(c == 'R') {
L--, R--;
} else if(c == '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++) {
ans += (x - g[i][j] == k);
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12528kb
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
Runtime Error
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...