Submission #19471700
Source Code Expand
Copy
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 998244353;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
const int N = 5e3 + 10;
int a[N][N];
int dp[N][N];
void add(int& x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
int64 power_mod(int64 a, int64 n, int p = MOD) {
int64 ret = 1;
for (; n; n >>= 1) {
if (n & 1) ret = ret * a % p;
a = a * a % p;
}
return ret;
}
int p3[N * N];
int main() {
p3[0] = 1;
for (int i = 1; i < N * N; ++i) p3[i] = p3[i - 1] * 3LL % MOD;
int64 inv3 = power_mod(3, MOD - 2);
int n, m, len;
cin >> n >> m >> len;
int sum = n * m;
for (int i = 0; i < len; ++i) {
int x, y;
string s;
cin >> x >> y >> s;
--x; --y;
if (s[0] == 'X') {
a[x][y] = 3;
} else if (s[0] == 'R') {
a[x][y] = 1;
} else {
a[x][y] = 2;
}
--sum;
}
for (int i = n - 1; i >= 0; --i) {
for (int j = m - 1; j >= 0; --j) {
if (i == n - 1 && j == m - 1) {
dp[i][j] = 1;
} else {
if (a[i][j] == 1) {
add(dp[i][j], dp[i][j + 1]);
} else if (a[i][j] == 2) {
add(dp[i][j], dp[i + 1][j]);
} else if (a[i][j] == 3) {
add(dp[i][j], dp[i][j + 1]);
add(dp[i][j], dp[i + 1][j]);
} else {
add(dp[i][j], dp[i][j + 1] * 2LL % MOD);
add(dp[i][j], dp[i + 1][j] * 2LL % MOD);
}
if (!a[i][j]) dp[i][j] = dp[i][j] * inv3 % MOD;
}
// trace(i, j, dp[i][j]);
}
}
int ret = 1LL * p3[sum] * dp[0][0] % MOD;
cout << ret << '\n';
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Robot on Grid |
User |
cuiaoxiang |
Language |
C++ (Clang 10.0.0) |
Score |
500 |
Code Size |
4057 Byte |
Status |
AC |
Exec Time |
900 ms |
Memory |
296892 KB |
Compile Error
./Main.cpp:78:42: warning: unused variable 'inf' [-Wunused-const-variable]
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
^
1 warning generated.
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 |
168 ms |
121056 KB |
random_02.txt |
AC |
166 ms |
121112 KB |
random_03.txt |
AC |
148 ms |
101132 KB |
random_04.txt |
AC |
148 ms |
101120 KB |
random_05.txt |
AC |
770 ms |
296740 KB |
random_06.txt |
AC |
770 ms |
296720 KB |
random_07.txt |
AC |
768 ms |
296892 KB |
random_08.txt |
AC |
767 ms |
296872 KB |
random_09.txt |
AC |
771 ms |
296800 KB |
random_10.txt |
AC |
900 ms |
296748 KB |
random_11.txt |
AC |
148 ms |
101644 KB |
random_12.txt |
AC |
145 ms |
101388 KB |
random_13.txt |
AC |
143 ms |
101276 KB |
random_14.txt |
AC |
144 ms |
101500 KB |
random_15.txt |
AC |
146 ms |
101384 KB |
random_16.txt |
AC |
312 ms |
147388 KB |
random_17.txt |
AC |
461 ms |
203712 KB |
random_18.txt |
AC |
533 ms |
199044 KB |
sample_01.txt |
AC |
143 ms |
101184 KB |
sample_02.txt |
AC |
143 ms |
101192 KB |
sample_03.txt |
AC |
532 ms |
198988 KB |