Submission #19499469
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;//三年竞赛一场空,不开long long见祖宗
//typedef __int128 lll;
#define print(i) cout << "debug: " << i << endl
#define close() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define x first
#define y second
typedef pair<int, int> pii;
const ll mod = 998244353;
const int maxn = 5010;
const int inf = 0x3f3f3f3f;
char g[maxn][maxn];
ll dp[maxn][maxn];
ll numd[maxn][maxn], numr[maxn][maxn];
int n, m, k;
ll p[maxn];
void init()
{
p[0] = 1;
for(int i = 1; i < maxn; i++)
p[i] = p[i - 1] * 3 % mod;
}
int main()
{
init();
cin >> n >> m >> k;
for(int i = 1; i <= k; i++)
{
int x, y;
string s;
cin >> x >> y >> s;
g[x][y] = s[0];
}
for(int i = 1; i <= n; i++)
for(int j = m; j >= 1; j--)
numr[i][j] = numr[i][j + 1] + (g[i][j] == 0);
for(int j = 1; j <= m; j++)
for(int i = n; i >= 1; i--)
numd[i][j] = numd[i + 1][j] + (g[i][j] == 0);
dp[1][1] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
ll num = dp[i][j];
if(g[i][j] == 'R' || g[i][j] == 'X') dp[i][j + 1] += num * p[numd[i + 1][j]] % mod, dp[i][j + 1] %= mod;
if(g[i][j] == 'D' || g[i][j] == 'X') dp[i + 1][j] += num * p[numr[i][j + 1]] % mod, dp[i + 1][j] %= mod;
if(g[i][j] == 0)
{
dp[i + 1][j] += 2 * num * p[numr[i][j + 1]] % mod;
dp[i + 1][j] %= mod;
dp[i][j + 1] += 2 * num * p[numd[i + 1][j]] % mod;
dp[i][j + 1] %= mod;
}
}
if(g[n][m] == 0) dp[n][m] *= 3, dp[n][m] %= mod;
cout << dp[n][m] << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Robot on Grid |
| User | Im_8421BCD |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1891 Byte |
| Status | AC |
| Exec Time | 1212 ms |
| Memory | 615292 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| 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 | 63 ms | 63784 KiB |
| random_02.txt | AC | 64 ms | 63884 KiB |
| random_03.txt | AC | 5 ms | 3820 KiB |
| random_04.txt | AC | 2 ms | 3948 KiB |
| random_05.txt | AC | 1212 ms | 615252 KiB |
| random_06.txt | AC | 1192 ms | 615272 KiB |
| random_07.txt | AC | 1195 ms | 615292 KiB |
| random_08.txt | AC | 1200 ms | 615148 KiB |
| random_09.txt | AC | 1202 ms | 615204 KiB |
| random_10.txt | AC | 1199 ms | 615156 KiB |
| random_11.txt | AC | 6 ms | 4444 KiB |
| random_12.txt | AC | 6 ms | 4096 KiB |
| random_13.txt | AC | 4 ms | 4052 KiB |
| random_14.txt | AC | 5 ms | 4116 KiB |
| random_15.txt | AC | 3 ms | 3992 KiB |
| random_16.txt | AC | 218 ms | 124340 KiB |
| random_17.txt | AC | 548 ms | 301988 KiB |
| random_18.txt | AC | 1056 ms | 590744 KiB |
| sample_01.txt | AC | 3 ms | 3656 KiB |
| sample_02.txt | AC | 3 ms | 3572 KiB |
| sample_03.txt | AC | 1047 ms | 590736 KiB |