Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define pb push_back
- #define int long long
- #define uint __int128
- #define mp make_pair
- #define left left_compile
- #define right right_compile
- #pragma GCC optimize("O3")
- #pragma GCC optimize("unroll-loops")
- const int INF = (int)1e18;
- const int md = (int)1e18 + 7;
- const int MAXN = (int)1e6 + 111;
- const int N = (int)2e5 + 111;
- //const int L = 20;
- const int debug = 0;
- const long double eps = 0.0001;
- //const int P[2] = {29,31};
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- struct DSU{
- int n;
- vector<int> parent;
- vector<int> sz;
- vector<int> deep;
- vector<int> l,r;
- DSU(int nn){
- n = nn;
- parent.resize(n+1);
- sz.resize(n+1,1);
- deep.resize(n+1,1);
- l.resize(n+1);
- r.resize(n+1);
- for(int i = 0; i <= n; i++)
- parent[i] = i, sz[i] = 1, deep[i] = 1, l[i] = r[i] = i;
- }
- int find_parent(int x){
- if(parent[x] == x)
- return x;
- return parent[x] = find_parent(parent[x]);
- }
- bool union_sets(int a,int b){
- int A,B;
- A = a, B = b;
- if(A == B)
- return true;
- a = find_parent(a);
- b = find_parent(b);
- if(a == b)
- return false;
- parent[a] = b;
- // cerr << A << " " << B << "\n";
- // cerr << l[a] << " " << r[a] << "\n";
- // cerr << l[b] << " " << r[b] << "\n\n";
- if(l[a] == A && l[b] == B)
- l[b] = r[b], r[b] = r[a];
- else if(l[a] == A && r[b] == B)
- l[b] = l[b], r[b] = r[a];
- else if(r[a] == A && l[b] == B)
- l[b] = l[a], r[b] = r[b];
- else if(r[a] == A && r[b] == B)
- r[b] = l[b], l[b] = l[a];
- else
- return false;
- return true;
- }
- bool connected(int a,int b){
- return find_parent(a) == find_parent(b);
- }
- };
- template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
- int bpow(int a,int b){
- if(b <= 0)
- return 1ll;
- if(b % 2 == 0){
- int t = bpow(a,b/2) % md;
- return (t * t) % md;
- }
- return (a * bpow(a,b-1)) % md;
- }
- int inv(int a){ /// return 1/a by PRIME modulo md
- return bpow(a,md-2);
- }
- template<class T>
- void myerase(ordered_multiset<T>& st, T t){
- T r = st.order_of_key(t);
- typename ordered_multiset<T>::iterator it = st.find_by_order(r);
- st.erase(it);
- return;
- }
- int fac[555555];
- int invfac[555555];
- void init(){
- fac[0] = 1;
- invfac[0] = 1;
- for(int i = 1; i < 555555; i++){
- fac[i] = fac[i-1] * i;
- invfac[i] = inv(fac[i]);
- }
- return;
- }
- //void add(int& a,int b){
- // a = (a + b >= md ? a + b - md : a + b);
- //}
- //
- //void sub(int& a,int b){
- // a = (a < b ? a - b + md : a - b);
- //}
- int mult(int a,int b){
- return a * b % md;
- }
- int C(int n,int k){
- assert(k >= 0 && k <= n);
- return mult(fac[n],mult(invfac[n-k],invfac[k]));
- }
- const int DX[] = {1,0,-1,0};
- const int DY[] = {0,1,0,-1};
- void solve(){
- int n,m;
- cin >> n >> m;
- if(n == 1 && m == 1){
- cout << "1\n1\n";
- return;
- }
- if(n == 1){
- if(m % 2 == 1){
- cout << "3\n";
- for(int i = 0; i < m - 1; i++){
- cout << i % 2 + 1 << " ";
- }
- cout << "3\n";
- } else {
- cout << "2\n";
- for(int i = 0; i < m; i++){
- cout << i % 2 + 1 << " ";
- }
- cout << "\n";
- }
- return;
- }
- if(m == 1){
- if(n % 2 == 1){
- cout << "3\n";
- for(int i = 0; i < n - 1; i++){
- cout << i % 2 + 1 << "\n";
- }
- cout << "3\n";
- } else {
- cout << "2\n";
- for(int i = 0; i < n; i++){
- cout << i % 2 + 1 << "\n";
- }
- }
- return;
- }
- if(n % 2 == 0 && m % 2 == 0){
- cout << "2\n";
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- cout << (i + j) % 2 + 1 << " ";
- }
- cout << "\n";
- }
- return;
- }
- cout << "3\n";
- for(int i = 1; i < n; i++){
- if(i % 2 == 0){
- cout << "3";
- for(int j = 1; j < m; j++){
- if(j % 2 == 1)
- cout << " 1";
- else
- cout << " 2";
- }
- } else {
- cout << "2";
- for(int j = 1; j < m; j++){
- if(j % 2 == 1)
- cout << " 3";
- else
- cout << " 1";
- }
- }
- cout << "\n";
- }
- cout << "1";
- for(int j = 1; j < m; j++){
- if(j % 2 == 1)
- cout << " 2";
- else
- cout << " 3";
- }
- cout << "\n";
- return;
- }
- /**
- 7 7 7 0 2
- 4 4
- 1 2 1 2
- 2 1 2 1
- 1 2 1 2
- 2 1 2 1
- n > 2 m > 2
- 3 1 2 1 2
- 2 3 1 3 1
- 3 1 2 1 2
- 1 2 3 2 3
- n == 1
- 1 2 1 2 1 2
- **/
- signed main(){
- ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- // init();
- int tests = 1;
- // cin >> tests;
- for(int _ = 1; _ <= tests; _++){
- solve();
- }
- //
- // #ifdef __WIN32
- // cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
- // #endif
- return 0;
- }
- /**
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement