CSES - Datatähti 2018 loppu - Results
Submission details
Task:Vaihdot
Sender:Yytsi
Submission time:2019-01-04 17:50:08 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED55
#3ACCEPTED33
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1details
#2ACCEPTED0.02 s1details
#3ACCEPTED0.01 s1details
#4ACCEPTED0.03 s1details
#5ACCEPTED0.03 s1details
#6ACCEPTED0.01 s2details
#7ACCEPTED0.02 s2details
#8ACCEPTED0.02 s2details
#9ACCEPTED0.02 s2details
#10ACCEPTED0.02 s2details
#11ACCEPTED0.09 s3details
#12ACCEPTED0.10 s3details
#13ACCEPTED0.08 s3details
#14ACCEPTED0.09 s3details
#15ACCEPTED0.09 s3details

Code

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define IO ios_base::sync_with_stdio(0); cin.tie(0)
#define ff first
#define ss second
#define pb push_back
#define INF 2147483647
#define LINF (1LL<<62LL)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n;

pii broken[555 * 555];
int trans[555][555];

pii pos[555 * 555];
int model[555][555];

vector<pii> rows, cols;


void swaprow(int a, int b) {
  // Swap rows a <-> b.
  FOR(i,0,n) {
    broken[trans[a][i]] = {b, i};
    broken[trans[b][i]] = {a, i};
    swap(trans[a][i], trans[b][i]);
  }
}

void swapcol(int a, int b) {
  // Swap columns a <-> b.
  FOR(i,0,n) {
    broken[trans[i][a]] = {i, b};
    broken[trans[i][b]] = {i, a};
    swap(trans[i][a], trans[i][b]);
  }
}

int main() {
  IO; cin>>n;
  FOR(i,0,n) {
    FOR(j,0,n) {
      cin>>trans[i][j];
      broken[trans[i][j]] = {i,j};
    }
  }
  
  FOR(i,0,n) {
    FOR(j,0,n) {
      cin>>model[i][j];
      pos[model[i][j]] = {i, j};
    }
  }
  
  FOR(x,1,n*n+1) {
    if (broken[x].ff != pos[x].ff) {
      // Row is not the same!
      rows.pb({broken[x].ff, pos[x].ff});
      swaprow(broken[x].ff, pos[x].ff);
    }
    if (broken[x].ss != pos[x].ss) {
      // Column is not the same!
      cols.pb({broken[x].ss, pos[x].ss});
      swapcol(broken[x].ss, pos[x].ss);
    }
  }
  
  FOR(x,1,n*n+1) {
    if (pos[x] != broken[x]) {
      cout<<-1<<"\n";
      exit(0);
    }
  }
  
  cout<<rows.size()+cols.size()<<"\n";
  for (pii m : cols)cout<<"2 "<<m.ff+1<<" "<<m.ss+1<<"\n";
  for (pii m : rows)cout<<"1 "<<m.ff+1<<" "<<m.ss+1<<"\n";
}












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 2 1
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 3 2

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: ACCEPTED

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
89
2 8 4
2 36 46
2 25 38
2 43 22
...

Test 7

Group: 2

Verdict: ACCEPTED

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
88
2 12 38
2 1 2
2 10 29
2 46 5
...

Test 8

Group: 2

Verdict: ACCEPTED

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
94
2 24 9
2 38 10
2 31 8
2 16 27
...

Test 9

Group: 2

Verdict: ACCEPTED

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
88
2 4 34
2 19 13
2 12 32
2 26 5
...

Test 10

Group: 2

Verdict: ACCEPTED

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

correct output
-1

user output
-1

Test 11

Group: 3

Verdict: ACCEPTED

input
500
125877 110081 73003 167540 184...

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

user output
986
2 113 434
2 140 406
2 161 154
2 478 147
...

Test 12

Group: 3

Verdict: ACCEPTED

input
500
98396 218927 201855 126130 103...

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

user output
983
2 441 223
2 200 177
2 441 359
2 482 267
...

Test 13

Group: 3

Verdict: ACCEPTED

input
500
54508 62242 106667 218403 5323...

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

user output
985
2 332 462
2 482 305
2 135 368
2 486 373
...

Test 14

Group: 3

Verdict: ACCEPTED

input
500
108478 62895 206775 78592 2247...

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

user output
986
2 473 172
2 2 335
2 132 338
2 297 18
...

Test 15

Group: 3

Verdict: ACCEPTED

input
500
96354 155542 19613 222634 1530...

correct output
-1

user output
-1