Please sign in first.
Submission #48405945
Source Code Expand
#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 KiB |
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 KiB |
| 001.txt | AC | 1 ms | 3556 KiB |
| 002.txt | AC | 1 ms | 3644 KiB |
| 003.txt | AC | 1 ms | 3492 KiB |
| 004.txt | AC | 1 ms | 3492 KiB |
| 005.txt | AC | 1 ms | 3472 KiB |
| 006.txt | AC | 2 ms | 3484 KiB |
| 007.txt | AC | 2 ms | 3472 KiB |
| 008.txt | AC | 2 ms | 3476 KiB |
| 009.txt | AC | 1 ms | 3456 KiB |
| 010.txt | AC | 1 ms | 3532 KiB |
| 011.txt | AC | 1 ms | 3492 KiB |
| 012.txt | AC | 1 ms | 3496 KiB |
| 013.txt | AC | 1 ms | 3484 KiB |
| 014.txt | AC | 1 ms | 3556 KiB |
| 015.txt | AC | 1 ms | 3488 KiB |
| 016.txt | AC | 1 ms | 3428 KiB |
| 017.txt | AC | 1 ms | 3536 KiB |
| 018.txt | AC | 1 ms | 3488 KiB |
| 019.txt | AC | 1 ms | 3524 KiB |
| 020.txt | AC | 1 ms | 3636 KiB |
| 021.txt | AC | 1 ms | 3456 KiB |
| 022.txt | AC | 2 ms | 3556 KiB |
| 023.txt | AC | 2 ms | 3452 KiB |
| 024.txt | AC | 2 ms | 3548 KiB |
| 025.txt | AC | 1 ms | 3412 KiB |
| 026.txt | AC | 1 ms | 3536 KiB |
| 027.txt | AC | 1 ms | 3516 KiB |
| 028.txt | AC | 1 ms | 3560 KiB |
| 029.txt | AC | 1 ms | 3476 KiB |
| 030.txt | AC | 2 ms | 3520 KiB |
| 031.txt | AC | 1 ms | 3612 KiB |
| 032.txt | AC | 1 ms | 3532 KiB |
| 033.txt | AC | 1 ms | 3516 KiB |
| 034.txt | AC | 1 ms | 3492 KiB |
| 035.txt | AC | 2 ms | 3480 KiB |
| 036.txt | AC | 1 ms | 3416 KiB |
| 037.txt | AC | 1 ms | 3552 KiB |
| example0.txt | AC | 1 ms | 3556 KiB |
| example1.txt | AC | 1 ms | 3452 KiB |
| example2.txt | AC | 1 ms | 3492 KiB |
| example3.txt | AC | 1 ms | 3520 KiB |