题面
https://www.luogu.org/problem/P1963
题解
// luogu-judger-enable-o2 #include<iostream> #include<cstdio> #include<cstring> #include<vector> #define ri register int #define N 10500 using namespace std; int read() { int ret=0,f=0; char ch=getchar(); while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar(); while (ch>='0' && ch<='9') ret=ret*10+(ch-'0'),ch=getchar(); return f?-ret:ret; } int n,tim; int vis[N],match[N],ans[N]; vector<int> to[N]; bool dfs(int x) { for (ri i=0;i<to[x].size();i++) { int y=to[x][i]; if (vis[y]==tim) continue; vis[y]=tim; if (!match[y] || dfs(match[y])) { match[y]=x; return 1; } } return 0; } int main() { n=read(); for (ri i=1;i<=n;i++) { int x=read(); int a=(i-1+x)%n+1; int b=(i-1+n-x)%n+1; if (a==b) to[i].push_back(a); else to[i].push_back(min(a,b)),to[i].push_back(max(a,b)); } tim=0; for (ri i=n;i>=1;i--) { ++tim; if (!dfs(i)) { puts("No Answer"); return 0; } } for (ri i=1;i<=n;i++) ans[match[i]]=i; for (ri i=1;i<=n;i++) printf("%d ",ans[i]-1); return 0; }