比赛 |
20241022 |
评测结果 |
AAAAAAAAAAAAAAWWWWWW |
题目名称 |
移球游戏 |
最终得分 |
70 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
2.162 s |
代码语言 |
C++ |
内存使用 |
9.54 MiB |
提交时间 |
2024-10-22 11:20:15 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 60,M = 410;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m,p;
int a[N][M],top[N];
bool v[N];
vector<pii>ans;
void prin(int x,int y){
if(x == y)return;
a[y][++top[y]] = a[x][top[x]],a[x][top[x]--] = 0;
ans.pb({x,y});
}
//int del[N],cnt = 0;
int main(){
freopen("2020ball.in","r",stdin);
freopen("2020ball.out","w",stdout);
n = read(),m = read();
p = n + 1;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)a[i][j] = read(),top[i] = m;
// for(int i = 1;i <= m;i++)del[++cnt] = n + 1;
for(int i = 1;i < n;i++){
for(int j = 1;j < p;j++){
if(v[j])continue;
int s = 0,mi = n + 1;
for(int k = 1;k <= m;k++)if(a[j][k] == i)mi = min(mi,k),s++;
if(!s)continue;
int w = (j == p-1 ? j - 1 : j + 1);
for(int k = 1;k <= s;k++)prin(w,p);
for(int k = m;k >= 1;k--)
if(a[j][k] != i)prin(j,p);
else prin(j,w);
for(int k = m;k > s;k--)prin(p,j);
for(int k = 1;k <= s;k++)prin(w,j);
for(int k = s;k >= 1;k--)prin(p,w);
// cnt = m;
}
for(int j = p-1;j >= 1;j--){
int s = 0;
for(int k = m;k >= 1;k--){
if(a[j][k] != i)break;
prin(j,p),s++;
}
for(int k = 1;k <= s;k++)prin(p-1,j);
}
p = p - 1;
}
// printf("\n---------\n");
// for(int i = 1;i <= n + 1;i++){
// for(int j = 1;j <= m;j++)
// printf("%d ",a[i][j]);
// printf("\n----\n");
// }
printf("%d\n",(int)ans.size());
for(auto x : ans)printf("%d %d\n",x.fi,x.se);
return 0;
}