Cod sursa(job #3334803)

Utilizator veronica_stanciuStanciu Veronica veronica_stanciu Data 19 ianuarie 2026 23:05:03
Problema Tablete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
using namespace std;

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

int a[1001][1001];
bool v[1000001];
int main()
{
    int n,k;
    cin >>n>>k;
    for (int i = 1; i <= n * n; i++)
        v[i] = 1;

    int x = 0;
    for (int i = 1; i <= n; i++){
        x += k - 1;
        if (x % 2 == 1){
            a[i][k] = x + 1;
            v[x + 1] = 0;
        }
        else{
            a[i][k] = x + 2;
            v[x + 2] = 0;
        }
        x++;
    }
    x = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < k; j++){
            while (v[x] == 0)
                x++;
            a[i][j] = x;
            v[x] = 0;
        }

    for (int i = 1; i <= n; i++)
        for (int j = k + 1; j <= n; j++){
            while (v[x] == 0)
                x++;
            a[i][j] = x;
            v[x] = 0;
        }

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++)
            cout <<a[i][j]<<" ";
        cout <<endl;
    }
    return 0;
}