이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int R=0;
for (int i=0;i<N;i++)
for (int j=i+1;j<N;j++)
if (S[i]>S[j])R++;
if (R==0){P[0]=Q[0]=1;return 1;}
for (int i=0;i<M;i++){
int p1=X[i],p2=Y[i],start=0,ok=1;
swap(S[p1],S[p2]);
// for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n");
if (p1+p2==1&&S[p1]+S[p2]==1)start=2;
for (int j=start;j<N-1;j++)
if (S[j]!=j){
P[i]=j;Q[i]=S[j];
// printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,j,S[j],S[j],S[S[j]]);
swap(S[j],S[S[j]]);
// for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n");
ok=0;
int oo=1;
for (int i=0;i<N;i++)
if (S[i]!=i){oo=0;break;}
if (oo){
if (ok)P[i]=Q[i]=0;
return i;
}
break;
}
if (ok){
if (S[0]>S[1]){
P[i]=0;Q[i]=1;
// printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,0,S[0],1,S[1]);
swap(S[0],S[1]);
// for (int j=0;j<N;i++)printf("%d ",S[i]);printf("\n");
return i;
}else {
P[i]=Q[i]=0;
return i;
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:24:22: warning: declaration of 'i' shadows a previous local [-Wshadow]
for (int i=0;i<N;i++)
^
sorting.cpp:11:14: note: shadowed declaration is here
for (int i=0;i<M;i++){
^
sorting.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |