Submission #715718

#TimeUsernameProblemLanguageResultExecution timeMemory
715718hamidh100Furniture (JOI20_furniture)C++17
100 / 100
891 ms58288 KiB
/* In the name of God */ #include <iostream> #include <iomanip> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string> #include <string.h> #include <algorithm> #include <bitset> #include <vector> #include <stack> #include <queue> #include <set> #include <list> #include <map> #include <numeric> #include <limits> #include <limits.h> #include <unordered_map> #include <unordered_set> #include <chrono> #include <random> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef map<int, int> MPII; typedef vector<int> VI; typedef vector<ll> VL; #define PB push_back #define POP pop_back #define MP make_pair #define all(a) (a).begin(), (a).end() #define endl '\n' #define dbg(x) cerr << '[' << #x << ": " << x << "]\n" #define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n" #define Yes cout << "Yes\n" #define YES cout << "YES\n" #define No cout << "No\n" #define NO cout << "NO\n" const ll INF = (ll)2e18 + 1386; const ld eps = 0.000000000000001; const int MOD = 1e9 + 7; inline int mod_(int a){ int res = a + MOD; return (res >= MOD? res - MOD : res); } inline int mod_add(int a, int b){ int res = a + b; return (res >= MOD? res - MOD : res); } inline int mod_neg(int a, int b){ int res = (abs(a - b) < MOD? a - b : (a - b) % MOD); return (res < 0? res + MOD : res); } inline int mod_mlt(int a, int b){ return (1ll * a * b % MOD); } inline string intToString(ll a){ char x[100]; sprintf(x, "%lld", a); string s = x; return s; } inline ll stringToInt(string s){ ll res; char x[100]; strcpy(x, s.c_str()); sscanf(x, "%lld", &res); return res; } inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); } const int MAXN = 1002; int n, m, deg1[MAXN][MAXN], degn[MAXN][MAXN]; bool a[MAXN][MAXN]; set<PII> goodie[2 * MAXN]; void upd(int x, int y){ queue<PII> q; if (deg1[x][y]){ deg1[x][y] = 0; q.push({x, y}); } while (!q.empty()){ auto v = q.front(); int xx = v.first, yy = v.second; q.pop(); goodie[xx + yy].erase(MP(xx, yy)); deg1[xx + 1][yy]--, deg1[xx][yy + 1]--; if (deg1[xx + 1][yy] == 0 && xx + 1 <= n) q.push({xx + 1, yy}); if (deg1[xx][yy + 1] == 0 && yy + 1 <= m) q.push({xx, yy + 1}); } if (degn[x][y]){ degn[x][y] = 0; q.push({x, y}); } while (!q.empty()){ auto v = q.front(); int xx = v.first, yy = v.second; q.pop(); goodie[xx + yy].erase(MP(xx, yy)); degn[xx - 1][yy]--, degn[xx][yy - 1]--; if (degn[xx - 1][yy] == 0 && xx - 1 >= 1) q.push({xx - 1, yy}); if (degn[xx][yy - 1] == 0 && yy - 1 >= 1) q.push({xx, yy - 1}); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ deg1[i][j] = degn[i][j] = 2; goodie[i + j].insert(MP(i, j)); } deg1[i][1] = 1; degn[i][m] = 1; } fill(deg1[1], deg1[1] + m + 1, 1), fill(degn[n], degn[n] + m + 1, 1); for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ cin >> a[i][j]; if (a[i][j] == 1) upd(i, j); } } int q; cin >> q; while (q--){ int x, y; cin >> x >> y; int sz = goodie[x + y].size(); bool another = (sz > 1 || (sz == 1 && goodie[x + y].count(MP(x, y)) == 0)); cout << another << endl; if (another) upd(x, y); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...