이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"sorting.h"
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x,begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
int ss[2010];
rep(i,N)ss[i]=S[i];
int R=0;
for(;;R++){
swap(S[X[R]],S[Y[R]]);
ll cnt=0,s[2010];
rep(i,N)s[i]=S[i];
//cout<<R<<"-";rep(i,N)cout<<"S:"<<s[i]<<endl;
rep(i,N){
ll p;
rep(j,N)if(i==s[j])p=j;
if(i!=p){
cnt++;
swap(s[i],s[p]);
}
}
if(cnt<=R+1){
R++;
cnt=0;
rep(i,N)s[i]=S[i];
rep(i,N){
ll p;
rep(j,N)if(i==s[j])p=j;
if(i!=p){
P[cnt]=s[i],Q[cnt]=s[p],cnt++;
swap(s[i],s[p]);
}
}
//assert(cnt==R);
for(;cnt<R;cnt++)P[cnt]=Q[cnt]=0;
//rep(i,R+1)cout<<"PQ:"<<P[i]<<" "<<Q[i]<<endl;
for(int i=0;i<cnt;i++){
swap(ss[X[i]],ss[Y[i]]);
ll place_p,place_q;
rep(j,N){
if(ss[j]==P[i])place_p=j;
if(ss[j]==Q[i])place_q=j;
}
swap(ss[place_p],ss[place_q]);
P[i]=place_p,Q[i]=place_q;
}
return R;
}
}
return -1;
}
/*
int main(){
int n,s[100],m,x[1000],y[1000],p[1000],q[1000];
cin>>n;
rep(i,n)cin>>s[i];
cin>>m;
rep(i,m){
cin>>x[i]>>y[i];
}
cout<<"R="<<findSwapPairs(n,s,m,x,y,p,q)<<endl;
}*/
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:39:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
P[cnt]=s[i],Q[cnt]=s[p],cnt++;
~~~^
sorting.cpp:39:28: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
P[cnt]=s[i],Q[cnt]=s[p],cnt++;
~~~^
sorting.cpp:54:10: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
P[i]=place_p,Q[i]=place_q;
^~~~~~~
sorting.cpp:54:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
P[i]=place_p,Q[i]=place_q;
^~~~~~~
sorting.cpp:14:37: warning: unused parameter 'M' [-Wunused-parameter]
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
^
sorting.cpp:38:5: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(i!=p){
^~
sorting.cpp:26:4: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(i!=p){
^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |