QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662284 | #8236. Snake Move | rgrgtgrf | Compile Error | / | / | C++23 | 3.5kb | 2024-10-20 22:34:08 | 2024-10-20 22:34:13 |
Judging History
answer
#pragma GCC optimize(2, "Ofast", "inline")
#include <bits/stdc++.h>
// using pair<int,int>= pair<int,int>;
// using tuple<int,int,int>= tuple<int,int,int>;
using ll = long long;
using ull = unsigned long long;
using namespace std;
const int inf = 1e9;
#define int long long
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vector<pair<int,int>> snack(k);
// map<pair<int,int>, int> mp;
vector<int> mp(n * m + 1000, 0);
for(int i = 0; i < k; i++) {
cin >> snack[i].first >> snack[i].second;
snack[i].first--;
snack[i].second--;
if(i)mp[snack[i].first * m + snack[i].second] = k - i;
}
vector<string> qizi(n);
for(int i = 0; i < n; i++) {
cin >> qizi[i];
}
int odir = -1;
for(int i = 0; i < 4; i++) {
if(snack[1].first+ dx[i] == snack[0].first && snack[1].second + dy[i] == snack[0].second) {
odir = i;
}
}
vector<array<int, 4>> f(n * m, {inf, inf, inf, inf});
// f[snack[0].first][snack[0].second] = 0;
deque<tuple<int,int,int>> pq;
pq.push_back({0, odir, snack[0].first * m + snack[0].second});
vector<vector<pair<int, int>>> v(n * m);
while(!pq.empty()) {
auto [d, dir, pos] = pq.front();
pq.pop_front();
if(!v[d].empty()) {
for(int i = 0; i < int(v[d].size()); i++) {
auto [a, b] = v[d].back();
v[d].pop_back();
pq.push_front({d, a, b});
}
}
int x = pos / m;
int y = pos % m;
if(f[pos][dir] != inf) {
continue;
}
// cerr << x + 1 << " " << y + 1 << " " << d << endl;
f[pos][dir] = d;
for(int i = 0; i < 4; i++) {
if(dir == (i + 2) % 4) continue;
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || nx >= n || ny < 0 || ny >= m || qizi[nx][ny] == '#') continue;
// cerr << mp[nx * m + ny] << endl;
if(mp[nx * m + ny] > d + 1) {
v[mp[nx * m + ny]].push_back({i, nx * m + ny});
} else {
pq.push_back({d + 1, i, nx * m + ny});
}
// cout << nx << " " << ny << endl;
}
}
int tim = k - 2;
tim = max(0, tim);
queue<tuple<int,int,int>> q;
q.push({snack[0].first, snack[0].second, tim});
vector<int> dis(n * m, inf);
dis[snack[0].first * m + snack[0].second] = tim;
while(!q.empty()) {
auto [x, y, d] = q.front();
q.pop();
for(int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || nx >= n || ny < 0 || ny >= m || qizi[nx][ny] == '#') continue;
if(dis[nx * m + ny] == inf){
dis[nx * m + ny] = min(d + 1, dis[nx * m + ny]);
q.push({nx, ny, d + 1});
}
}
}
ull res = 0;
for(int i = 0; i < n * m; i++) {
int ans = dis[i];
for(int j = 0; j < 4; j++) {
ans = min(ans, f[i][j]);
}
if(ans == inf) {
ans = 0;
}
// cerr << ans << " \n"[(i + 1) % m == 0];
res += 1ll * ans * ans;
}
cout << res << "\n";
}
signed main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int tt = 1;
// std::cin >> tt;
while (tt--)
solve();
}
Details
answer.code: In function ‘void solve()’: answer.code:9:13: error: expected primary-expression before ‘long’ 9 | #define int long long | ^~~~ answer.code:49:32: note: in expansion of macro ‘int’ 49 | for(int i = 0; i < int(v[d].size()); i++) { | ^~~ answer.code:49:31: error: expected ‘;’ before ‘long’ 49 | for(int i = 0; i < int(v[d].size()); i++) { | ^ | ; answer.code:9:13: error: expected primary-expression before ‘long’ 9 | #define int long long | ^~~~ answer.code:49:32: note: in expansion of macro ‘int’ 49 | for(int i = 0; i < int(v[d].size()); i++) { | ^~~ answer.code:49:31: error: expected ‘)’ before ‘long’ 49 | for(int i = 0; i < int(v[d].size()); i++) { | ~ ^ | ) answer.code:9:13: error: expected primary-expression before ‘long’ 9 | #define int long long | ^~~~ answer.code:49:32: note: in expansion of macro ‘int’ 49 | for(int i = 0; i < int(v[d].size()); i++) { | ^~~ answer.code:49:50: error: ‘i’ was not declared in this scope 49 | for(int i = 0; i < int(v[d].size()); i++) { | ^ answer.code:79:14: error: no matching function for call to ‘max(int, long long int&)’ 79 | tim = max(0, tim); | ~~~^~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:2: /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: answer.code:79:14: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’) 79 | tim = max(0, tim); | ~~~^~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: answer.code:79:14: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’) 79 | tim = max(0, tim); | ~~~^~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: answer.code:79:14: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘int’ 79 | tim = max(0, tim); | ~~~^~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: answer.code:79:14: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘int’ 79 | tim = max(0, tim); | ~~~^~~~~~~~