QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387759 | #5414. Stop, Yesterday Please No More | wsc2008# | WA | 5ms | 6344kb | C++14 | 2.1kb | 2024-04-12 19:25:32 | 2024-04-12 19:25:33 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=2005;
ll n,m,k,len,sum[N][N],X,Y,Lx,Rx,Ly,Ry;
char s[N*N];
ll S(ll x,ll y,ll u,ll v){
x+=n,y+=m,u+=n,v+=m;
return sum[u][v]-sum[x-1][v]-sum[u][y-1]+sum[x-1][y-1];
}
void solve(){
n=read(),m=read(),k=read();
scanf("%s",s+1);
len=strlen(s+1);
sum[n][m]=1;
rep(i,1,len){
if(s[i]=='U')X++;
else if(s[i]=='D')X--;
else if(s[i]=='L')Y++;
else Y--;
if(X+n<0||X+n>2*n||Y+m<0||Y+m>2*m)continue;
sum[X+n][Y+m]=1;
}
rep(i,0,n*2){
rep(j,1,m*2)sum[i][j]+=sum[i][j-1];
}
rep(i,1,n*2){
rep(j,0,m*2)sum[i][j]+=sum[i-1][j];
}
X=Y=0;
rep(i,1,len){
if(s[i]=='U')X--;
else if(s[i]=='D')X++;
else if(s[i]=='L')Y--;
else Y++;
Lx=min(Lx,X),Rx=max(Rx,X);
Ly=min(Ly,Y),Ry=max(Ry,Y);
}
ll xL=0,xR=0,yL=0,yR=0;
rep(i,1,n){
if(i+Lx>=1&&i+Rx<=n){
if(!xL)xL=i;
xR=i;
}
}
rep(i,1,m){
if(i+Ly>=1&&i+Ry<=m){
if(!yL)yL=i;
yR=i;
}
}
if(!xL||!xR){
if(!k)write(n*m),putchar('\n');
else puts("0");
return ;
}
ll ans=0;
rep(i,1,n){
rep(j,1,m){
ll xl=xL-i,xr=xR-i,yl=yL-j,yr=yR-j;
ll s=(xR-xL+1)*(yR-yL+1)-S(xl,yl,xr,yr);
if(s==k)ans++;
}
}
write(ans),putchar('\n');
}
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
ll T=read();
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5964kb
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: 5ms
memory: 6344kb
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 0 0 0 15 0 240 0 0 0 0 0 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 320 0 0 0 0 0 0 0 0 0 0 0 0 22 0 51 0 0 6 0 0 48 28 8 0 0 0 0 0 0 0 0 0 44 0 0 0 0 4 30 0 0 105 0 0 17 0 66 0 11 28 0 0 0 0 0 0 90 0 0 0 0 48 0 0 0 0 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 225 0 0 0 0 11 0 90 0 0 228 0 3...
result:
wrong answer 3rd numbers differ - expected: '20', found: '0'