Submission #1174162

#TimeUsernameProblemLanguageResultExecution timeMemory
1174162lopkusFurniture (JOI20_furniture)C++20
5 / 100
5089 ms1136 KiB
#include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; void solve() { int n, m; std::cin >> n >> m; std::vector<std::vector<int>> a(n + 1, std::vector<int>(m + 1)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { std::cin >> a[i][j]; } } int q; std::cin >> q; while(q--) { int x, y; std::cin >> x >> y; std::vector<std::vector<int>> b(n + 1, std::vector<int>(m + 1)); std::vector<std::vector<int>> dp(n + 1, std::vector<int>(m + 1)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { b[i][j] = a[i][j]; } } b[x][y] ^= 1; dp[1][1] = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(i == 1 && j == 1) { continue; } if(b[i][j]) { continue; } if(j - 1 > 0 && b[i][j - 1] == 0) { dp[i][j] |= dp[i][j - 1]; } if(i - 1 > 0 && b[i - 1][j] == 0) { dp[i][j] |= dp[i - 1][j]; } } } std::cout << dp[n][m] << "\n"; if(dp[n][m]) { a[x][y] ^= 1; } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; //std::cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...