625C - K-special Tables - CodeForces Solution


constructive algorithms implementation *1300

Please click on ads to support us..

C++ Code:

//Not the Best :)
 
#include <bits/stdc++.h>
using namespace std;
 
//DataTypes
using str =  string;
using ll  = long long;
using ld  = long double;
using vl  = vector<ll>;
using vd  = vector<ld>;
using vs  = vector<str>;
using vpl = vector<pair<ll,ll>>;
#define umap unordered_map
#define uset unordered_set
 
//Shorts
#define pus     push_back
#define pub     pop_back
#define ff       first
#define ss       second
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
 
//Algorithms
#define sz(x)     ((ll)(x).size())
#define all(x)    x.begin(),x.end()
#define srt(x)    sort(all(x))
#define srtd(x)   sort(x.rbegin(),x.rend())
#define rev(x)    reverse(all(x));
#define Vmax(x)   *max_element(all(x))
#define Vmin(x)   *min_element(all(x))
#define Vsum(x)   accumulate(all(x),0ll)
#define lowB(v,x) *lower_bound(all(v),x) // >=x
#define upB(v,x)  upper_bound(all(v),x)-v.begin() // > x
#define ers(v,i)  v.erase(v.begin()+i) 
#define uniq(x)   x.erase(unique(all(x)),x.end())
#define NextP(x)  next_permutation(all(x))
#define PrevP(x)  prev_permutation(all(x))
#define cntB(x)   __builtin_popcountll(x)  
#define cntC(s,x) ll(count(all(s), x));
 
//loops
#define For(n)  for (ll i = 0; i < n; i++)
#define ForR(n) for (ll i = n-1; i >= 0; i--)
#define Forj(n) for (ll j = 0; j < n; j++)
#define For1(n) for (ll i = 1; i < n; i++)
 
//IO
#define nl      cout << "\n";
#define ya      cout << "YES\n";
#define na      cout << "NO\n";
#define inpt(v) For(sz(v)) cin >> v[i];
#define prt(v)  for(auto i:v) cout << i << " "; cout << "\n";
 
// ll binary(ll a, vector<ll>&v){
//     ll l=0, r=v.size()-1;
//     while(r-l>1){
//         ll mid=(l+r)/2;
//         if (a>v[mid]){
//             l=mid+1;
//         }
//         else r=mid;
//     }
//     if (v[r]==a) return r;
//     if(v[l]==a) return l;
//     else return -1;
// }
 
 
//Constants
const int M = 1e9+7; 
const int N = 2e5+5;
const ld pi = 3.141592653589793238;
const ll INF = 9e18;
 
ll n, a, b, c, k,z, m,d, x, y, q; str s;
 
//---------------------------------------------------------------------------------------------------------------------------------
//Let's Go :)

void solve()
{
    cin>>n>>k;
    x = 1;
    y = (k-1)*n +1;
    vector<vector<ll>> v(n,vector<ll>(n));
    For(n){
        Forj(n){
            if(j<(k-1)){
                v[i][j] = x;
                x++;
            }
            else{
                v[i][j]=y;
                y++;
            }
        }
        
    }
    c=0;
    For(n){
        c+= v[i][k-1];
    }
    cout<<c;nl
    For(n){
        Forj(n){
            cout<<v[i][j]<<" ";
        }
        nl
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t =  1;
    // cin>>t;
    while(t--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess
467B - Fedor and New Game
252C - Points on Line
735C - Tennis Championship
992A - Nastya and an Array
554A - Kyoya and Photobooks
79B - Colorful Field
265B - Roadside Trees (Simplified Edition)
1362C - Johnny and Another Rating Drop
1214C - Bad Sequence
1091B - New Year and the Treasure Geolocation
244A - Dividing Orange
1061C - Multiplicity
1312A - Two Regular Polygons
801A - Vicious Keyboard
510B - Fox And Two Dots
616D - Longest k-Good Segment
1604A - Era
555B - Case of Fugitive
551A - GukiZ and Contest
1399F - Yet Another Segments Subset
1371C - A Cookie for You
430B - Balls Game
1263A - Sweet Problem
1332B - Composite Coloring
254A - Cards with Numbers