QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629753 | #8236. Snake Move | taijinvjin | Compile Error | / | / | C++17 | 3.3kb | 2024-10-11 14:39:26 | 2024-10-11 14:39:28 |
Judging History
answer
#include <bits/stdc++.h>
#define u64 unsigned long long
#define PII std::pair<int, int>
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
struct node {
u64 dis,
int id, cnt, len;
bool operator < (const node &a) const {
return dis > a.dis;
}
};
void solve() {
int n, m, k;
std::cin >> n >> m >> k;
std::vector<PII> snake(k + 1);
for (int i = 1; i <= k; i ++) {
std::cin >> snake[i].first >> snake[i].second;
}
std::vector<std::string> mp(n + 1);
for (int i = 1; i <= n; i ++) {
std::string s;
std::cin >> s;
s = ' ' + s;
mp[i] = s;
}
auto getid = [&](int x, int y) -> int {
x --;
y --;
return x * m + y + 1;
};
auto getpos = [&](int id) -> PII {
return {(id - 1) / m + 1, (id - 1) % m + 1};
};
std::vector<std::vector<int>> Cnt(n + 1, std::vector<int>(m + 1, 0));
auto dijkstra = [&](PII s) -> void {
std::vector<u64> dis(n * m + 1, 1E9);
std::vector<int> vis(n * m + 1, 0);
std::vector<std::vector<int>> Mp(n + 1, std::vector<int>(m + 1, 1E9));
for (int i = 1; i <= k; i ++) {
Mp[snake[i].first][snake[i].second] = i;
}
// for (int i = 1; i <= n; i ++) {
// for (int j = 1; j <= m; j ++) std::cout << Mp[i][j] << " \n"[j == m];
// }
std::priority_queue<node> q;
q.push({0, getid(s.first, s.second), 0, k});
dis[getid(s.first, s.second)] = 0;
while (!q.empty()) {
auto [d, u, cnt, len] = q.top();
q.pop();
auto [x, y] = getpos(u);
if (vis[u] == 1) continue;
vis[u] = 1;
for (int i = 0; i < 4; i ++) {
int nx = x + dx[i], ny = y + dy[i];
int v = getid(nx, ny);
if (nx < 1 || nx > n || ny < 1 || ny > m || mp[nx][ny] == '#') continue;
if (len - Mp[nx][ny] - cnt > 0) {
int Len = Mp[nx][ny];
if (Len < 1) continue;
// std::cout << nx << " " << ny << " " << Len << "\n";
if (dis[v] > d + len - Len + 1) {
dis[v] = d + len - Len + 1;
q.push({dis[v], v, cnt + 1, Len});
}
continue;
}
v = getid(nx, ny);
if (dis[v] > d + 1) {
dis[v] = d + 1;
q.push({dis[v], v, cnt + 1, len});
}
}
}
u64 Ans = 0;
for (int i = 1; i <= n * m; i ++) {
auto P = getpos(i);
Cnt[P.first][P.second] = dis[i];
if (dis[i] == 1E9) continue;
Ans += (dis[i]) * (dis[i]);
}
// for (int i = 1; i <= n; i ++) {
// for (int j = 1; j <= m; j ++) {
// std::cout << Cnt[i][j] << " \n"[j == m];
// }
// }
std::cout << Ans << "\n";
};
dijkstra({snake[1].first, snake[1].second});
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T = 1;
// std::cin >> T;
while (T --) {
solve();
}
}
Details
answer.code:11:5: error: expected unqualified-id before ‘int’ 11 | int id, cnt, len; | ^~~ answer.code: In lambda function: answer.code:56:15: error: no matching function for call to ‘std::priority_queue<node>::push(<brace-enclosed initializer list>)’ 56 | q.push({0, getid(s.first, s.second), 0, k}); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/queue:66, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157, from answer.code:1: /usr/include/c++/13/bits/stl_queue.h:738:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 738 | push(const value_type& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:738:30: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::priority_queue<node>::value_type&’ {aka ‘const node&’} 738 | push(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_queue.h:746:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 746 | push(value_type&& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:746:25: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::priority_queue<node>::value_type&&’ {aka ‘node&&’} 746 | push(value_type&& __x) | ~~~~~~~~~~~~~^~~ answer.code:59:18: error: 4 names provided for structured binding 59 | auto [d, u, cnt, len] = q.top(); | ^~~~~~~~~~~~~~~~ answer.code:59:18: note: while ‘node’ decomposes into 1 element answer.code:66:35: error: ‘ny’ was not declared in this scope; did you mean ‘n’? 66 | int v = getid(nx, ny); | ^~ | n answer.code:74:31: error: no matching function for call to ‘std::priority_queue<node>::push(<brace-enclosed initializer list>)’ 74 | q.push({dis[v], v, cnt + 1, Len}); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_queue.h:738:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 738 | push(const value_type& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:738:30: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::priority_queue<node>::value_type&’ {aka ‘const node&’} 738 | push(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_queue.h:746:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 746 | push(value_type&& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:746:25: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::priority_queue<node>::value_type&&’ {aka ‘node&&’} 746 | push(value_type&& __x) | ~~~~~~~~~~~~~^~~ answer.code:81:27: error: no matching function for call to ‘std::priority_queue<node>::push(<brace-enclosed initializer list>)’ 81 | q.push({dis[v], v, cnt + 1, len}); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_queue.h:738:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 738 | push(const value_type& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:738:30: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::priority_queue<node>::value_type&’ {aka ‘const node&’} 738 | push(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_queue.h:746:7: note: candidate: ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = node; _Sequence = std::vector<node, std::allocator<node> >; _Compare = std::less<node>; value_type = node]’ 746 | push(value_type&& __x) | ^~~~ /usr/include/c++/13/bits/stl_queue.h:746:25: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::priority_queue<node>::value_type&&’ {aka ‘node&&’} 746 | push(value_type&& __x) |...