QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764967#8023. The Journey of Geor AutumnlarryyuWA 1ms5588kbC++201.4kb2024-11-20 11:24:212024-11-20 11:24:21

Judging History

This is the latest submission verdict.

  • [2024-11-20 11:24:21]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5588kb
  • [2024-11-20 11:24:21]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int a[5050][5050];
int cnt1[5050],cnt2[5050];
long long f[5050][5050],pw[5050];
struct Mod{
	long long m,p;
	void init(long long pp){
		m=((__int128)1ll<<64)/pp;p=pp;
	}
	long long operator()(long long x){
		return x-((__int128(x)*m)>>64)*p;
	}
}mod;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	mod.init(998244353);
	cin>>n>>m>>k;
	pw[0]=1;
	for(int i=1;i<=max(n,m);i++){
		pw[i]=mod(pw[i-1]*3ll);
	}
	for(int i=1;i<=k;i++){
		int x,y;
		char ch;
		cin>>x>>y>>ch;
		if(ch=='R') a[x][y]=1;
		else if(ch=='D') a[x][y]=2;
		else a[x][y]=3;
	}
	for(int i=1;i<=n;i++){
			cnt1[i]=(!a[i][m]);
	}
	for(int i=1;i<=m;i++){
			cnt2[i]=(!a[n][i]);
	}
	f[n][m]=(!a[n][m]?3ll:1ll);
	for(int i=n-1;i;i--){
		if(a[i][m]>=2) f[i][m]=f[i+1][m];
		else if(!a[i][m]) f[i][m]=mod(2ll*f[i+1][m]);
	}
	for(int i=m-1;i;i--){
		if(a[n][i]%2) f[n][i]=f[n][i+1];
		else if(!a[n][i]) f[n][i]=mod(2ll*f[n][i+1]);
	}
	long long x,y;
	for(int i=n-1;i;i--){
		for(int j=m-1;j;j--){
			x=mod(f[i][j+1]*pw[cnt2[j]]);
			y=mod(f[i+1][j]*pw[cnt1[i]]);
			cnt1[i]+=!(a[i][j]);
			cnt2[j]+=!(a[i][j]);
			if(!a[i][j]){
				f[i][j]=mod(2ll*(x+y));
			}else if(a[i][j]==1){
				f[i][j]=x;
			}else if(a[i][j]==2){
				f[i][j]=y;
			}else{
				f[i][j]=mod(x+y);
			}
		}
	}
	cout<<f[1][1];
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5588kb

input:

1 1

output:

3

result:

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