CSES - Datatähti 2017 loppu - Results
Submission details
Task:Ruudukko
Sender:ollpu
Submission time:2017-06-25 10:43:45 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED21
#3ACCEPTED44
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1details
#2ACCEPTED0.03 s1details
#3ACCEPTED0.06 s1details
#4ACCEPTED0.04 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.05 s1details
#7ACCEPTED0.04 s1details
#8ACCEPTED0.04 s1details
#9ACCEPTED0.05 s1details
#10ACCEPTED0.04 s2details
#11ACCEPTED0.08 s2details
#12ACCEPTED0.04 s2details
#13ACCEPTED0.05 s2details
#14ACCEPTED0.05 s2details
#15ACCEPTED0.05 s2details
#16ACCEPTED0.04 s3details
#17ACCEPTED0.06 s3details
#18ACCEPTED0.05 s3details
#19ACCEPTED0.09 s3details
#20ACCEPTED0.14 s3details
#21ACCEPTED0.18 s3details

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...