Submission #899408

# Submission time Handle Problem Language Result Execution time Memory
899408 2024-01-06T04:44:04 Z Keys Furniture (JOI20_furniture) C++14
0 / 100
2 ms 2636 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define mp make_pair
#define ar array
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define trav(i, a) for (auto& i : a)
template <class T> istream &operator>>(istream& in, vector<T> &v) {trav(i, v) in >> i; return in;}
 
#ifdef LOCAL
#include "../../lib/debug.h"
#else
#define dbg(...)
#endif
 
const int N = 1000 + 5;
int a[N][N]; // maintain whether we can reach end
int d[2 * N];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m;
 
void upd(int x, int y) {
  d[x + y]--;
  a[x][y] = 1;
  FOR(i, 0, 4) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (!(nx <= 0 or nx > n or ny <= 0 or ny > m) and !a[nx][ny] and
        (a[nx + 1][ny] and a[nx][ny + 1] and mp(nx, ny) != mp(n, m) or a[nx - 1][ny] and a[nx][ny - 1] and mp(nx, ny) != mp(1ll, 1ll))) {
      upd(nx, ny);
    }
  }
}
 
 
signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n >> m;
  FOR(i, 0, n + 2) FOR(j, 0, m + 2) a[i][j] = 1;
  FOR(i, 1, n + 1) FOR(j, 1, m + 1) {
    a[i][j] = 0;
    d[i + j]++;
  }
 
  FOR(i, 1, n + 1) FOR(j, 1, m + 1) {
    int x; cin >> x;
    if (x) upd(i, j);
  }
  // FOR(i, 1, n + 1) {FOR(j, 1, m + 1) cout << a[i][j] << " "; cout << endl;}
 
  int q; cin >> q; while (q--) {
    int i, j; cin >> i >> j; 
    if (a[i][j] == 1) cout << 1 << endl;
    else if (d[i + j] == 1) cout << 0 << endl;
    else cout << 1 << endl, upd(i, j);
  }
}

Compilation message

furniture.cpp: In function 'void upd(long long int, long long int)':
furniture.cpp:39:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   39 |         (a[nx + 1][ny] and a[nx][ny + 1] and mp(nx, ny) != mp(n, m) or a[nx - 1][ny] and a[nx][ny - 1] and mp(nx, ny) != mp(1ll, 1ll))) {
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2520 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2520 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -