1360G - AB Matrix - CodeForces Solution


constructive algorithms greedy math *1900

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define int long long
#define double long double
#define PB push_back
#define maxn 100007
#define bit(x,i) ((x>>i)&1)
#define S second
#define F first
#define MP make_pair
#define epsilon 0.000001

using namespace std;

typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int inf = 1e18;
const int mod = 1e9+7;

int add(int x, int y){
    int s=x+y;
    if (s>mod) s-=mod;
    return s;
}

int n,m,a,b;

void readData(){
    cin>>n>>m>>a>>b;
}

void solve(){
    if (n*a!=b*m){
        cout<<"NO"<<"\n";
        return;
    }
    cout<<"YES"<<"\n";
    int d=0;
    for (int i=1;i<m;i++)
        if ((i*n)%m==0){
            d=i;
            break;
        }
    int ans[n+1][m+1];
    for (int i=0;i<n;i++)
        for (int j=0;j<m;j++)
            ans[i][j]=0;
    int dak=0;
    for (int i=0;i<n;i++){
        dak+=d;
        for (int j=0;j<a;j++)
            ans[i][(j+dak)%m]=1;
    }
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++)
            cout<<ans[i][j];
        cout<<"\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);
    int t;
    cin>>t;
    while (t--){
        readData();
        solve();
    }
    return 0;
}
/*
               _oo0oo_
              o8888888o
              88" . "88
              (| -_- |)
              0\  =  /0
            ___/`---'\___
          .' \\|     |// '.
         / \\|||  :  |||// \
        / _||||| -:- |||||- \
       |   | \\\  -  /// |   |
       | \_|  ''\---/''  |_/ |
       \  .-\__  '-'  ___/-. /
     ___'. .'  /--.--\  `. .'___
  ."" '<  `.___\_<|>_/___.' >' "".
 | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 \  \ `_.   \_ __\ /__ _/   .-` /  /
=====`-.____`.___ \_____/___.-`___.-'=====
               `=---='
*/


Comments

Submit
0 Comments
More Questions

729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme