目录
The 2022 ICPC Asia Nanjing Regional Contest
Stop, Yesterday Please No More
//>>>Qiansui
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x, y, sizeof(x))
#define debug(x) cout << #x << " = " << x << '\n'
#define debug2(x,y) cout << #x << " = " << x << " " << #y << " = "<< y << '\n'
//#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
/*
*/
const int N = 2e3 + 10, inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
void solve(){
int n, m, k;
string ss;
cin >> n >> m >> k >> ss;
int sx = n, sy = m;
int x = n, y = m, f[4] = {sx, sx, sy, sy};
vector p(n * 2 + 10, vector<int>(m * 2 + 10, 0));
p[n][m] = 1;
for(auto ch : ss){
if(ch == 'U'){
++ x;
}else if(ch == 'D'){
-- x;
}else if(ch == 'L'){
++ y;
}else{
-- y;
}
if(x >= 1 && y >= 1 && x <= n * 2 - 1 && y <= m * 2 - 1){
p[x][y] = 1;
}
if(x > sx) f[0] = max(f[0], x);// d
else f[1] = min(f[1], x);// u
if(y > sy) f[2] = max(f[2], y);// r
else f[3] = min(f[3], y);// l
}
int up = f[0] - sx, down = sx - f[1], right = sy - f[3], left = f[2] - sy;
int a = max(0, n - up - down), b = max(0, m - left - right);
int ans = 0;
if(a * b == 0){
if(k == 0) ans = n * m;
}else if(a * b >= k){
int sti = 1 + up, stj = 1 + left;
for(int i = 1; i < n * 2; ++ i){
for(int j = 1; j < m * 2; ++ j){
p[i][j] += p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
}
}
for(int i = sti; i < sti + n; ++ i){
for(int j = stj; j < stj + m; ++ j){
if(p[i + a - 1][j + b - 1] - p[i + a - 1][j - 1]
- p[i - 1][j + b - 1] + p[i - 1][j - 1] == a * b - k)
++ ans;
}
}
}
cout << ans << '\n';
return ;
}
signed main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}
标签:sy,sx,int,南京,else,++,ch,2022ICPC
From: https://www.cnblogs.com/Qiansui/p/17861589.html