Submission #1269395

#TimeUsernameProblemLanguageResultExecution timeMemory
1269395quangminh412Furniture (JOI20_furniture)C++17
100 / 100
156 ms10288 KiB
/*
  Ben Watson

  stuang Minh MasterDDDDD
*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long

const string name = "test";

void solve();
signed main()
{
    if (fopen((name + ".inp").c_str(), "r"))
    {
        freopen((name + ".inp").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();

    return 0;
}

// main program
const int maxn = 1e3 + 2;

int c[maxn][maxn], R[maxn][maxn], cnt[2 * maxn];
int n, m, q;

stack<pair<int, int>> st;
void ins(int u, int v)
{
    if (R[u][v] == 1)
        return;
    R[u][v] = 1;
    cnt[u + v]--;
    st.push({u, v});
}

int update(int u, int v)
{
    if (R[u][v] == 1)
        return 1;
    if (cnt[u + v] == 1)
        return 0;

    ins(u, v);
    while (!st.empty())
    {
        int x = st.top().first, y = st.top().second;
        st.pop();

        if (R[x - 1][y + 1] == 1)
        {
            ins(x - 1, y);
            ins(x, y + 1);
        }
        if (R[x + 1][y - 1] == 1)
        {
            ins(x, y - 1);
            ins(x + 1, y);
        }
    }
    return 1;
}

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

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            cin >> c[i][j];
            if (c[i][j] == 1)
                update(i, j);
        }

    cin >> q;
    while (q--)
    {
        int x, y; cin >> x >> y;

        cout << update(x, y) << '\n';
    }
}

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...