Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 3,188 MiB 0,000 s OK
#2 10/10 3,188 MiB 0,004 s OK
#3 10/10 3,039 MiB 0,000 s OK
#4 10/10 3,195 MiB 0,004 s OK
#5 10/10 3,215 MiB 0,009 s OK
#6 10/10 3,211 MiB 0,003 s OK
#7 10/10 3,102 MiB 0,013 s OK
#8 10/10 3,258 MiB 0,026 s OK
#9 10/10 3,250 MiB 0,026 s OK
#10 10/10 3,113 MiB 0,019 s OK

Ocenjevani program (kvadratstevil.cpp):
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>
#define SIZE 100
using namespace std;
int polje[SIZE][SIZE];

#define NOTVISITED 10000007
#define NOTSET 10000006
int N;
 queue<pair<int, int> > Q;

void vstavi(int x, int y){
    if(polje[x][y] != NOTVISITED)
        return;

    if(x >= N || x < 0 || y >= N || y < 0)
        return;

    Q.push(make_pair(x, y));

    polje[x][y] = NOTSET;

}

int main()
{


    vector<int> stevila;
    cin >> N;
    stevila.resize(N * N);

    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j)
            polje[i][j] = NOTVISITED;
    }

    for(int i = 0; i < N*N; ++i){
        cin >> stevila[i];
    }

    sort(stevila.begin(), stevila.end());

    int counter = N*N;

    Q.push(make_pair(N/2, N/2));

    for(int i = 0; i < N * N; ++i){
        int x= Q.front().first;
        int y = Q.front().second;

        polje[Q.front().first][Q.front().second] = stevila[--counter];

        Q.pop();
        vstavi(x + 1, y);
        vstavi(x - 1, y);
        vstavi(x, y + 1);
        vstavi(x, y - 1);
    }

    for(int i  =0; i < N; ++i){
        for(int j = 0; j < N; ++j)
            cout << polje[i][j] << ' ';
        cout << endl;
    }


    return 0;
}