Submission #112514

#TimeUsernameProblemLanguageResultExecution timeMemory
112514KastandaWall (CEOI14_wall)C++11
30 / 100
863 ms20196 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 44, K = 10; int n, m, vert[N][N], horz[N][N], F[N][N]; ll dp[N][N][1 << K]; priority_queue < pair < ll , int > > Pq; inline void Relax(int a, int b, int mask, ll d) { if (dp[a][b][mask] > d) { dp[a][b][mask] = d; Pq.push(make_pair(- d, (mask << 12) | (b << 6) | a)); } } int main() { scanf("%d%d", &n, &m); vector < pair < int , int > > vec; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int b; scanf("%d", &b); if (b) vec.push_back({i, j}); } for (int i = 0; i < n; i++) for (int j = 0; j <= m; j++) scanf("%d", &vert[i][j]); for (int i = 0; i <= n; i++) for (int j = 0; j < m; j++) scanf("%d", &horz[i][j]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { for (int h = 0; h < (int)vec.size(); h++) if (vec[h].first >= i && vec[h].second == j) F[i][j] ^= 1 << h; } assert((int)vec.size() <= 10); memset(dp, 63, sizeof(dp)); dp[0][0][0] = 0; Pq.push({0, 0}); while (Pq.size()) { int d, a, b, mask, tmp; d = - Pq.top().first; tmp = Pq.top().second; a = tmp & 63; tmp >>= 6; b = tmp & 63; tmp >>= 6; mask = tmp; Pq.pop(); if (d > dp[a][b][mask]) continue; // Up : if (a > 0) Relax(a - 1, b, mask, d + vert[a - 1][b]); // Down : if (a < n) Relax(a + 1, b, mask, d + vert[a][b]); // Left : if (b > 0) Relax(a, b - 1, mask ^ F[a][b - 1], d + horz[a][b - 1]); // Right : if (b < m) Relax(a, b + 1, mask ^ F[a][b], d + horz[a][b]); } return !printf("%lld\n", dp[0][0][(1 << (int)vec.size()) - 1]); }

Compilation message (stderr)

wall.cpp: In function 'int main()':
wall.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
wall.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &b);
    ~~~~~^~~~~~~~~~
wall.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &vert[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
wall.cpp:33:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &horz[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...