Submission #649398

# Submission time Handle Problem Language Result Execution time Memory
649398 2022-10-10T07:30:24 Z BackNoob Furniture (JOI20_furniture) C++14
0 / 100
2 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 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(a[x - 1][y] == 0) {
                a[x - 1][y] = 1;
                f[x - 1 + y]--;
                q.push({x - 1, y});
            }
            if(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(a[x][y - 1] == 0) {
                a[x][y - 1] = 1;
                f[x + y - 1]--;
                q.push({x + 1, y - 1});
            }
            if(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:48:13: warning: unused variable 'u' [-Wunused-variable]
   48 |         int u = q.front().fi;
      |             ^
furniture.cpp:49:13: warning: unused variable 'v' [-Wunused-variable]
   49 |         int v = q.front().se;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 2 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 2 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -