QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698333#5414. Stop, Yesterday Please No Moresix_sspWA 0ms3924kbC++231.5kb2024-11-01 18:57:552024-11-01 18:57:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 18:57:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3924kb
  • [2024-11-01 18:57:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n, m, K;
string s;
int f[2005][2005];
int main() {
    int T; 
	scanf("%d", &T);
    while(T--)
	{
	scanf("%d%d%d",&n, &m, &K);
    cin>>s;
    int U=1,D=n,L=1,R=m;
    int u=1,d=n,l=1,r=m;
    for(int i=0;i<s.size();i++) 
	{
        if(s[i]=='U') 
		  u++, d++;
        else if(s[i]=='D')
		   u--, d--;
        else if(s[i]=='L') 
		  l++, r++;
        else 
		  l--, r--;
        U=max(U,u);
        D=min(D,d);
        L=max(L,l);
        R=min(R,r);
    }
    if(U>D||L>R)
	 {
        if(K == 0)
		  printf("%d\n",n*m);
        else 
		  printf("0\n");
        continue;
    }
    int cha=(D-U+1)*(R-L+1)-K;
    if(cha<0)
	 {
        printf("0\n");
        continue;
    }
    for(int i=0;i<=n*2+5;i++) 
	  for(int j=0;j<=m*2+5;j++) 
	  f[i][j]=0;
    int BR=n+1,BC=m+1;
    f[BR][BC]=1;
    for (int i=0,r=R,c=BC;i<s.size();i++)
	 {
        if(s[i]=='U') r++;
        else if(s[i]=='D') r--;
        else if(s[i]=='L') c++;
        else if(s[i]=='R') c--;
        f[r][c]=1;
    }
    for(int i=1;i<=n*2+5;i++)
	  for (int j=1;j<=m*2+5;j++) 
	   f[i][j]+=f[i][j-1];
    for(int i=1;i<=n*2+5;i++)
	  for(int j=1;j<=m*2+5;j++) 
	    f[i][j]+=f[i-1][j];
    int ans=0;
    for(int i=1;i<=n;i++) 
	for(int j=1;j<=m;j++)
	 {
        int bR=BR-i,bC=BC-j;
        int t=f[D+bR][R+bC]-f[U-1+bR][R+bC]-f[D+bR][L-1+bC]+f[U-1+bR][L-1+bC];
        if(t==cha)
		  ans++;
    }
    printf("%d\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3924kb

input:

3
4 5 3
ULDDRR
4 5 0
UUUUUUU
4 5 10
UUUUUUU

output:

3
20
0

result:

wrong answer 1st numbers differ - expected: '2', found: '3'