Cod sursa(job #1890916)

Utilizator theodor.moroianuTheodor Moroianu theodor.moroianu Data 23 februarie 2017 16:31:54
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
using namespace std;

int ans[1010][1010];

int main()
{
    ifstream in("tablete.in");
    int n, k;
    in >> n >> k;
    int cdown = n * n;

    for (int i(n); i >= 1; i--) {
        for (int j(n); j >= 1; j--) {
            if (ans[j][i])
                continue;
            if (i == k) {
                if (!(cdown & 1)) {
                    ans[j][i] = cdown--;
                    ans[j][i - 1] = cdown--;
                }
                else {
                    ans[j][i] = cdown--;
                    swap(ans[j][i], ans[1][i + 1]);
                }
            }
            else
                ans[j][i] = cdown--;
        }
    }

    ofstream out("tablete.out");

    for (int i(1); i <= n; i++)
        for (int j(1); j <= n; j++)
            out << ans[i][j] << (j == n ? '\n' : ' ');
    return 0;
}