Task: | Ruudukko |
Sender: | ollpu |
Submission time: | 2017-06-25 10:43:45 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 35 |
#2 | ACCEPTED | 21 |
#3 | ACCEPTED | 44 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.04 s | 1 | details |
#2 | ACCEPTED | 0.03 s | 1 | details |
#3 | ACCEPTED | 0.06 s | 1 | details |
#4 | ACCEPTED | 0.04 s | 1 | details |
#5 | ACCEPTED | 0.05 s | 1 | details |
#6 | ACCEPTED | 0.05 s | 1 | details |
#7 | ACCEPTED | 0.04 s | 1 | details |
#8 | ACCEPTED | 0.04 s | 1 | details |
#9 | ACCEPTED | 0.05 s | 1 | details |
#10 | ACCEPTED | 0.04 s | 2 | details |
#11 | ACCEPTED | 0.08 s | 2 | details |
#12 | ACCEPTED | 0.04 s | 2 | details |
#13 | ACCEPTED | 0.05 s | 2 | details |
#14 | ACCEPTED | 0.05 s | 2 | details |
#15 | ACCEPTED | 0.05 s | 2 | details |
#16 | ACCEPTED | 0.04 s | 3 | details |
#17 | ACCEPTED | 0.06 s | 3 | details |
#18 | ACCEPTED | 0.05 s | 3 | details |
#19 | ACCEPTED | 0.09 s | 3 | details |
#20 | ACCEPTED | 0.14 s | 3 | details |
#21 | ACCEPTED | 0.18 s | 3 | details |
Code
#include <iostream> #include <unordered_set> using namespace std; const int N = 1000; int n; int tc[N], t[N][N]; int tctmp[N]; int rrange(int a, int b) { if (b < a) return a; return rand()%(b-a+1)+a; } bool recover() { for (int j = 0; j < n; ++j) { tc[j] = tctmp[j]; } return 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; if (n < 4) { cout << "QAQ\n"; return 0; } unordered_set<long> rsa; while (true) { rsa.clear(); bool f = 1; for (int i = 0; i < n; ++i) tc[i] = 0; for (int i = 0; i < n; ++i) { long rs, rstryc = 0; do { if (rstryc++ > 1000) { f = 0; break; } rs = 0; for (int j = 0; j < n; ++j) tctmp[j] = tc[j]; for (int j = 0; j < i; ++j) rs += t[i][j]; for (int j = i; j < n; ++j) { int o; do { o = rrange(1, n); } while (tc[o-1] == n); tc[o-1]++; t[i][j] = o; rs += o; // cout <<"--"<< j << endl; } } while (rsa.count(rs) && recover()); if (!f) break; rsa.insert(rs); rstryc = 0; do { if (rstryc++ > 1000) { f = 0; break; } rs = 0; for (int j = 0; j < n; ++j) tctmp[j] = tc[j]; for (int j = 0; j < i+1; ++j) rs += t[j][i]; for (int j = i+1; j < n; ++j) { int o; do { o = rrange(1, n); } while (tc[o-1] == n); tc[o-1]++; t[j][i] = o; rs += o; // cout <<"--"<< j << endl; } } while (rsa.count(rs) && recover()); if (!f) break; rsa.insert(rs); } // for (int i = 0; i < n; ++i) { // for (int j = 0; j < n; ++j) { // cout << t[i][j] << " "; // } // cout << "\n"; // } if (!f) continue; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << t[i][j] << " "; } cout << "\n"; } break; } }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 2
Group: 1
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 3
Group: 1
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
4 3 3 2 4 4 1 2 2 3 2 1 3 4 1 1 |
Test 4
Group: 1
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
2 3 4 1 1 3 4 2 1 2 4 2 3 1 3 4 3 2 1 4 5 5 5 5 5 |
user output |
---|
1 2 3 5 5 1 3 1 2 5 3 2 1 5 4 5 3 2 4 4 1 3 2 4 4 |
Test 5
Group: 1
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
2 3 4 5 1 1 3 4 5 2 1 2 4 5 2 3 1 3 5 2 3 4 1 4 5 4 3 2 1 5 ... |
user output |
---|
5 5 4 6 1 4 2 5 6 5 2 6 3 1 6 1 3 4 2 1 3 4 2 1 3 6 6 3 4 5 ... |
Test 6
Group: 1
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
2 3 4 5 6 1 1 3 4 5 6 2 1 2 4 5 6 2 3 1 3 5 6 2 3 4 1 4 6 2 3 4 5 1 5 ... |
user output |
---|
4 6 6 3 5 5 1 7 4 7 2 6 2 4 2 1 1 5 7 5 7 3 4 2 1 7 2 3 5 2 7 2 6 6 6 ... |
Test 7
Group: 1
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
2 3 4 5 6 7 1 1 3 4 5 6 7 2 1 2 4 5 6 7 2 3 1 3 5 6 7 2 3 4 1 4 6 7 2 3 4 5 1 5 ... |
user output |
---|
7 4 4 5 3 3 4 4 3 6 6 6 4 5 4 6 5 1 1 7 8 7 3 3 6 7 7 2 3 8 7 2 6 3 2 8 5 5 8 8 ... |
Test 8
Group: 1
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
2 3 4 5 6 7 8 1 1 3 4 5 6 7 8 2 1 2 4 5 6 7 8 2 3 1 3 5 6 7 8 2 3 4 1 4 6 7 8 2 3 4 5 1 5 ... |
user output |
---|
7 7 7 5 7 3 8 5 7 7 3 2 4 4 1 4 2 8 4 1 3 2 9 1 2 5 3 6 1 8 2 7 9 4 7 4 4 3 2 5 9 6 3 6 9 ... |
Test 9
Group: 1
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
2 3 4 5 6 7 8 9 1 1 3 4 5 6 7 8 9 2 1 2 4 5 6 7 8 9 2 3 1 3 5 6 7 8 9 2 3 4 1 4 6 7 8 9 2 3 4 5 1 5 ... |
user output |
---|
3 3 2 3 5 8 3 6 3 3 10 9 9 4 1 2 5 4 6 1 5 7 7 6 7 9 8 7 5 9 10 3 5 9 9 3 1 8 5 1 7 5 2 1 8 4 6 10 2 1 ... |
Test 10
Group: 2
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 11
Group: 2
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
4 3 3 2 4 4 1 2 2 3 2 1 3 4 1 1 |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
29 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
21 8 9 11 26 7 10 22 27 4 5 5 ... |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
48 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
8 37 35 32 38 28 27 12 42 47 3... |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
80 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
65 28 55 35 1 6 46 25 5 48 44 ... |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
97 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 34 21 31 43 15 3 62 47 70 72... |
Test 16
Group: 3
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 17
Group: 3
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
4 3 3 2 4 4 1 2 2 3 2 1 3 4 1 1 |
Test 18
Group: 3
Verdict: ACCEPTED
input |
---|
111 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
35 110 43 47 57 110 104 16 97 ... |
Test 19
Group: 3
Verdict: ACCEPTED
input |
---|
506 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
150 231 260 256 398 346 199 11... |
Test 20
Group: 3
Verdict: ACCEPTED
input |
---|
844 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
385 509 738 260 297 488 558 51... |
Test 21
Group: 3
Verdict: ACCEPTED
input |
---|
991 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
692 132 769 153 738 645 825 44... |