#include "bits/stdc++.h"
using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
int binpow(int base, int exp, int modulus=mod) {
base %= modulus;
int result = 1;
while (exp > 0) {
if (exp & 1) result = (1ll*result * base) % modulus;
base = (1ll*base * base) % modulus;
exp >>= 1;
}
return result;
}
int n, m, q;
vector<vector<int>> merge(const vector<vector<int>> &a, const vector<vector<int>> &b) {
vector ans(m, vector(m, 0));
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < m; k++) {
// ans[i][k] += a[i][j] * b[j][k];
ans[i][k] = (ans[i][k] + ll(a[i][j]) * b[j][k]) % mod;
}
}
}
return ans;
}
bool bish(int x1, int y1, int x2, int y2) {
return x1 + y1 == x2 + y2 or x1 - y1 == x2 - y2;
}
int main() {
cin >> n >> m >> q;
int lg = 0;
while ((1 << lg) < n) lg++;
vector<vector<vector<int>>> dp;
vector ans(m, vector(m, 0));
if (m <= 100) {
dp = vector(lg, vector(m, vector(m, 0)));
for (int i = 0; i < m; i++) {
dp[0][i][i] = 1;
if (i > 0) dp[0][i][i - 1] = 1;
if (i + 1 < m) dp[0][i][i + 1] = 1;
}
for (int i = 1; i < lg; i++) dp[i] = merge(dp[i - 1], dp[i - 1]);
bool emp = true;
for (int i = lg - 1; i >= 0; i--) {
if ((n - 1) >> i & 1) {
if (emp) ans = dp[i];
else ans = merge(ans, dp[i]);
emp = false;
}
}
}
while (q--) {
char op;
int c1, c2;
cin >> op >> c1 >> c2;
if (op == 'P') {
if (c1 == c2) cout << n - 1 << " 1\n";
else cout << "0 0\n";
} else if (op == 'R') {
if (c1 == c2) cout << "1 1\n";
else cout << "2 2\n";
} else if (op == 'Q') {
if (c1 == c2 or bish(c1, 1, c2, n)) cout << "1 1\n";
else {
cout << "2 ";
set<pair<int, int>> st;
st.emplace(1, c2);
st.emplace(n, c1);
int x = 1, y = c1;
for (int i = 1; i <= m; i++) {
if (x + i > n) continue;
if (y - i > 0) {
if (bish(x + i, y - i, n, c2) or x + i == n or y - i == c2) st.emplace(x + i, y - i);
}
if (y + i <= m) {
if (bish(x + i, y + i, n, c2) or x + i == n or y + i == c2) st.emplace(x + i, y + i);
}
}
x = n, y = c2;
for (int i = 1; i <= m; i++) {
if (x - i <= 0) continue;
if (y - i > 0) {
if (bish(x - i, y - i, 1, c1) or x - i == 1 or y - i == c1) st.emplace(x - i, y - i);
}
if (y + i <= m) {
if (bish(x - i, y + i, 1, c1) or x - i == 1 or y + i == c1) st.emplace(x - i, y + i);
}
}
cout << st.size() << '\n';
}
} else if (op == 'K') {
cout << n - 1 << ' ' << ans[c1 - 1][c2 - 1] << '\n';
} else if (op == 'B') {
queue<pair<int, int>> q;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |