Submission #536347

# Submission time Handle Problem Language Result Execution time Memory
536347 2022-03-13T02:19:59 Z Monarchuwu Furniture (JOI20_furniture) C++17
0 / 100
20 ms 1236 KB
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 1000 + 3, mod = 1e9 + 2277;
int m, n;
int c[N][N];

void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; }
ll dp[2][N][N];
void build() {
    dp[0][1][1] = dp[1][m][n] = 1;

    for (int i = 1; i <= m; ++i)
        for (int j = (i == 1 ? 2 : 1); j <= n; ++j) {
            dp[0][i][j] = 0;
            if (!c[i][j]) {
                add(dp[0][i][j], dp[0][i - 1][j]);
                add(dp[0][i][j], dp[0][i][j - 1]);
            }
        }

    for (int i = m; i; --i)
        for (int j = (i == m ? n - 1 : n); j; --j) {
            dp[1][i][j] = 0;
            if (!c[i][j]) {
                add(dp[1][i][j], dp[1][i + 1][j]);
                add(dp[1][i][j], dp[1][i][j + 1]);
            }
        }
}

bool check(int i, int j) {
    return dp[0][i][j] && dp[1][i][j] && dp[0][i][j] * dp[1][i][j] % mod != dp[0][m][n];
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> m >> n;
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j) cin >> c[i][j];
    build();

    int q, i, j; cin >> q; while (q--) {
        cin >> i >> j;
        if (check(i, j)) {
            cout << "1\n";
            c[i][j] = 1;
            build();
        }
        else cout << "0\n";
    }
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -