QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632181 | #5414. Stop, Yesterday Please No More | CSQ# | RE | 0ms | 3576kb | C++17 | 2.0kb | 2024-10-12 12:48:29 | 2024-10-12 12:48:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i < b;i++)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x.size())
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int pref[1002][1002];
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t;
cin>>t;
while(t--){
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
pref[i][j] = 0;
}
}
int xl = 0,xr = n-1;
int yl = 0,yr = m-1;
string s;
cin>>s;
vector<pii>moved;
int cx = 0,cy = 0;
for(char c:s){
if(c == 'U'){
cx--;
xl--;
xr--;
xl = max(xl,0);
}
if(c == 'D'){
cx++;
xl++;
xr++;
xr = min(xr,n-1);
}
if(c == 'L'){
cy--;
yl--;
yr--;
yl = max(yl,0);
}
if(c == 'R'){
cy++;
yl++;
yr++;
yr = min(yr,m-1);
}
moved.push_back({cx,cy});
if(xl > xr || yl > yr)break;
}
xl += cx;
xr += cx;
yl += cy;
yr += cy;
//cout<<xl<<" "<<xr<<" "<<yl<<" "<<yr<<'\n';
if(xl > xr || yl > yr){
if(k)cout<<0<<'\n';
else cout<<n*m<<'\n';
continue;
}
map<pii,int>seen;
for(auto [x,y]:moved){
if(seen[{x,y}])continue;
seen[{x,y}] = 1;
pref[xl+x][yl+y]++;
pref[xl+x][yr+y+1]--;
//cout<<x<<" "<<y<<'\n';
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<pref[i][j]<<" ";
}
cout<<'\n';
}
cout<<'\n';*/
for(int i=0;i<n;i++){
for(int j=1;j<m;j++){
pref[i][j] += pref[i][j-1];
}
}
int d = xr-xl+1;
for(int j=0;j<m;j++){
for(int i=1;i<n;i++)pref[i][j] += pref[i-1][j];
for(int i=n-1;i>=d;i--)pref[i][j] -= pref[i-d][j];
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<pref[i][j]<<" ";
}
cout<<'\n';
}*/
int ans = 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int cnt = (xr-xl+1) * (yr-yl+1);
if(cnt - pref[i][j] == k)ans++;
}
}
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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...