QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116121 | #5280. Depot Rearrangement | lcjlcj# | Compile Error | / | / | C++20 | 1.8kb | 2023-06-28 09:59:44 | 2024-05-31 14:20:52 |
Judging History
你现在查看的是最新测评结果
- [2024-05-31 14:20:52]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-06-28 09:59:44]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=1605;
int n,m;
int ecnt;
vector<pair<int,int>> g[maxn+5];
vector<int> cnt[maxn+5][maxn+5];
vector<pair<int,int>> ans;
int sta[maxn*maxn+5],top;
int cur[maxn+5],vis[maxn+5];
bool flg[maxn*maxn+5],flg2[maxn*maxn+5];
void dfs(int u) {
vis[u]=1;
for (int &i=cur[u];i<g[u].size();i++) {
int v=g[u][i].first,w=g[u][i].second;
if (w<0) {
if (flg2[-w]) continue ;
flg2[-w]=1;
}
else {
if (flg[w]) continue ;
flg[w]=1;
}
dfs(v);
if (w>0) sta[++top]=w;
}
}
void makeswap(int u,int v) {
ans.emplace_back(u,v);
swap(A[u],A[v]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
int t;
cin>>t;
int id=(i-1)*m+j;
A[id]=t;
cnt[i][t].emplace_back(id);
}
for (int j=1;j<=m;j++) {
if (cnt[i][j].size()==0) {
g[i].emplace_back(j+n,--ecnt);
} else if (cnt[i][j].size()>=2) {
for (int k=0;k<cnt[i][j].size()-1;k++) {
g[j+n].emplace_back(i,cnt[i][j][k]);
}
}
}
}
int lst=n*m+1;
for (int i=n+1;i<=n+m;i++) {
if (!vis[i]) {
top=0;
dfs(i);
if (top==1) continue ;
makeswap(sta[top],lst);
for (int j=top;j>=2;j--) makeswap(sta[j-1],sta[j]);
makeswap(lst,sta[1]);
}
}
for (int i=1;i<=n*m+1;i++) {
cout<<A[i]<<' ';
}
cout<<'\n';
cout<<ans.size()<<'\n';
for (auto [x,y]:ans) cout<<x<<' '<<y<<'\n';
return 0;
}
Details
answer.code: In function ‘void makeswap(int, int)’: answer.code:33:10: error: ‘A’ was not declared in this scope 33 | swap(A[u],A[v]); | ^ answer.code: In function ‘int main()’: answer.code:45:13: error: ‘A’ was not declared in this scope 45 | A[id]=t; | ^ answer.code:71:15: error: ‘A’ was not declared in this scope 71 | cout<<A[i]<<' '; | ^