Submission #1278560

#TimeUsernameProblemLanguageResultExecution timeMemory
1278560wedonttalkanymoreRobots (APIO13_robots)C++20
Compilation error
0 ms0 KiB
#pragma GCC target("avx") #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #include <bits/stdc++.h> /* Wake up, I'm wake up Thu sang roi, em thay khong? */ using namespace std; using ll = long long; // #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 5e2 + 5, inf = 1e9, mod = 1e9 + 7, block = 320, lim = 19; int n, w, h; char a[N][N]; int dx[] = {-1, 0, 1, 0}; // tren, phai, duoi, trai int dy[] = {0, 1, 0, -1}; pii pre[N][N][4]; int dp[N][N][10][10]; pii dfs(int x, int y, int k) { // cout << x << ' ' << y << ' ' << k << '\n'; // cout << pre[x][y][k].se << '\n'; if (pre[x][y][k].se == -1) { int nx = 0, ny = 0, nk = k; pre[x][y][k].se = 0; if (a[x][y] == 'A') { nk = (k + 3) % 4; } else if (a[x][y] == 'C') { nk = (k + 1) % 4; } // if (x == 2 && y == 2 && k == 2) cout << "at: " << k << ' ' << nk << '\n'; nx = x + dx[nk]; ny = y + dy[nk]; // cout << "now: " << nx << ' ' << ny << ' ' << nk << '\n'; if (nx < 1 || ny < 1 || nx > h || ny > w || a[nx][ny] == 'x') { pre[x][y][k] = make_pair(x, y); } else pre[x][y][k] = dfs(nx, ny, nk); } return pre[x][y][k]; } void precompute() { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int k = 0; k < 4; k++) { pre[i][j][k] = make_pair(-1, -1); } } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int k = 0; k < 4; k++) { dfs(i, j, k); } } } // dfs(1, 1, 2); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int k = 0; k < 4; k++) { // cout << i << ' ' << j << ' ' << k << '\n'; // cout << "now: " << pre[i][j][k].fi << ' ' << pre[i][j][k].se << '\n'; } } } } struct item { int x, y, L, R, val; bool operator <(const item &other) const { return val > other.val; } }; void dijkstra(int len) { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int R = len; R <= n; R++) { int L = R - len + 1; dp[i][j][L][R] = inf; } } } priority_queue <item> q; if (len == 1) { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int R = 1; R <= n; R++) { if (a[i][j] - '0' == R) { dp[i][j][R][R] = 0; // if (len == 1) cout << i << ' ' << j << ' ' << R << '\n'; q.push({i, j, R, R, 0}); } } } } } else { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int R = len; R <= n; R++) { int L = R - len + 1; int val = inf; for (int k = L; k < R; k++) { val = min(val, dp[i][j][L][k] + dp[i][j][k + 1][R]); } if (val < inf) { dp[i][j][L][R] = val; q.push({i, j, L, R, val}); } } } } } while(q.size()) { auto [x, y, L, R, val] = q.top(); q.pop(); if (dp[x][y][L][R] < val) continue; for (int i = 0; i < 4; i++) { int nx = pre[x][y][i].fi, ny = pre[x][y][i].se; if (dp[nx][ny][L][R] > dp[x][y][L][R] + 1) { dp[nx][ny][L][R] = dp[x][y][L][R] + 1; q.push({nx, ny, L, R, dp[nx][ny][L][R]}); } } } } void solve() { for (int len = 1; len <= n; len++) { dijkstra(len); } int ans = inf; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { // cout << i << ' ' << j << ' ' << dp[i][j][1][n] << '\n'; ans = min(ans, dp[i][j][1][n]); } } cout << (ans >= inf ? -1 : ans); } signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n >> w >> h; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; } } precompute(); solve(); return 0; }

Compilation message (stderr)

robots.cpp:22:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   22 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
robots.cpp:29:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   29 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
robots.cpp:31:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   31 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
robots.cpp:45:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   45 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
robots.cpp:70:28: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   70 | pii dfs(int x, int y, int k) {
      |                            ^
robots.cpp:70:28: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:70:28: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:70:28: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp:94:17: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   94 | void precompute() {
      |                 ^
robots.cpp:94:17: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:94:17: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:94:17: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp:122:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  122 |     bool operator <(const item &other) const {
      |                                        ^~~~~
robots.cpp:122:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:122:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:122:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp:127:22: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  127 | void dijkstra(int len) {
      |                      ^
robots.cpp:127:22: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:127:22: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:127:22: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp:181:12: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  181 | void solve() {
      |            ^
robots.cpp:181:12: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:181:12: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:181:12: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp:195:13: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  195 | signed main() {
      |             ^
robots.cpp:195:13: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
robots.cpp:195:13: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
robots.cpp:195:13: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
robots.cpp: In function 'int main()':
robots.cpp:199:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  199 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
robots.cpp:200:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  200 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from robots.cpp:48:
/usr/include/c++/13/bits/allocator.h: In destructor 'constexpr std::_Vector_base<item, std::allocator<item> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = item]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~