跳到正文

闲话

666

__dpfQwQ__约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int t,h,w;
string s;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>h>>w>>s;
		int x=1,y=1,xx=1,yy=1,d1=h-1,d2=h-1,r1=w-1,r2=w-1;
		int l[200005],r[200005];
		l[1]=1,r[1]=1;
		for(int i=0;i<s.size();i++){
			if(s[i]=='D') d1--,d2--;
			else if(s[i]=='R') r1--,r2--;
		}
		for(int i=0;i<s.size();i++){
			if(s[i]=='D'){
				x++,xx++;
				l[x]=y,r[xx]=yy;
			}
			else if(s[i]=='R'){
				y++,yy++;
				r[xx]=yy;
			}
			else{
				if(d1>0) d1--,x++,l[x]=y;
				else r1--,y++;
				if(r2>0) r2--,yy++,r[xx]=yy;
				else d2--,xx++,r[xx]=yy;
			}
		}
		int ans=0;
		for(int i=1;i<=h;i++) ans+=r[i]-l[i]+1;
		cout<<ans<<'\n';
	}
	return 0;
}
原文