# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159342 | shn | Chess Rush (CEOI20_chessrush) | C++20 | 0 ms | 0 KiB |
// #include "arithmetics.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1e9+7;
int Add(int a, int b) {
int ret = a%P;
ret = (ret<0 ? P+ret : ret) + (b%P);
return (ret>=0 ? ret%P : ret+P);
}
int Sub(int a, int b) {
int ret = a%P;
ret = (ret<0 ? P+ret : ret) - (b%P);
return (ret>=0 ? ret%P : ret+P);
}
int Mul(int a, int b) {
int ret = (1ll*(a%P) * (b%P)) % P;
return (ret<0 ? P+ret : ret);
}
int modpow(int base, int exp, int modulus=P) {
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 modinv(int a, int modulus=P) {
return modpow(a,modulus-2);
}
int Div(int a, int b) {
int ret = b%P;
ret = (1ll*(a%P) * modinv(ret<0 ? P+ret : ret)) % P;
return (ret<0 ? P+ret : ret);
}
int main(){
int r , c , q;
cin >> r >> c >> q;
while(q--){
char tt;
cin >> tt;
if(tt == 'P'){
int x , y;
cin >> x >> y;
if(x != y){
cout << 0 << '\n';
continue;
}
cout << "1 1\n";
}
else if(tt == 'R'){
int x , y;
cin >> x >> y;
if(x == y){
cout << "1 1\n";
continue;
}
cout << "2 2\n";
}
else{
int x , y;
cin >> x >> y;
if(x == y || abs(x - y) == abs(1 - r)){
cout << "1 1\n";
continue;
}
int ans = 2;
for(int j = 1; j <= c; j++){
if(j == x){
// int x2 = r - abs(j - y);
// if()
continue;
}
int x2 = 1 + abs(j - x);
if(abs(x2 - r) == abs(j - y)) ans = Add(ans , 1);
if(x2 == r) ans = Add(ans , 1);
if(j == y) ans = Add(ans , 1);
x2 = 1;
if(abs(x2 - r) == abs(j - y)) ans = Add(ans , 1);
if(j == y) ans = Add(ans , 1);
}
cout << 2 << ' ' << ans << '\n';
}
}
}