Language: C++

#include<bits/stdc++.h>
#pragma GCC optimize(3)
namespace ZDY{
    #define res register
    #define ri res int
    #define ll long long
    #define db double
    #define il inline
    #define MB template <class T>
    #define Fur(i,x,y) for(ri i=x;i<=y;i++)
    #define fur(i,x,y) for(i=x;i<=y;i++)
    #define Fdr(i,x,y) for(ri i=x;i>=y;i--)
    #define in2(x,y) in(x),in(y)
    #define in3(x,y,z) in2(x,y),in(z)
    #define in4(a,b,c,d) in2(a,b);in2(c,d)
    #define outn(x) out(x),pc('\n')
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fl(i,x) for(ri i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define inf 2147483647
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdin)
    #define gt io.gc()
    MB il T ABS(T x){return x>0?x:-x;}
    MB il T MAX(T x,T y){return x>y?x:y;}
    MB il T MIN(T x,T y){return x<y?x:y;}
    MB il T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB il void SWAP(T x,T y){T t=x;y=t;x=y;}
}using namespace ZDY;using namespace std;
class IO{
    #define fok (ch!=EOF)
    #define sep (ch==' '||ch=='\n'||ch=='\t')
    #define dsep !isdigit(ch)
    #define neq(a,b) ((a)-(b)>1e-6)
    char rbuf[1000002],wbuf[1000002],b,*p1,*p2;
    int rs,ws,S;
    public:
        IO():p1(rbuf),p2(wbuf),S(1000000),rs(1000000),ws(-1),b(1){}
        ~IO(){fwrite(wbuf,1,ws+1,stdout);}
        il char gc(){return rs==S&&(p1=rbuf,rs=-1,(S=fread(rbuf,1,S+1,stdin)-1)==-1)?(b=0,EOF):(++rs,*p1++);}
        il void pc(int x){ws==1000000&&(p2=wbuf,ws=-1,fwrite(wbuf,1,1000001,stdout)),++ws,*p2++=x;}
        il void puts(const char str[]){fwrite(wbuf,1,ws+1,stdout)?(ws=-1):0,fwrite(str,1,strlen(str),stdout);}
        il void gl(string& s){for(res char ch;(ch=gc())!='\n'&&fok;)s+=ch;}
        il IO& operator>>(int& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
        il IO& operator>>(ll& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
        il IO& operator>>(char& ch){return ch=gc(),*this;}
        il IO& operator>>(string& s){res char ch=gc();while(sep&&fok)ch=gc();while(!sep&&fok)s+=ch,ch=gc();return *this;}
        il IO& operator>>(double& x){x=0;res char f=0,ch=gc();double d=0.1;while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=x*10+(ch^48),ch=gc();if(ch=='.')while(isdigit(ch=gc()))x+=d*(ch^48),d*=0.1;return x=f?-x:x,*this;}
        il IO& operator<<(int x){res char ch[10],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
        il IO& operator<<(ll x){res char ch[20],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
        il IO& operator<<(char ch){return pc(ch),*this;}
        il IO& operator<<(char str[]){return puts(str),*this;}
        il IO& operator<<(double x){int y=int(x);*this<<y;x-=y;while(neq(x,int(x)))x*=10;x?*this<<'.'<<int(x):0;return *this;}
        il operator bool(){return b;}
}io;
#define N 501
int n,m,a[N][N],p[N*N],q[N*N],y[N*N],z[N*N],d=0;
bool v[N][N];
int main(){
    io>>n>>m;
    Fur(i,1,n)Fur(j,1,m)io>>a[i][j];
    Fur(i,1,n){
        Fur(j,1,m)
        if(a[i][j]&1){
            int k=j+1;
            bool f=0;
            while(!(a[i][k]&1)){if(v[i][k])break;k++;if(k>m){f=1;break;}}
            if(f)break;
            Fur(u,j+1,k)v[i][u-1]=1,p[++d]=i,q[d]=u-1,y[d]=i,z[d]=u;
            a[i][j]--;a[i][k]++;j=k;
        }
    }
    Fur(j,1,m){
        Fur(i,1,n)
        if(a[i][j]&1){
            int k=i+1;
            bool f=0;
            while(!(a[k][j]&1)){if(v[k][j]break;k++;if(k>n){f=1;break;}}
            if(f)break;
            Fur(u,i+1,k)v[u-1][j]=1,p[++d]=u-1,q[d]=j,y[d]=u,z[d]=j;
            a[i][j]--;a[k][j]++;i=k;
        }
    }
    io<<d<<'\n';
    Fur(i,1,d)io<<p[i]<<' '<<q[i]<<' '<<y[i]<<' '<<z[i]<<'\n';
}


Compiler output:
a.cc: In member function 'void IO::gl(std::string&)':
a.cc:43:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         il void gl(string& s){for(res char ch;(ch=gc())!='\n'&&fok;)s+=ch;}
      |                                            ^~
a.cc: In member function 'IO& IO::operator>>(int&)':
a.cc:44:48: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         il IO& operator>>(int& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
      |                                                ^
a.cc:44:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         il IO& operator>>(int& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
      |                                                    ^~
a.cc: In member function 'IO& IO::operator>>(long long int&)':
a.cc:45:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         il IO& operator>>(ll& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
      |                                               ^
a.cc:45:51: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         il IO& operator>>(ll& x){x=0;res char f=0,ch=gc();while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();return x=f?-x:x,*this;}
      |                                                   ^~
a.cc: In member function 'IO& IO::operator>>(std::string&)':
a.cc:47:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         il IO& operator>>(string& s){res char ch=gc();while(sep&&fok)ch=gc();while(!sep&&fok)s+=ch,ch=gc();return *this;}
      |                                               ^~
a.cc: In member function 'IO& IO::operator>>(double&)':
a.cc:48:51: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         il IO& operator>>(double& x){x=0;res char f=0,ch=gc();double d=0.1;while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=x*10+(ch^48),ch=gc();if(ch=='.')while(isdigit(ch=gc()))x+=d*(ch^48),d*=0.1;return x=f?-x:x,*this;}
      |                                                   ^
a.cc:48:55: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         il IO& operator>>(double& x){x=0;res char f=0,ch=gc();double d=0.1;while(dsep&&fok)f|=(ch=='-'),ch=gc();while(isdigit(ch))x=x*10+(ch^48),ch=gc();if(ch=='.')while(isdigit(ch=gc()))x+=d*(ch^48),d*=0.1;return x=f?-x:x,*this;}
      |                                                       ^~
a.cc: In member function 'IO& IO::operator<<(int)':
a.cc:49:43: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         il IO& operator<<(int x){res char ch[10],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
      |                                           ^~
a.cc:49:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         il IO& operator<<(int x){res char ch[10],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
      |                                                  ^
a.cc: In member function 'IO& IO::operator<<(long long int)':
a.cc:50:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         il IO& operator<<(ll x){res char ch[20],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
      |                                          ^~
a.cc:50:49: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         il IO& operator<<(ll x){res char ch[20],i=-1;!x?(pc('0'),0):0,x<0?(pc('-'),x=-x):0;while(x)ch[++i]=x%10+48,x/=10;while(~i)pc(ch[i]),--i;return *this;}
      |                                                 ^
a.cc: In function 'int main()':
a.cc:61:9: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   61 |     Fur(i,1,n)Fur(j,1,m)io>>a[i][j];
      |         ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:61:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   61 |     Fur(i,1,n)Fur(j,1,m)io>>a[i][j];
      |                   ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:62:9: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 |     Fur(i,1,n){
      |         ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:63:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         Fur(j,1,m)
      |             ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:69:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   69 |             Fur(u,j+1,k)v[i][u-1]=1,p[++d]=i,q[d]=u-1,y[d]=i,z[d]=u;
      |                 ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:73:9: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |     Fur(j,1,m){
      |         ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:74:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |         Fur(i,1,n)
      |             ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:78:43: error: expected ';' before 'break'
   78 |             while(!(a[k][j]&1)){if(v[k][j]break;k++;if(k>n){f=1;break;}}
      |                                           ^~~~~
      |                                           ;
a.cc:78:52: error: expected ')' before ';' token
   78 |             while(!(a[k][j]&1)){if(v[k][j]break;k++;if(k>n){f=1;break;}}
      |                                   ~                ^
      |                                                    )
a.cc:80:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   80 |             Fur(u,i+1,k)v[u-1][j]=1,p[++d]=u-1,q[d]=j,y[d]=u,z[d]=j;
      |                 ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^
a.cc:85:9: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   85 |     Fur(i,1,d)io<<p[i]<<' '<<q[i]<<' '<<y[i]<<' '<<z[i]<<'\n';
      |         ^
a.cc:10:31: note: in definition of macro 'Fur'
   10 |     #define Fur(i,x,y) for(ri i=x;i<=y;i++)
      |                               ^