Codeforces 1283C Friends and Gifts
1983 단어 Codeforces
#include
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define fi first
#define sc second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pt(a) cerr<#define rp(i,n) for(int i=0;i
#define rpn(i,n) for(int i=1;i<=n;i++)
const int maxn=2e5+5;
int f[maxn];
bool flag[maxn];
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin>>n;
rpn(i,n){
cin>>f[i]; flag[f[i]]=true;
}
vector<int> a,b;
rpn(i,n){
if(f[i]==0) a.pb(i);
if(flag[i]==false) b.pb(i);
}
int sz=a.size();
for(int i=0;i<sz;i++){
if(a[i]==b[i]){
int x=i,y=(i+1)%sz;
swap(b[x],b[y]);
}
}
rp(i,sz) f[a[i]]=b[i];
rpn(i,n) cout<<f[i]<<' ';
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
CF1303E - Erase Subsequences DP문자열의 길이를 보면 O(N3)O(N^3)O(N3)O(N3)의 가장 직접적인 생각은 tt열을 두 부분으로 나누어 t1, t2t1, t2t1, t2t1, t2t2, 그리고 ss열을 매칭하는 것이다. t2는 같은 문자를...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.