QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#674237 | #5414. Stop, Yesterday Please No More | yumingsk# | WA | 2ms | 7684kb | C++20 | 2.6kb | 2024-10-25 14:41:39 | 2024-10-25 14:41:41 |
Judging History
answer
#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";
using namespace std;
const int N = 1011;
const int Mod = 998244353;
using ll = long long;
ll n, m, k, a[N][N], q, qzh[N][N], len, sum;
ll xx, x, yy, y, lx, ly;
ll rn, cn, rmax, rmin, cmax, cmin;
string S;
void solve()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = 0;
cin >> S;
len = S.size();
rmax = rmin = cmax = cmin = rn = cn = 0;
for (int i = 0; i < len; i++)
{
if (S[i] == 'U')
{
rn--;
if (rn < rmin)
rmin = rn;
}
if (S[i] == 'D')
{
rn++;
if (rn > rmax)
rmax = rn;
}
if (S[i] == 'L')
{
cn--;
if (cn < cmin)
cmin = cn;
}
if (S[i] == 'R')
{
cn++;
if (cn > cmax)
cmax = cn;
}
}
xx = 1 - rmin;
yy = 1 - cmin;
lx = n + rmin - rmax;
ly = m + cmin - cmax;
if (lx <= 0 || ly <= 0)
{
if (k > 0)
cout << "0\n";
else
cout << n * m << '\n';
return;
}
k = lx * ly - k;
if (k < 0)
{
cout << "0\n";
return;
}
x = xx;
y = yy;
a[x][y] = 1;
for (int i = 0; i < len; i++)
{
if (S[i] == 'U')
x--;
if (S[i] == 'D')
x++;
if (S[i] == 'L')
y--;
if (S[i] == 'R')
y++;
a[x][y] = 1;
}
for (int i = 1; i <= n; i++)
{
q = 0;
for (int j = 1; j <= m; j++)
{
q += a[i][j];
qzh[i][j] = qzh[i - 1][j] + q;
}
}
sum = 0;
for (int i = lx; i <= n; i++)
for (int j = ly; j <= m; j++)
if (qzh[i][j] - qzh[i - lx][j] - qzh[i][j - ly] + qzh[i - lx][j - ly] == k)
sum++;
cout << sum << '\n';
}
int main()
{
IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
clock_t start_time = clock();
#endif
int t = 1;
cin >> t;
while (t--)
{
solve();
}
#ifndef ONLINE_JUDGE
cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7684kb
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: 6116kb
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 2 1 3 15 1 240 5 0 0 2 2 18 1 2 0 2 1 1 1 1 1 0 0 1 2 3 0 2 2 9 14 1 320 1 2 1 0 0 2 0 1 0 0 2 0 22 1 51 3 7 6 1 0 48 28 8 1 2 1 1 2 1 1 1 2 44 0 2 0 0 4 30 0 1 105 4 1 17 0 66 3 11 28 1 3 1 3 3 1 90 1 0 1 1 48 8 3 2 0 30 1 1 1 1 1 1 2 2 0 2 0 1 0 1 0 1 2 48 1 0 225 1 1 1 2 11 2 90 2 2 228 1 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '2'