Submission #536348

#TimeUsernameProblemLanguageResultExecution timeMemory
536348MonarchuwuFurniture (JOI20_furniture)C++17
5 / 100
5076 ms21832 KiB
#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] % 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 (!dp[0][i][j] || !dp[1][i][j]) { cout << "1\n"; continue; } if (check(i, j)) { cout << "1\n"; c[i][j] = 1; build(); } else cout << "0\n"; } } /** /\_/\ * (= ._.) * / >0 \>1 **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...