Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- vector<vector<char>> dp;
- int n, m;
- void foo(int a, int b) {
- for (int i = 0; i < a; i++) dp[i][b] = 1;
- for (int i = 0; i < b; i++) dp[a][i] = 1;
- for (int i = a - 1, j = b - 1; i >= 0 && j >= 0; i--, j--) dp[i][j] = 1;
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- fin >> n >> m;
- dp.assign(n, vector<char>(m, -1));
- dp[n - 1][m - 1] = 0;
- for (int i = n - 1; i >= 0; i--) {
- for (int j = m - 1; j >= 0; j--) {
- if (dp[i][j] == 0)
- foo(i, j);
- else if (dp[i][j] == -1) {
- bool foo = 1;
- for (int k = i + 1; k < n; k++)
- if (dp[k][j] != 1)
- foo = 0;
- for (int k = j + 1; k < m; k++)
- if (dp[i][k] != 1)
- foo = 0;
- for (int k = i + 1, g = j + 1; k < n && g < m; k++, g++)
- if (dp[k][g] != 1)
- foo = 0;
- if (foo)
- dp[i][j] = 0;
- else
- dp[i][j] = 1;
- }
- }
- }
- fout << (dp[0][0] ? 1 : 2) << endl;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment