Submission #649399

# Submission time Handle Problem Language Result Execution time Memory
649399 2022-10-10T07:32:47 Z BackNoob Furniture (JOI20_furniture) C++14
0 / 100
1 ms 724 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()

using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;

template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

int n;
int m;
int numq;
int a[1007][1007];
int f[mxN];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<pair<int, int>> q;

bool ok(int x, int y)
{
    return (1 <= x && x <= n && 1 <= y && y <= m);
}

bool add(int x, int y)
{
    if(a[x][y] == 1) return 1;
    if(f[x + y] == 1) return 0;

    a[x][y] = 1;
    f[x + y]--;

    while(!q.empty()) {
        int u = q.front().fi;
        int v = q.front().se;
        q.pop();

        if(a[x - 1][y + 1] == 1) {

            if(ok(x - 1, y) == true && a[x - 1][y] == 0) {
                a[x - 1][y] = 1;
                f[x - 1 + y]--;
                q.push({x - 1, y});
            }
            if(ok(x, y + 1) == true && a[x][y + 1] == 0) {
                a[x][y + 1] = 1;
                f[x + y + 1]--;
                q.push({x, y + 1});
            }

        }
        if(a[x + 1][y - 1] == 1) {
            if(ok(x, y - 1) == true && a[x][y - 1] == 0) {
                a[x][y - 1] = 1;
                f[x + y - 1]--;
                q.push({x + 1, y - 1});
            }
            if(ok(x + 1, y) == true && a[x + 1][y] == 0) {
                a[x + 1][y] = 1;
                f[x + 1 + y]--;
                q.push({x + 1, y});
            }
        }
    }
    return true;
}

void solve()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= m; j++) f[i + j]++;

    for(int i = 0; i <= n + 1; i++)
    for(int j = 0; j <= m + 1; j++) {
        if(1 <= i && i <= n && 1 <= j && j <= m) continue;
        a[i][j] = 1;
    }

    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= m; j++) {
        int x;
        cin >> x;
        if(x == 1) add(i, j);
    }

    cin >> numq;
    while(numq--) {
        int x, y;
        cin >> x >> y;
        cout << add(x, y) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(TASK".inp" , "r" , stdin);
    //freopen(TASK".out" , "w" , stdout);

    int tc = 1;
    //cin >> tc;
    while(tc--) {
    	solve();
    }
    return 0;
}

Compilation message

furniture.cpp: In function 'bool add(int, int)':
furniture.cpp:53:13: warning: unused variable 'u' [-Wunused-variable]
   53 |         int u = q.front().fi;
      |             ^
furniture.cpp:54:13: warning: unused variable 'v' [-Wunused-variable]
   54 |         int v = q.front().se;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -