Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- int main()
- {
- ll t;
- cin >> t;
- while (t-- > 0)
- {
- ll r, c;
- cin >> r >> c;
- vector<string> z1(r); // store keypad information
- vector<string> ans(r, string(c, 'N')); // for the visual output
- vector<string> ch(r, string(c, 'N')); // for checking the existents of a button
- vector<ll> rw;
- vector<ll> cl;
- for (int i = 0; i < r; i++)
- {
- cin >> z1.at(i);
- }
- for (int i = 0; i < r; i++)
- {
- int hp = 0;
- for (int j = 0; j < c; j++)
- {
- if (hp >= 2)
- {
- break;
- }
- if (z1.at(i).at(j) == '1')
- {
- hp += 1;
- }
- }
- if (hp >= 2)
- {
- rw.push_back(1);
- }
- else
- {
- rw.push_back(0);
- }
- }
- for (int i = 0; i < c; i++)
- {
- int hp = 0;
- for (int j = 0; j < r; j++)
- {
- if (hp == 2)
- {
- break;
- }
- if (z1.at(j).at(i) == '1')
- {
- hp += 1;
- }
- }
- if (hp >= 2)
- {
- cl.push_back(1);
- }
- else
- {
- cl.push_back(0);
- }
- }
- for (int i = 0; i < r; i++)
- {
- for (int j = 0; j < c; j++)
- {
- if (z1.at(i).at(j) == '1')
- {
- if (rw.at(i) == 1 && cl.at(j) == 1)
- {
- ans.at(i).at(j) = 'I';
- }
- else if (rw.at(i) == 1)
- {
- ans.at(i).at(j) = 'P';
- }
- }
- }
- }
- if (ans == ch)
- {
- cout << "impossible" << endl;
- }
- else
- {
- for (int i = 0; i < r; i++)
- {
- cout << ans.at(i) << endl;
- }
- }
- cout << "----------" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment