#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef pair<ll,ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll R, C, Q;
cin >> R >> C >> Q;
vvv distance(C, vv(R, v(C, INF)));
vvv numberOfWays(C, vv(R, v(C, 0)));
for (ll i = 0; i < C; i++)
{
queue<tri> bfs;
bfs.emplace(0, p(0, i));
numberOfWays[i][0][i] = 1;
distance[i][0][i] = 0;
while (!bfs.empty())
{
auto top = bfs.front();
bfs.pop();
assert(top.s.f >= 0 && top.s.s >= 0 && top.s.f < R && top.s.s < C);
for (ll add = -min(top.s.f, top.s.s); add < min(R - top.s.f, C - top.s.s); add++)
{
if (distance[i][top.s.f + add][top.s.s + add] == INF)
{
distance[i][top.s.f + add][top.s.s + add] = top.f + 1;
bfs.emplace(top.f + 1, p(top.s.f + add, top.s.s + add));
}
if (distance[i][top.s.f + add][top.s.s + add] == top.f + 1)
{
numberOfWays[i][top.s.f + add][top.s.s + add] = (numberOfWays[i][top.s.f + add][top.s.s + add] + numberOfWays[i][top.s.f][top.s.s]) % mod;
}
}
for (ll add = -min(R - top.s.f - 1, top.s.s); add < min(top.s.f + 1, C - top.s.s); add++)
{
if (distance[i][top.s.f - add][top.s.s + add] == INF)
{
distance[i][top.s.f - add][top.s.s + add] = top.f + 1;
bfs.emplace(top.f + 1, p(top.s.f - add, top.s.s + add));
}
if (distance[i][top.s.f - add][top.s.s + add] == top.f + 1)
{
numberOfWays[i][top.s.f - add][top.s.s + add] = (numberOfWays[i][top.s.f - add][top.s.s + add] + numberOfWays[i][top.s.f][top.s.s]) % mod;
}
}
}
}
for (ll iter = 0; iter < Q; iter++)
{
char T;
cin >> T;
ll from, to;
cin >> from >> to;
if (T == 'B')
{
cout << distance[from - 1][R - 1][to - 1] << " " << numberOfWays[from - 1][R - 1][to - 1] << "\n";
}
else cout << "-1 -1\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |