Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Kvadrat števil C++ 100/100OK 13. okt '18 @ 13:06

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 3,152 MiB 0,000 s OK
#2 10/10 3,004 MiB 0,000 s OK
#3 10/10 3,004 MiB 0,000 s OK
#4 10/10 3,215 MiB 0,004 s OK
#5 10/10 3,012 MiB 0,003 s OK
#6 10/10 3,012 MiB 0,000 s OK
#7 10/10 3,039 MiB 0,013 s OK
#8 10/10 3,250 MiB 0,019 s OK
#9 10/10 3,250 MiB 0,026 s OK
#10 10/10 3,043 MiB 0,007 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <unordered_map>
#include <algorithm>

using namespace std;


bool mycmp(int a, int b)
{
    return a > b;
}

int main()
{
    int cnt[200];
    for (int i = 0; i != 200; i++)
        cnt[i] = 0;

    int n;
    cin >> n;
    int center_r = n/2;
    int center_c = n/2;
    int* numbers = new int[n*n];
    int* off = new int[n];
    for (int i = 0; i != n; i++)
        off[i] = 0;

    for (int i = 0; i != n * n; i++)
    {
        int x;
        cin >> x;
        numbers[i] = x;
    }

    sort(numbers, numbers + n * n, mycmp);

    for (int r = 0; r != n; r++)
    {
        for (int c = 0; c != n; c++)
        {
            int dst = abs(center_c - c) + abs(center_r - r);
            off[dst]++;
        }
    }


    for (int i = 1; i < n; i++)
    {
        off[i] += off[i - 1];
    }

    for (int r = 0; r != n; r++)
    {
        for (int c = 0; c != n; c++)
        {
            int dst = abs(center_c - c) + abs(center_r - r);
            int myoff = off[max(dst - 1, 0)];
            if (dst == 0)
                myoff = 0;

            cout << numbers[myoff + cnt[dst]] << ' ';

            cnt[dst]++;
        }
        cout << endl;
    }

    return 0;
}