QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401346 | #5414. Stop, Yesterday Please No More | Credit | RE | 0ms | 3596kb | C++17 | 2.7kb | 2024-04-28 15:35:11 | 2024-04-28 15:35:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
ll n, m, k;
string line;
ll g[2005][2005];
void solve()
{
cin >> n >> m >> k >> line;
ll sx = 0, sy = 0, L = 0, R = 0, U = 0, D = 0, high, wide, sum = 0;
for (int i = 0;i < line.length();i++) {
if (line[i] == 'U') {
sy -= 1;
}
if (line[i] == 'D') {
sy += 1;
}
if (line[i] == 'L') {
sx -= 1;
}
if (line[i] == 'R') {
sx += 1;
}
L = min(L, sx);
R = max(R, sx);
U = max(U, sy);
D = min(D, sy);
}
if (R - L >= m||U - D >= n) {
if (k == 0) {
cout << n * m << '\n';
return;
}
else {
cout << 0 << '\n';
return;
}
}
high = n - U + D;
wide = m - R + L;
int x = -L+1;
int y = -D+1;
g[x][y] = 1;
for (int i = 0;i < line.length();i++) {
if (line[i] == 'U') {
y += 1;
g[x][y] = 1;
}
if (line[i] == 'D') {
y -= 1;
g[x][y] = 1;
}
if (line[i] == 'L') {
x += 1;
g[x][y] = 1;
}
if (line[i] == 'R') {
x -= 1;
g[x][y] = 1;
}
}
for (int i = 1;i < n;i++) {
for (int j = 1;j < m;j++) {
g[j][i] = g[j - 1][i] + g[j][i - 1] - g[j - 1][i - 1]+g[j][i];
}
}
for (int i = 1;i < n;i++) {
for (int j = 1;j < m;j++) {
if (j > wide && i > high) {
if (k == high*wide-(g[j][i] - g[j - wide][i] - g[j][i - high] + g[j - wide][i - high])) {
sum++;
}
}
else if (i > high) {
if (k == high * wide - (g[j][i] - g[j][i - high])) {
sum++;
}
}
else if (j > wide) {
if (k == high * wide - (g[j][i] - g[j - wide][i])) {
sum++;
}
}
else {
if (k == high * wide - g[j][i]) {
sum++;
}
}
}
}
cout << sum << '\n';
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) {
// cout << g[j][i] << ' ';
g[j][i] = 0;
}
// cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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...