Submission #256106

#TimeUsernameProblemLanguageResultExecution timeMemory
256106tomsydT-Covering (eJOI19_covering)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,int>> pos; vector<pair<int,int>> dir = {{1,0},{0,-1},{-1,0},{0,1}}; vector<vector<bool>> notin; vector<vector<int>> grid; int n,m; int solve(int idx, int crt_ans){ if (idx == pos.size()) return crt_ans; int ans = -1, A = pos[idx].first, B = pos[idx].second; if (notin[A][B]) return 0; notin[A][B] = true; for (int j=0; j<4; ++j){ int a = crt_ans+grid[A][B]; for (int k=0; k<3; ++k){ int AA = A+dir[(j+k)%4].first, BB = B+dir[(j+k)%4].second; if (AA >= n or BB >= m or AA < 0 or BB < 0 or notin[AA][BB]){ a = -1; break; } a += grid[AA][BB]; } if (a == -1) continue; for (int i=0; i<3; ++i){ notin[A+dir[(j+i)%4].first][B+dir[(j+i)%4].second] = true; } ans = max(ans,solve(idx+1,a)); for (int i=0; i<3; ++i){ notin[A+dir[(j+i)%4].first][B+dir[(j+i)%4].second] = false; } } notin[A][B] = false; return ans; } bool check(){ for (int i=0; i<pos.size(); ++i){ for (int j=i+1; j<pos.size(); ++j){ if (abs(pos[i].first-pos[j].first) <= 1 or abs(pos[i].second-pos[j].second) <= 1) return false; } } return true; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; grid = vector<vector<int>>(n,vector<int>(m)); notin = vector<vector<bool>>(n,vector<bool>(m)); for (int i=0; i<n; ++i){ for (int j=0; j<m; ++j){ cin >> grid[i][j]; } } int q; cin >> q; for (int i=0; i<q; ++i){ int x,y; cin >> x >> y; pos.emplace_back(x,y); } if (pos.size() > 2){ cout << "No"; return 0; } // if (check()){ /* { int ans = 0; for (int i=0; i<q; ++i){ int best = -1; for (int j=0; j<4; ++j){ int A = grid[pos[i].first][pos[i].second]; for (int a=0; a<3; ++a){ int AA = pos[i].first+dir[(a+j)%4].first, BB = pos[i].second+dir[(a+j)%4].second; if (AA < 0 or BB < 0 or AA >= n or BB >= m){ A = -1; break; } A += grid[AA][BB]; } best = max(best,A); } if (best == -1){ ans = -1; break; } ans += best; } if (ans == -1) cout << "No"; else cout << ans; return 0; // } } */ int ans = solve(0,0); if (ans == -1) cout << "No" << '\n'; else cout << ans << '\n'; return 0; }

Compilation message (stderr)

covering.cpp: In function 'int solve(int, int)':
covering.cpp:11:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (idx == pos.size()) return crt_ans;
      ~~~~^~~~~~~~~~~~~
covering.cpp: In function 'bool check()':
covering.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<pos.size(); ++i){
                ~^~~~~~~~~~~
covering.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=i+1; j<pos.size(); ++j){
                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...