Task: | Ruudukko |
Sender: | JPaananen |
Submission time: | 2019-10-12 14:24:51 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ~~~~~^~~~~~~~~~
Code
// Made by Jaakko P.#include <stdio.h>#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)int log2(int x) {return 31 ^ __builtin_clz(x);}#elif defined(_MSC_VER)#include <intrin.h>int log2(int x) {unsigned long r = 0;_BitScanReverse(&r, x);return r;}#endiftemplate<int cl2>int magicFunc(int x, int y) {int val = 1;for (int i = 0; i < cl2; ++i)val += (((x >> i) + (y >> i)) & 1) << i;return val;}template<int cl2>void printGrid(int size) {for (int i = 0; i < size; ++i) {for (int j = 0; j < size; ++j) {printf("%d ", magicFunc<cl2>(i, j));}puts("\n");}}int main() {int n;#ifdef _MSC_VERscanf_s("%d", &n); // fix compilation#elsescanf("%d", &n);#endifswitch (log2(n-1)+1) { // TODO use ceil(log2(n)) insteadcase 1:printGrid<1>(n);break;case 2:printGrid<2>(n);break;case 3:printGrid<3>(n);break;case 4:printGrid<4>(n);break;case 5:printGrid<5>(n);break;case 6:printGrid<6>(n);break;case 7: // Stop at 2^7 because 2^7=128, 128 > 100.printGrid<7>(n);break;}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: ACCEPTED
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 |
---|
1 2 3 4 5 2 1 4 3 6 3 4 1 2 7 ... |
Test 4
Verdict: ACCEPTED
input |
---|
42 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 5
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 6
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |