Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 3,379 MiB 0,000 s OK
#2 10/10 3,234 MiB 0,000 s OK
#3 10/10 3,234 MiB 0,004 s OK
#4 10/10 3,238 MiB 0,004 s OK
#5 10/10 3,395 MiB 0,000 s OK
#6 10/10 3,246 MiB 0,000 s OK
#7 10/10 3,328 MiB 0,010 s OK
#8 10/10 3,332 MiB 0,003 s OK
#9 10/10 3,328 MiB 0,016 s OK
#10 10/10 3,336 MiB 0,015 s OK

Ocenjevani program (KvadratStevil.cpp):
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF (1LL << 55)
#define maxn 111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int arr[maxn][maxn];
vector<int> v;

pii dir[] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; 
int n;

int nxt(){
	int ret = v.back();
	v.pop_back();
	return ret;
}

void fillArr(int x, int y){
	if(x < 0 || x >= n || y < 0 || y >= n)
		return;
	
	arr[x][y] = nxt();
	
	for(int i = x + 1; i < n; i++){
		if(arr[i][y] != -1)
			break;
		
		arr[i][y] = nxt();
	}
	
	for(int i = x - 1; i >= 0; i--){
		if(arr[i][y] != -1)
			break;
		
		arr[i][y] = nxt();
	}
	
	for(int i = y + 1; i < n; i++){
		if(arr[x][i] != -1)
			break;
		
		arr[x][i] = nxt();
	}
	
	for(int i = y - 1; i >= 0; i--){
		if(arr[x][i] != -1)
			break;
		
		arr[x][i] = nxt();
	}
	
}

int main(){
	scanf("%d", &n);
    
        for(int  i = 0; i < n * n; i++) {
            int x;
            scanf("%d", &x);
            v.pb(x);
        }
        
        memset(arr, -1, sizeof(arr));
        
        sort(v.begin(), v.end());
		
	int zac = n / 2;
	fillArr(zac, zac);
	while(v.size() > 0){
		for(int len = 1; len < n + 10; len++){
			for(int j = 0; j < 4; j++)
				fillArr(zac + len * dir[j].fi, zac + len * dir[j].se);
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++)
			printf("%d ", arr[i][j]);
		printf("\n");
	}
	return 0;
}