Skip to content

Commit

Permalink
Madoka and Childish Pranks
Browse files Browse the repository at this point in the history
Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of n rows and m columns, consisting only of zeroes and ones. The coordinate of the cell in the i-th row and the j-th column (1≤i≤n, 1≤j≤m) is (i,j).

One day she saw a picture "Mahou Shoujo Madoka Magica" and decided to draw it on her wall. Initially, the Madoka's table is a table of size n×m filled with zeroes. Then she applies the following operation any number of times:

Madoka selects any rectangular subtable of the table and paints it in a chess coloring (the upper left corner of the subtable always has the color 0). Note that some cells may be colored several times. In this case, the final color of the cell is equal to the color obtained during the last repainting.

White color means 0, black means 1. So, for example, the table in the first picture is painted in a chess coloring, and the others are not.
For better understanding of the statement, we recommend you to read the explanation of the first test.

Help Madoka and find some sequence of no more than n⋅m operations that allows you to obtain the picture she wants, or determine that this is impossible.

https://codeforces.com/problemset/problem/1647/C
  • Loading branch information
Ujjwal2017099 authored Aug 7, 2022
1 parent 8a5700e commit b6f92b8
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions 1647C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <bits/stdc++.h>
#define int long long
#define float double
#define vi vector<int>
#define vf vector<float>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define rep(i,a,b) for(int i = a;i<=b;i++)
#define rrep(i,a,b) for(int i = a;i>=b;i--)
#define jaldi ios_base::sync_with_stdio(false);
#define kar cin.tie(NULL);
#define bhai cout.tie(NULL);
#define no "NO"
#define yes "YES"
#define all(__) __.begin(),__.end()
#define endl "\n"
#define pb push_back
#define pairii pair<int,int>
#define pairif pair<int,float>
#define pairfi pair<float,int>
#define pairff pair<float,float>
#define pairib pair<int,bool>

using namespace std;
template <typename T>
istream &operator>>(istream &istream, vector<T> &v){for (auto &it : v){cin >> it;}return istream;}
template <typename Te>
ostream &operator<<(ostream &ostream, vector<Te> &v){for (auto it : v){cout << it << " ";}cout << endl;return ostream;}

void solution(){
int n,m;cin>>n>>m;
vector<string> v;
v.push_back("shjvhgv");
vector<vi> ans;
rep(i,1,n){
string t;cin>>t;
t = "!" + t;
v.pb(t);
}
if(v[1][1] == '1'){cout<<-1<<endl;return;}
rep(i,1,n){
rrep(j,m,2){
if(v[i][j] == '1'){
ans.pb({i,j-1,i,j});
}
}
}

rrep(i,n,2){
if(v[i][1] == '1'){
ans.pb({i-1,1,i,1});
}
}
cout<<ans.size()<<endl;
for(auto i:ans) cout<<i;
}
signed main()
{
jaldi kar bhai
int t=1;
cin >> t;

while (t--) solution();
}

0 comments on commit b6f92b8

Please sign in to comment.