Raslboyy

113079

Sep 14th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<vector<char>> dp;
  8. int n, m;
  9.  
  10. void foo(int a, int b) {
  11.     for (int i = 0; i < a; i++) dp[i][b] = 1;
  12.     for (int i = 0; i < b; i++) dp[a][i] = 1;
  13.     for (int i = a - 1, j = b - 1; i >= 0 && j >= 0; i--, j--) dp[i][j] = 1;
  14. }
  15.  
  16. int main() {
  17.     ifstream fin("input.txt");
  18.     ofstream fout("output.txt");
  19.  
  20.     fin >> n >> m;
  21.     dp.assign(n, vector<char>(m, -1));
  22.     dp[n - 1][m - 1] = 0;
  23.     for (int i = n - 1; i >= 0; i--) {
  24.         for (int j = m - 1; j >= 0; j--) {
  25.             if (dp[i][j] == 0)
  26.                 foo(i, j);
  27.             else if (dp[i][j] == -1) {
  28.                 bool foo = 1;
  29.                 for (int k = i + 1; k < n; k++)
  30.                     if (dp[k][j] != 1)
  31.                         foo = 0;
  32.                 for (int k = j + 1; k < m; k++)
  33.                     if (dp[i][k] != 1)
  34.                         foo = 0;
  35.                 for (int k = i + 1, g = j + 1; k < n && g < m; k++, g++)
  36.                     if (dp[k][g] != 1)
  37.                         foo = 0;
  38.                 if (foo)
  39.                     dp[i][j] = 0;
  40.                 else
  41.                     dp[i][j] = 1;
  42.             }
  43.                
  44.                    
  45.         }
  46.     }
  47.     fout << (dp[0][0] ? 1 : 2) << endl;
  48.  
  49.     fin.close();
  50.     fout.close();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment