QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142582#5414. Stop, Yesterday Please No Morebalpoint_penWA 0ms7676kbC++141.6kb2023-08-19 12:42:492023-08-19 12:42:51

Judging History

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

  • [2023-08-19 12:42:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7676kb
  • [2023-08-19 12:42:49]
  • 提交

answer

/*
    Author: YZB
    Problem:
    Time:
*/
#include <bits/stdc++.h>
#define int long long
#define rep(_i_,_l_,_r_) for(int _i_=_l_;_i_<=_r_;_i_++)
//#define FILE
using namespace std;
const int N=1005;
int sm[N][N],f[N][N];
char mv[N*N];
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)sm[i][j]=f[i][j]=0;
	string s;
	cin>>s;
	int len=s.size();
	for(int i=0;i<len;i++)mv[i+1]=s[i];
	int tx=0,ty=0,mxx=0,mxy=0,mix=0,miy=0;
	for(int i=1;i<=len;i++){
		if(mv[i]=='U')tx--;
		if(mv[i]=='D')tx++;
		if(mv[i]=='L')ty--;
		if(mv[i]=='R')ty++;
		mxx=max(mxx,tx); mix=min(mix,tx);
		mxy=max(mxy,ty); miy=min(miy,ty);
	}
	int lx=1-mix,ly=1-miy,rx=n-mxx,ry=m-mxy;
	if(lx>n||rx<1||ly>m||ry<1||lx>rx||ly>ry){
		if(k==0)cout<<n*m<<'\n';
		else cout<<0<<'\n';
		return ;
	}
	int tot=(rx-lx+1)*(ry-ly+1);
	f[rx][ry]=1; sm[rx][ry]++; sm[rx][ly-1]--; sm[lx-1][ry]--; sm[lx-1][ly-1]++;
	for(int i=1;i<=len;i++){
		if(mv[i]=='U')lx--,rx--;
		if(mv[i]=='D')lx++,rx++;
		if(mv[i]=='L')ly--,ry--;
		if(mv[i]=='R')ly++,ry++;
		if(f[rx][ry])continue; f[rx][ry]=1;
		sm[rx][ry]++; sm[rx][ly-1]--; sm[lx-1][ry]--; sm[lx-1][ly-1]++;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			sm[i][j]+=sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1];
	int ans=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans+=((tot-sm[i][j])==k);
	cout<<ans<<'\n';
}
signed main(){
#ifdef FILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--)solve(); 
	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

0
20
0

result:

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