Submission #48405945
Source Code Expand
Copy
#include<bits/stdc++.h>using namespace std;int n,m,ans = 0x3f3f3f3f;int a[10][10],b[10][10];int p[10],q[10];int main(){cin >> n >> m;for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++){cin >> a[i][j];}}for(int i = 1;i <= n;i++){for(int j = 1;j <= m;j++){cin >> b[i][j];
#include<bits/stdc++.h> using namespace std; int n,m,ans = 0x3f3f3f3f; int a[10][10],b[10][10]; int p[10],q[10]; int main() { cin >> n >> m; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { cin >> a[i][j]; } } for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { cin >> b[i][j]; } } for(int i = 1;i <= n;i++) { p[i] = i; } for(int i = 1;i <= m;i++) { q[i] = i; } do { do { bool flag = 1; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { if(a[p[i]][q[j]] != b[i][j]) { flag = 0; } } } if(!flag) { continue; } int mvp = 0,mvq = 0; for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) { if(i < j && p[i] > p[j]) { mvp++; } } } for(int i = 1;i <= m;i++) { for(int j = 1;j <= m;j++) { if(i < j && q[i] > q[j]) { mvq++; } } } ans = min(ans,mvp + mvq); }while(next_permutation(q + 1,q + m + 1)); }while(next_permutation(p + 1,p + n + 1)); if(ans == 0x3f3f3f3f) { cout << -1; return 0; } cout << ans; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Swapping Puzzle |
User | feather_life |
Language | C++ 20 (gcc 12.2) |
Score | 425 |
Code Size | 1810 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 3672 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 425 / 425 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 1 ms | 3672 KB |
001.txt | AC | 1 ms | 3556 KB |
002.txt | AC | 1 ms | 3644 KB |
003.txt | AC | 1 ms | 3492 KB |
004.txt | AC | 1 ms | 3492 KB |
005.txt | AC | 1 ms | 3472 KB |
006.txt | AC | 2 ms | 3484 KB |
007.txt | AC | 2 ms | 3472 KB |
008.txt | AC | 2 ms | 3476 KB |
009.txt | AC | 1 ms | 3456 KB |
010.txt | AC | 1 ms | 3532 KB |
011.txt | AC | 1 ms | 3492 KB |
012.txt | AC | 1 ms | 3496 KB |
013.txt | AC | 1 ms | 3484 KB |
014.txt | AC | 1 ms | 3556 KB |
015.txt | AC | 1 ms | 3488 KB |
016.txt | AC | 1 ms | 3428 KB |
017.txt | AC | 1 ms | 3536 KB |
018.txt | AC | 1 ms | 3488 KB |
019.txt | AC | 1 ms | 3524 KB |
020.txt | AC | 1 ms | 3636 KB |
021.txt | AC | 1 ms | 3456 KB |
022.txt | AC | 2 ms | 3556 KB |
023.txt | AC | 2 ms | 3452 KB |
024.txt | AC | 2 ms | 3548 KB |
025.txt | AC | 1 ms | 3412 KB |
026.txt | AC | 1 ms | 3536 KB |
027.txt | AC | 1 ms | 3516 KB |
028.txt | AC | 1 ms | 3560 KB |
029.txt | AC | 1 ms | 3476 KB |
030.txt | AC | 2 ms | 3520 KB |
031.txt | AC | 1 ms | 3612 KB |
032.txt | AC | 1 ms | 3532 KB |
033.txt | AC | 1 ms | 3516 KB |
034.txt | AC | 1 ms | 3492 KB |
035.txt | AC | 2 ms | 3480 KB |
036.txt | AC | 1 ms | 3416 KB |
037.txt | AC | 1 ms | 3552 KB |
example0.txt | AC | 1 ms | 3556 KB |
example1.txt | AC | 1 ms | 3452 KB |
example2.txt | AC | 1 ms | 3492 KB |
example3.txt | AC | 1 ms | 3520 KB |