Submission #681553

#TimeUsernameProblemLanguageResultExecution timeMemory
681553peijarFurniture (JOI20_furniture)C++17
100 / 100
301 ms27756 KiB
#include <bits/stdc++.h> #define int long long using namespace std; namespace std { template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { out << "["; for (int i = 0; i < (int)vec.size(); ++i) { out << vec[i]; if (i + 1 < (int)vec.size()) out << ", "; } return out << "]"; } } // namespace std void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int nbLig, nbCol; cin >> nbLig >> nbCol; vector<int> onDiag(nbLig + nbCol - 1); vector<vector<bool>> isUseful(nbLig, vector<bool>(nbCol, true)); vector<vector<int>> cntReach(nbLig, vector<int>(nbCol)); vector<vector<int>> cntReachRev(nbLig, vector<int>(nbCol)); for (int lig = 0; lig < nbLig; ++lig) for (int col = 0; col < nbCol; ++col) { if (lig + 1 < nbLig) cntReach[lig + 1][col]++, cntReachRev[lig][col]++; if (col + 1 < nbCol) cntReach[lig][col + 1]++, cntReachRev[lig][col]++; onDiag[lig + col] += 1; } auto tryDisable = [&](int lig, int col) { if (!isUseful[lig][col]) return true; if (onDiag[lig + col] == 1) return false; queue<pair<int, int>> q; q.emplace(lig, col); while (!q.empty()) { auto [r, c] = q.front(); q.pop(); assert(isUseful[r][c]); isUseful[r][c] = false; onDiag[r + c]--; // try right if (c + 1 < nbCol) { cntReach[r][c + 1]--; if (!cntReach[r][c + 1] and isUseful[r][c + 1]) q.emplace(r, c + 1); } // try bot if (r + 1 < nbLig) { cntReach[r + 1][c]--; if (!cntReach[r + 1][c] and isUseful[r + 1][c]) q.emplace(r + 1, c); } // try left if (c > 0) { cntReachRev[r][c - 1]--; if (!cntReachRev[r][c - 1] and isUseful[r][c - 1]) q.emplace(r, c - 1); } // try top if (r > 0) { cntReachRev[r - 1][c]--; if (!cntReachRev[r - 1][c] and isUseful[r - 1][c]) q.emplace(r - 1, c); } } return true; }; for (int lig = 0; lig < nbLig; ++lig) for (int col = 0; col < nbCol; ++col) { int x; cin >> x; if (x) assert(tryDisable(lig, col)); } int q; cin >> q; for (int i = 0; i < q; ++i) { for (int lig = 0; lig < nbLig; ++lig) dbg(isUseful[lig]); dbg(onDiag); int lig, col; cin >> lig >> col; --lig, --col; cout << tryDisable(lig, col) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...