QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276461 | #7034. Honeycomb | zzuqy# | RE | 1ms | 3724kb | C++20 | 4.0kb | 2023-12-05 21:29:51 | 2023-12-05 21:29:52 |
Judging History
answer
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
#define DEBUG 0
const int N = 4e3 + 9;
typedef long long ll;
int read() {
int x = 0, s = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') s = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * s;
}
int r, c;
// int d[N][N];
// x -- r ; y -- c
// start from up
const int dx[] = {-2, -1, 1, 2, 1, -1}, dy[] = {0, 3, 3, 0, -3, -3};
const int di[] = {-1, -1, 0, 1, 0, -1}, dj[] = {0, 1, 1, 0, -1, -1};
const int di2[] = {-1, 0, 1, 1, 1, 0}, dj2[] = {0, 1, 1, 0, -1, -1};
// 寄 (3, 5)
/*
1
3 4
+---+ +---+
/ \ / \
+ +---+ +---+
\ \ / \
+ + S +---+ T +
/ \ / /
+ +---+ + +
\ \ / \
+---+ +---+ +
/ /
+ +---+ + +
\ / \
+---+ +---+ +
\ / \ /
+---+ +---+
*/
int _r, _c;
int get(int i, int j) {
return (i - 1) * c + j;
}
void solve() {
vector<int> G[N];
_c = 0;
_r = 1;
r = read(), c = read();
map<pair<int, int>, char> mp;
while (_r <= 4 * r + 3) {
char ch = getchar();
if (ch == EOF)
break;
_c++;
mp[{_r, _c}] = ch;
if (ch == '\n') {
_r++;
_c = 0;
}
}
for (int i = 1; i <= 4 * r + 3; ++i) {
for (int j = 1; ; ++j) {
char ch = mp[{i, j}];
// cout << ch;
if (ch == '\n')
break;
}
}
int sx, sy, tx, ty;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j += 2) {
int x = 3 + (i - 1) * 4, y = 5 + (j - 1) * 6;
if (mp[{x, y}] == 'S') {
if (DEBUG) {
cout << "A: ";
cout << i << ' ' << j << '\n';
}
sx = i, sy = j;
}
if (mp[{x, y}] == 'T') {
if (DEBUG) {
cout << "B: ";
cout << i << ' ' << j << '\n';
}
tx = i, ty = j;
}
for (int k = 0; k < 6; ++k) {
int nx = x + dx[k], ny = y + dy[k];
int ni = i + di[k], nj = j + dj[k];
if (mp[{nx, ny}] == ' ') {
G[get(i, j)].push_back(get(ni, nj));
// G[get(ni, nj)].push_back(get(i, j));
// cout << i << ' ' << j << "->" << ni << ' ' << nj << '\n';
}
}
}
for (int j = 2; j <= c; j += 2) {
int x = 5 + (i - 1) * 4, y = 11 + (j - 2) * 6;
if (mp[{x, y}] == 'S') {
if (DEBUG) {
cout << "C: ";
cout << i << ' ' << j << '\n';
}
sx = i, sy = j;
}
if (mp[{x, y}] == 'T') {
if (DEBUG) {
cout << "D: ";
cout << i << ' ' << j << '\n';
}
tx = i, ty = j;
}
for (int k = 0; k < 6; ++k) {
int nx = x + dx[k], ny = y + dy[k];
int ni = i + di2[k], nj = j + dj2[k];
if (mp[{nx, ny}] == ' ') {
G[get(i, j)].push_back(get(ni, nj));
// G[get(ni, nj)].push_back(get(i, j));
// cout << i << ' ' << j << "->" << ni << ' ' << nj << '\n';
}
}
}
}
if (DEBUG) {
cout << sx << ' ' << sy << '\n';
cout << tx << ' ' << ty << '\n';
}
queue<int> que;
map<int, int> dis;
dis[get(sx, sy)] = 1;
que.push(get(sx, sy));
while (que.size()) {
auto x= que.front();
que.pop();
for (auto y : G[x]) {
if (dis.count(y))
continue;
dis[y] = dis[x] + 1;
que.push(y);
if (y == get(tx, ty))
break;
}
}
if (dis.count(get(tx, ty))) {
printf("%d\n", dis[get(tx, ty)]);
} else {
puts("-1");
}
}
int main() {
int T = read();
while (T--) {
// cout << "Cialo~\n";
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3724kb
input:
1 3 4 +---+ +---+ / \ / \ + +---+ +---+ \ \ / \ + + S +---+ T + / \ / / + +---+ + + \ \ / \ +---+ +---+ + / / + +---+ + + \ ...
output:
7
result:
ok single line: '7'
Test #2:
score: -100
Runtime Error
input:
400 67 89 +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ ...