Cod sursa(job #3333254)

Utilizator EricMartinmartin petru eric EricMartin Data 12 ianuarie 2026 16:43:57
Problema Tablete Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.18 kb

#include <fstream>
using namespace std;

ifstream cin ("tablete.in");
ofstream cout ("tablete.out");

int a[1001][1001];
int v[1000001];
int main()
{
    int n,k;
    cin >>n>>k;
    for (int i = 1; i <= n * n; i++)
    {
        v[i] = 1;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        cnt += k - 1;
        if (cnt % 2 == 1)
        {
            a[i][k] = cnt + 1;
            v[cnt + 1] = 0;
        }
        else
        {
            a[i][k] = cnt + 2;
            v[cnt + 2] = 0;
        }
        cnt++;
    }
    cnt = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < k; j++)
        {
            while (v[cnt] == 0)
                cnt++;
            a[i][j] = cnt;
            v[cnt] = 0;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = k + 1; j <= n; j++)
        {
            while (v[cnt] == 0)
                cnt++;
            a[i][j] = cnt;
            v[cnt] = 0;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cout <<a[i][j]<<" ";
        }
        cout <<"\n";
    }
    return 0;
}