Submission #641145

#TimeUsernameProblemLanguageResultExecution timeMemory
641145maks007Game (eJOI20_game)C++14
0 / 100
1 ms296 KiB
#include "bits/stdc++.h" signed main () { int n, m; scanf("%d%d", &n, &m); char a[n + 1][m], b[n][m + 1]; for(int i = 0; i <= n; i ++) { for(int j = 0; j < m; j ++) std::cin >> a[i][j]; } for(int i = 0; i < n; i ++) { for(int j = 0; j <= m; j ++) std::cin >> b[i][j]; } std::queue <std::pair <int,int>> q; int used[n][m]; memset(used, 0, sizeof(used)); int deg[n][m]; memset(deg, 0, sizeof(deg)); for(int i = 0; i < n; i ++ ) { for(int j = 0; j < m; j ++) { deg[i][j] += (a[i][j] == '1') + (a[i+1][j] == '1') + (b[i][j] == '1') + (b[i][j + 1] == '1'); } } int cnt = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { if(used[i][j] || deg[i][j] == 4) continue; used[i][j] = cnt; q.push({i, j}); while(!q.empty()) { std::pair <int,int> v = q.front(); q.pop(); if(b[v.first][v.second] != '1') { int ni = v.first, nj = v.second-1; if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) { q.push({ni, nj}); used[ni][nj] = cnt; } } if(b[v.first][v.second + 1] != '1') { int ni = v.first, nj = v.second + 1; if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) { q.push({ni, nj}); used[ni][nj] = cnt; } } if(a[v.first][v.second] != '1') { int ni = v.first - 1, nj = v.second; if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) { q.push({ni, nj}); used[ni][nj] = cnt; } } if(a[v.first + 1][v.second] != '1') { int ni = v.first + 1, nj = v.second; if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) { q.push({ni, nj}); used[ni][nj] = cnt; } } } cnt ++; } } int cnt1 = 0, cnt2 = 0; for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { if(used[i][j] == 1) cnt1 ++; else if(used[i][j] == 2) cnt2 ++; // printf("%d ", used[i][j]); } // printf("\n"); } printf("%d", std::max(cnt1, cnt2) - std::min(cnt1, cnt2)); return 0; }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
#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...