Language: C++

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int H, W, A, B;
    cin>>H>>W>>A>>B;

    /*
    r0*A + (W-A)*(H-r0) = (2*A-W)*r0 + W*H - A*H = n0
    c0*B + (H-B)*(W-c0) = (2*B-H)*c0 + H*W - B*W = n0
    */

    for (int n0=0; n0<=H*W/2; n0++)
    {
        int r0 = 2*A-W==0 ? -1 : (n0-W*H+A*H)/(2*A-W);
        int c0 = 2*B-H==0 ? -1 : (n0-H*W+B*W)/(2*B-H);

        if ((2*A-W==0 || 0<=r0 && r0<=H && r0*A+(W-A)*(H-r0)==n0) &&
            (2*B-H==0 || 0<=c0 && c0<=W && c0*B+(H-B)*(W-c0)==n0))
        {
            vector<string> ans(H, string(W, '*'));
            cerr<<n0<<" "<<r0<<" "<<c0<<endl;

            if (r0==-1 && c0==-1)
            {
                for (int y=0; y<H; y++)
                    for (int x=0; x<W; x++)
                        ans[y][x] = '0'+(x+y)%2;
            }
            else if (r0==-1)
            {
                for (int y=0; y<H; y++)
                    for (int x=0; x<W; x++)
                        if (y%2==0 && x<A ||
                            y%2!=0 && x>=A)
                            ans[y][x] = '0';
                        else
                            ans[y][x] = '1';
            }
            else if (c0==-1)
            {
                for (int y=0; y<H; y++)
                    for (int x=0; x<W; x++)
                        if (x%2==0 && y<B ||
                            x%2!=0 && y>=B)
                            ans[y][x] = '0';
                        else
                            ans[y][x] = '1';
            }
            else
            {
                bool ff = false;
                for (int t=0; t<4; t++)
                {
                    bool ok = true;
                vector<int> C(W), C1(W);
                for (int y=0; y<H && ok; y++)
                {
                    int c = 0;
                    int c1 = 0;
                    for (int x=0; x<W && ok; x++)
                    {
                        if ((y<r0 && c<A || y>=r0 && c<W-A) &&
                            (x<c0 && C[x]<B || x>=c0 && C[x]<H-B) &&
                            (y<r0 && c1<W-A || y>=r0 && c1<A) &&
                                 (x<c0 && C1[x]<H-B || x>=c0 && C1[x]<B))
                        {
                            switch(t)
                            {
                            case 0: ans[y][x] = '0'; break;
                            case 1: ans[y][x] = '1'; break;
                            case 2:
                                if ( ((y<r0 ? A : W-A)-c) > ((y<r0 ? W-A : A)-c1))
                                    ans[y][x] = '0';
                                else
                                    ans[y][x] = '1';
                                break;
                            case 3:
                                if ( ((x<c0 ? B : H-B)-C[x]) > ((x<c0 ? H-B : B)-C1[x]))
                                    ans[y][x] = '0';
                                else
                                    ans[y][x] = '1';
                                break;
                            }
                        }
                        else if ((y<r0 && c<A || y>=r0 && c<W-A) &&
                            (x<c0 && C[x]<B || x>=c0 && C[x]<H-B))
                        {
                            ans[y][x] = '0';
                        }
                        else if ((y<r0 && c1<W-A || y>=r0 && c1<A) &&
                                 (x<c0 && C1[x]<H-B || x>=c0 && C1[x]<B))
                        {
                            ans[y][x] = '1';
                        }
                        else
                            ok = false;

                        if (ans[y][x]=='0')
                        {
                            c++;
                            C[x]++;
                        }
                        else
                        {
                            c1++;
                            C1[x]++;
                        }

                    }
                }
                if (ok)
                {
                    ff = true;
                    break;
                }
                }
                if (!ff)

            for (int y=0; y<H; y++)
            for (int x=0; x<W; x++)
                if (y<B && x<A ||
                    y>=B && x>=A)
                    ans[y][x] = '0';
                else
                    ans[y][x] = '1';

            

            for (int y=0; y<H; y++)
                cout<<ans[y]<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:141:2: error: expected '}' at end of input
  141 | }
      |  ^
a.cc:8:1: note: to match this '{'
    8 | {
      | ^