CSES - Datatähti 2018 loppu - Results
Submission details
Task:Vaihdot
Sender:Leiska
Submission time:2018-01-18 17:07:00 +0200
Language:C++
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.18 s1details
#2ACCEPTED0.20 s1details
#3ACCEPTED0.17 s1details
#4ACCEPTED0.06 s1details
#5ACCEPTED0.19 s1details
#6--2details
#7--2details
#8--2details
#9--2details
#10--2details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details

Compiler report

input/code.cpp: In function 'void s(int)':
input/code.cpp:34:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(o.size()<len) {
              ^
input/code.cpp: In function 'int main()':
input/code.cpp:78:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i<o1.size(); i++) {
                   ^

Code

#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> a1;
vector<int> a2;
vector<int> arr;
vector<string> o1;
vector<string> o;
int len=1e9;
int depth = 6;

void row(int a, int b) {
	o.push_back("1 " + to_string(a) + " " + to_string(b));
	for(int i=0; i<n; i++) {
		int t = arr[ ((a-1)*n) + i ];
		arr[ ((a-1)*n) + i ] = arr[ ((b-1)*n) + i ];
		arr[ ((b-1)*n) + i ] = t;
	}
}
void column(int a, int b) {
	o.push_back("2 " + to_string(a) + " " + to_string(b));
	for(int i=0; i<n; i++) {
		int t = arr[(i*n)+a-1];
		arr[(i*n)+a-1] = arr[(i*n)+b-1];
		arr[(i*n)+b-1] = t;
	}
}

void s(int d) {
	if(d>depth) return;
	if(arr==a2) {
		if(o.size()<len) {
			len = o.size();
			o1 = o;		
		}
		return;
	}

	
	for(int a = 1; a<n; a++) {
		for(int b=a+1; b<=n; b++) {
			for(int i=0; i<=1; i++) {
				vector<int> t = arr;
				if(i==0)
					row(a,b);
				else
					column(a,b);

				s(d+1);

				arr=t;
				o.pop_back();
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin >> n;

	for(int i = 0; i<n*n; i++) {
		int t; cin >> t; a1.push_back(t);
	}
	for(int i = 0; i<n*n; i++) {
		int t; cin >> t; a2.push_back(t);
	}
	if(a1==a2) { cout << 0 << endl; return 0; }
	arr = a1;
	s(0);
	if(o1.size()<=0) cout << -1 << endl;
	else {
		cout << o1.size() << endl;
		for(int i = 0; i<o1.size(); i++) {
			cout << o1[i] << endl;
		}
	}
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
3
2 1 7
4 3 6
8 9 5
1 7 2
...

correct output
2
2 1 3
2 1 2

user output
2
2 1 2
2 2 3

Test 2

Group: 1

Verdict: ACCEPTED

input
3
3 7 2
1 5 6
4 8 9
7 3 2
...

correct output
2
1 2 3
2 1 2

user output
2
2 1 2
1 2 3

Test 3

Group: 1

Verdict: ACCEPTED

input
3
3 7 8
4 5 1
6 9 2
3 8 7
...

correct output
1
2 2 3

user output
1
2 2 3

Test 4

Group: 1

Verdict: ACCEPTED

input
3
3 1 8
5 2 6
9 4 7
3 1 8
...

correct output
0

user output
0

Test 5

Group: 1

Verdict: ACCEPTED

input
3
6 5 8
1 2 4
3 7 9
7 9 3
...

correct output
-1

user output
-1

Test 6

Group: 2

Verdict:

input
50
2080 2133 335 2071 1666 1889 4...

correct output
89
1 1 27
1 1 47
1 1 32
1 1 2
...

user output
(empty)

Test 7

Group: 2

Verdict:

input
50
59 2140 2044 1095 520 1562 153...

correct output
88
1 1 29
1 1 47
1 1 3
1 1 26
...

user output
(empty)

Test 8

Group: 2

Verdict:

input
50
1015 2205 747 1628 2184 61 189...

correct output
94
1 1 17
1 1 30
1 1 15
1 1 3
...

user output
(empty)

Test 9

Group: 2

Verdict:

input
50
1936 637 1930 1825 1375 688 23...

correct output
88
1 1 45
1 1 34
1 1 26
1 1 21
...

user output
(empty)

Test 10

Group: 2

Verdict:

input
50
367 944 222 1047 2163 113 1076...

correct output
-1

user output
(empty)

Test 11

Group: 3

Verdict:

input
500
125877 110081 73003 167540 184...

correct output
986
1 1 222
1 1 325
1 1 203
1 1 73
...

user output
(empty)

Test 12

Group: 3

Verdict:

input
500
98396 218927 201855 126130 103...

correct output
983
1 1 80
1 1 125
1 1 242
1 1 85
...

user output
(empty)

Test 13

Group: 3

Verdict:

input
500
54508 62242 106667 218403 5323...

correct output
985
1 1 356
1 1 88
1 1 142
1 1 321
...

user output
(empty)

Test 14

Group: 3

Verdict:

input
500
108478 62895 206775 78592 2247...

correct output
986
1 1 182
1 1 253
1 1 365
1 1 413
...

user output
(empty)

Test 15

Group: 3

Verdict:

input
500
96354 155542 19613 222634 1530...

correct output
-1

user output
(empty)