Submission #19463613


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int H,W,K;
char S[5050][5050];
ll dp[5050][5050];
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	FOR(i,K) {
		cin>>y>>x>>s;
		S[y-1][x-1]=s[0];
	}
	dp[0][0]=1;
	ll re=1;
	ll a=2*modpow(3);
	FOR(y,H) FOR(x,W) {
		if(S[y][x]==0) {
			re=re*3%mo;
			(dp[y+1][x]+=dp[y][x]*a)%=mo;
			(dp[y][x+1]+=dp[y][x]*a)%=mo;
		}
		else {
			if(S[y][x]=='D'||S[y][x]=='X') (dp[y+1][x]+=dp[y][x])%=mo;
			if(S[y][x]=='R'||S[y][x]=='X') (dp[y][x+1]+=dp[y][x])%=mo;
		}
	}
	cout<<dp[H-1][W-1]*re%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task C - Robot on Grid
User kmjp
Language C++ (GCC 9.2.1)
Score 500
Code Size 1498 Byte
Status AC
Exec Time 361 ms
Memory 225552 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:29:8: warning: unused variable ‘j’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:29:10: warning: unused variable ‘k’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:29:12: warning: unused variable ‘l’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:29:14: warning: unused variable ‘r’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:58:38: note: in expansion of macro ‘FOR’
   58 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 35 ms 23712 KB
random_02.txt AC 33 ms 23648 KB
random_03.txt AC 2 ms 3708 KB
random_04.txt AC 2 ms 3692 KB
random_05.txt AC 358 ms 225472 KB
random_06.txt AC 356 ms 225488 KB
random_07.txt AC 357 ms 225432 KB
random_08.txt AC 361 ms 225552 KB
random_09.txt AC 358 ms 225428 KB
random_10.txt AC 361 ms 225552 KB
random_11.txt AC 6 ms 3920 KB
random_12.txt AC 2 ms 3780 KB
random_13.txt AC 2 ms 3776 KB
random_14.txt AC 2 ms 3820 KB
random_15.txt AC 2 ms 3832 KB
random_16.txt AC 85 ms 53152 KB
random_17.txt AC 176 ms 111680 KB
random_18.txt AC 308 ms 200880 KB
sample_01.txt AC 6 ms 3668 KB
sample_02.txt AC 2 ms 3644 KB
sample_03.txt AC 311 ms 200916 KB