Submission #19488484
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;
using mi = atcoder::modint998244353;
void solve() {
int H,W,K; cin >> H >> W >> K;
// R,D,X 0,1,2
vector<vector<mi>> dp(H,vector<mi>(W,0));
vector<vector<char>> grid(H,vector<char>(W,'.'));
REP(_,K) {
int h,w;
char c;
cin >> h >> w >> c;
h--; w--;
grid[h][w] = c;
}
using Position = pair<int,int>;
dp[0][0] = mi(3).pow(H*W - K);
auto r = mi(2) * mi(3).inv();
REP(h,H) REP(w,W) {
if (grid[h][w] == 'D' && h + 1 < H) {
dp[h+1][w] += dp[h][w];
continue;
} else if (grid[h][w] == 'R' && w + 1 < W) {
dp[h][w+1] += dp[h][w];
continue;
} else if (grid[h][w] == 'X') {
if(h + 1 < H) dp[h+1][w] += dp[h][w];
if (w + 1 < W) dp[h][w+1] += dp[h][w];
continue;
} else if (grid[h][w] == '.') {
if (h+1 < H) dp[h+1][w] += dp[h][w] * r;
if (w+1 < W) dp[h][w+1] += dp[h][w] * r;
}
}
cout << (dp[H-1][W-1]).val() << endl;
}
int main() {
solve();
return 0;
}
Submission Info
Submission Time
2021-01-17 15:09:16+0900
Task
C - Robot on Grid
User
reud
Language
C++ (GCC 9.2.1)
Score
500
Code Size
1844 Byte
Status
AC
Exec Time
330 ms
Memory
125684 KiB
Compile Error
./Main.cpp: In function ‘void solve()’:
./Main.cpp:38:11: warning: typedef ‘using Position = struct std::pair<int, int>’ locally defined but not used [-Wunused-local-typedefs]
38 | using Position = pair<int,int>;
| ^~~~~~~~
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
6 ms
4168 KiB
random_02.txt
AC
4 ms
3960 KiB
random_03.txt
AC
2 ms
3472 KiB
random_04.txt
AC
2 ms
3460 KiB
random_05.txt
AC
329 ms
125572 KiB
random_06.txt
AC
328 ms
125672 KiB
random_07.txt
AC
327 ms
125520 KiB
random_08.txt
AC
330 ms
125684 KiB
random_09.txt
AC
326 ms
125660 KiB
random_10.txt
AC
324 ms
125504 KiB
random_11.txt
AC
4 ms
3580 KiB
random_12.txt
AC
4 ms
3420 KiB
random_13.txt
AC
3 ms
3408 KiB
random_14.txt
AC
3 ms
3424 KiB
random_15.txt
AC
6 ms
3520 KiB
random_16.txt
AC
81 ms
18820 KiB
random_17.txt
AC
163 ms
56072 KiB
random_18.txt
AC
245 ms
125520 KiB
sample_01.txt
AC
2 ms
3472 KiB
sample_02.txt
AC
3 ms
3472 KiB
sample_03.txt
AC
249 ms
125584 KiB