Task: | Ruudukko |
Sender: | 2 |
Submission time: | 2019-09-30 18:08:16 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | RUNTIME ERROR | 0.01 s | details |
#4 | RUNTIME ERROR | 0.01 s | details |
#5 | RUNTIME ERROR | 0.01 s | details |
#6 | RUNTIME ERROR | 0.01 s | details |
Code
#include <iostream> #include <vector> #include <algorithm> #include <assert.h> inline int& get(int* vals, int n, int x, int y) { return vals[x + y * n]; } inline void set(int* vals, int n, int x, int y, int val) { vals[x + y * n] = val; } void fill_to(std::vector<int>& v, int n) { v.resize(n); for (int i = 0; i < n; i++) v[i] = i + 1; } int main() { int n; std::cin >> n; int* matrix = new int[n * n]; // i = y // k = x for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { // Find available std::vector<int> available; fill_to(available, n); for (int j = 0; j < i; j++) { available[get(matrix, n, k, j) - 1] = -1; } for (int j = 0; j < k; j++) { available[get(matrix, n, j, i) - 1] = -1; } std::remove_if(std::begin(available), std::end(available), [](int v) {return v == -1; }); set(matrix, n, k, i, available[0]); } } for (int i = 0; i < n * n; i++) { int x = i % 4; std::cout << matrix[i]; if (x == 3) std::cout << "\n"; if (x < 3) std::cout << " "; } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
1 2 2 1 |
user output |
---|
1 2 2 1 |
Test 3
Verdict: RUNTIME ERROR
input |
---|
5 |
correct output |
---|
1 2 3 4 5 2 1 4 3 6 3 4 1 2 7 4 3 2 1 8 5 6 7 8 1 |
user output |
---|
(empty) |
Error:
munmap_chunk(): invalid pointer
Test 4
Verdict: RUNTIME ERROR
input |
---|
42 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Error:
munmap_chunk(): invalid pointer
Test 5
Verdict: RUNTIME ERROR
input |
---|
99 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Error:
munmap_chunk(): invalid pointer
Test 6
Verdict: RUNTIME ERROR
input |
---|
100 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
(empty) |
Error:
munmap_chunk(): invalid pointer