QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511035 | #5414. Stop, Yesterday Please No More | potential | WA | 6ms | 6532kb | C++20 | 3.7kb | 2024-08-09 15:29:45 | 2024-08-09 15:29:45 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
# define int long long
# define lowbit(x) (x & (-x))
# define fi first
# define se second
// # define endl '\n'
inline int Read();
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 1e6 + 10;
map <PII, int> mp;
vector <int> v;
string a;
int b[2010][2010];
void Solve(){
mp.clear();
int n, m, k;
cin >> n >> m >> k >> a;
for(int i = 1; i <= n * 2; i ++){
for(int j = 1; j <= m *2 ; j ++){
b[i][j] = 0;
}
}
int u = 1, d = n, l = 1, r = m;
int x = 1, y = 1;
int hx = 0, hy = 0;
mp[{1, 1}] = 1;
for(int i = 0; i < a.size(); i ++){
if(a[i] == 'U'){
u --; d --; x ++;
// if(x < 1) x = 1;
if(u < 1) u = 1;
if(d < 1){
if(k == 0) cout << n * m <<"\n";
else cout << 0 <<"\n";
return;
}
}
if(a[i] == 'D'){
u ++; d ++; x --;
// if(x > n) x = n;
if(d > n) d = n;
if(u > n){
if(k == 0) cout << n * m <<"\n";
else cout << 0 <<"\n";
return;
}
}
if(a[i] == 'L'){
l --; r --; y ++;
// if(y > m) y = m;
if(l < 1) l = 1;
if(r < 1){
if(k == 0) cout << n * m <<"\n";
else cout << 0 <<"\n";
return;
}
}
if(a[i] == 'R'){
l ++; r ++; y --;
// if(y < 1) y = 1;
if(r > m) r = m;
if(l > m){
if(k == 0) cout << n * m <<"\n";
else cout << 0 <<"\n";
return;
}
}
mp[{x, y}] = 1;
// cout << x <<" " << y <<"*\n";
}
int xx = 0, yy = 0;
for(auto i : mp){
xx = i.fi.fi;
yy = i.fi.se;
break;
}
// cout << xx <<" " << yy <<'\n';
int tx = 1 - xx, ty = 1 - yy;
int sx = 1 + tx, sy = 1 + ty;
// cout << x <<" " << y <<"\n";
for(auto i : mp){
x = i.fi.fi;
y = i.fi.se;
b[x + tx][y + ty] ++;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
// cout << b[i][j] <<" \n"[j == m];
}
}
int ans = 0;
// cout << u <<" " << d <<" " << l <<' ' << r <<"\n";
// cout << sx <<" " << sy <<"\n";
for(int i = (int)a.size() - 1; i >= 0; i --){
if(a[i] == 'U') u ++, d ++;
if(a[i] == 'D') u --, d --;
if(a[i] == 'L') l ++, r ++;
if(a[i] == 'R') l --, r --;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
int px, py;
px = sx - (i + tx), py = sy - (j + ty);
if(b[d + tx + px][r + ty + py] - b[d + tx + px][max(l - 1 + ty + py, 0ll)] - b[max(u - 1 + tx + px, 0ll)][r + ty + py] + b[max(u - 1 + tx + px, 0ll)][max(l - 1 + ty + py, 0ll)] == (d - u + 1) * (r - l + 1) - k) {
ans ++;
// cout << i <<" " << j <<" " << ans <<"\n";
}
}
}
cout << ans << '\n';
}
signed main(){
IOS;
int T = 1;
cin >> T;
while (T--)
Solve();
return 0;
}
inline int Read(){
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 6ms
memory: 6532kb
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 15 15 34 240 15 0 0 13 20 18 13 0 1 19 108 8 2 2 3 7 0 30 16 21 0 8 0 9 15 5 320 11 10 3 0 0 2 0 11 0 0 14 0 22 0 51 24 6 6 4 0 48 28 8 63 22 49 13 10 4 108 10 18 44 0 15 0 0 4 30 36 99 105 10 0 17 0 66 10 11 28 52 60 56 33 14 56 90 14 0 121 3 48 27 36 11 0 30 7 8 3 9 16 45 20 34 0 38 0...
result:
wrong answer 5th numbers differ - expected: '18', found: '15'