Skip to content
Snippets Groups Projects
Commit e181b086 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Small fixes

parent c769033c
No related branches found
No related tags found
No related merge requests found
...@@ -27,11 +27,12 @@ struct BFS { ...@@ -27,11 +27,12 @@ struct BFS {
while (!Q.empty()) { while (!Q.empty()) {
int v = Q.front(); Q.pop(); int v = Q.front(); Q.pop();
vis[v] = true;
for (auto i : graph[v]) for (auto i : graph[v])
if (!vis[i]) if (!vis[i]) {
vis[i] = true;
Q.push(i); Q.push(i);
}
} }
} }
}; };
...@@ -18,83 +18,65 @@ using namespace std; ...@@ -18,83 +18,65 @@ using namespace std;
typedef long long ll; typedef long long ll;
typedef pair<int,int> ii; typedef pair<int,int> ii;
typedef pair<ll, int> lli; typedef pair<ii,ii> elem;
typedef pair<ii, lli> elem;
ll cont[110][110];
int dx[] = {1, -1, 0, 0}; int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1}; int dy[] = {0, 0, 1, -1};
int cont[110][110][1 << 8];
int main() { int main() {
ios::sync_with_stdio(0); ios::sync_with_stdio(0);
cin.tie(0); cin.tie(0);
ii arya;
string x; string x;
vector<string> v; vector<string> mat;
int n, m;
ii arya, exit;
for (int lin = 0; cin >> x; ++lin) {
v.pb(x);
for (int i = 0; i < x.size(); ++i) {
if (x[i] == '@')
arya = {lin, i};
else if (x[i] == '*')
exit = {lin, i};
}
n = lin; for (int i = 0; cin >> x; ++i) {
m = x.size(); mat.pb(x);
for (int j = 0; j < x.size(); ++j)
if (x[j] == '@')
arya = {i, j};
} }
n++;
mset(cont, -1); int n = mat.size(), m = mat[0].size();
mset(cont, 0);
queue<elem> Q; queue<elem> Q;
Q.push({arya, {0LL, 0}}); Q.push({arya, {0, 0}});
int ans = -1; cont[arya.fi][arya.se][0] = 1;
while (!Q.empty()) { while (!Q.empty()) {
elem curr = Q.front(); Q.pop(); elem curr = Q.front(); Q.pop();
cont[curr.fi.fi][curr.fi.se] = curr.se.fi; cont[curr.fi.fi][curr.fi.se][curr.se.fi] = 1;
//for (int i = 0; i < n; ++i) { if (mat[curr.fi.fi][curr.fi.se] == '*')
// for (int j = 0; j < m; ++j) return cout << curr.se.se << ende, 0;
// cout << cont[i][j] << " ";
// cout << ende;
//}
//cout << ende;
if (curr.fi == exit) {
ans = curr.se.se;
break;
}
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
int x = curr.fi.fi + dx[i]; int x = curr.fi.fi + dx[i];
int y = curr.fi.se + dy[i]; int y = curr.fi.se + dy[i];
if (x >= 0 && x < n && y >= 0 && y < m && (cont[x][y] == -1 || __builtin_popcountll(cont[x][y]) < __builtin_popcountll(curr.se.fi)) && v[x][y] != '#') { if (x >= 0 && x < n && y >= 0 && y < m &&
ll msk = curr.se.fi; !cont[x][y][curr.se.fi] && mat[x][y] != '#') {
int msk = curr.se.fi;
if (v[x][y] >= 'a' && v[x][y] <= 'g') { if (mat[x][y] >= 'A' && mat[x][y] <= 'G') {
msk |= (1 << (v[x][y] - 'a')); if (msk & (1 << (mat[x][y] - 'A'))) {
} //cont[x][y][msk] = 1;
if (v[x][y] >= 'A' && v[x][y] <= 'G') {
if (msk & (1 << (v[x][y] - 'A')))
Q.push({{x, y}, {msk, curr.se.se + 1}}); Q.push({{x, y}, {msk, curr.se.se + 1}});
} else }
} else {
if (mat[x][y] >= 'a' && mat[x][y] <= 'g')
msk |= (1 << (mat[x][y] - 'a'));
//cont[x][y][msk] = 1;
Q.push({{x, y}, {msk, curr.se.se + 1}}); Q.push({{x, y}, {msk, curr.se.se + 1}});
}
} }
} }
} }
if (ans == -1) cout << "--" << ende;
cout << "--" << ende;
else
cout << ans << ende;
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment