T3000

Untitled

Apr 7th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int main()
  7. {
  8.     ll t;
  9.     cin >> t;
  10.     while (t-- > 0)
  11.     {
  12.         ll r, c;
  13.         cin >> r >> c;
  14.         vector<string> z1(r);                  // store keypad information
  15.         vector<string> ans(r, string(c, 'N')); // for the visual output
  16.         vector<string> ch(r, string(c, 'N'));  // for checking the existents of a button
  17.         vector<ll> rw;
  18.         vector<ll> cl;
  19.         for (int i = 0; i < r; i++)
  20.         {
  21.             cin >> z1.at(i);
  22.         }
  23.         for (int i = 0; i < r; i++)
  24.         {
  25.             int hp = 0;
  26.             for (int j = 0; j < c; j++)
  27.             {
  28.                 if (hp >= 2)
  29.                 {
  30.                     break;
  31.                 }
  32.                 if (z1.at(i).at(j) == '1')
  33.                 {
  34.                     hp += 1;
  35.                 }
  36.             }
  37.             if (hp >= 2)
  38.             {
  39.                 rw.push_back(1);
  40.             }
  41.             else
  42.             {
  43.                 rw.push_back(0);
  44.             }
  45.         }
  46.         for (int i = 0; i < c; i++)
  47.         {
  48.             int hp = 0;
  49.             for (int j = 0; j < r; j++)
  50.             {
  51.                 if (hp == 2)
  52.                 {
  53.                     break;
  54.                 }
  55.                 if (z1.at(j).at(i) == '1')
  56.                 {
  57.                     hp += 1;
  58.                 }
  59.             }
  60.             if (hp >= 2)
  61.             {
  62.                 cl.push_back(1);
  63.             }
  64.             else
  65.             {
  66.                 cl.push_back(0);
  67.             }
  68.         }
  69.         for (int i = 0; i < r; i++)
  70.         {
  71.             for (int j = 0; j < c; j++)
  72.             {
  73.                 if (z1.at(i).at(j) == '1')
  74.                 {
  75.                     if (rw.at(i) == 1 && cl.at(j) == 1)
  76.                     {
  77.                         ans.at(i).at(j) = 'I';
  78.                     }
  79.                     else if (rw.at(i) == 1)
  80.                     {
  81.                         ans.at(i).at(j) = 'P';
  82.                     }
  83.                 }
  84.             }
  85.         }
  86.         if (ans == ch)
  87.         {
  88.             cout << "impossible" << endl;
  89.         }
  90.         else
  91.         {
  92.             for (int i = 0; i < r; i++)
  93.             {
  94.                 cout << ans.at(i) << endl;
  95.             }
  96.         }
  97.  
  98.         cout << "----------" << endl;
  99.     }
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment