이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"sorting.h"
#include<bits/stdc++.h>
//#include"grader.cpp"
using namespace std;
int n,s[800005],x[800005],y[800005],tmp[800005],pos[800005];
vector<pair<int,int>>res;
bool check(int m){
int i;
for(i=0;i<n;i++)tmp[i]=s[i];
for(i=0;i<m;i++)swap(tmp[x[i]],tmp[y[i]]);
for(i=0;i<n;i++)pos[tmp[i]]=i;
vector<pair<int,int>>sw;
res.clear();
for(i=0;i<n;i++){
if(pos[i]==i)continue;
sw.push_back({tmp[i],tmp[pos[i]]});
swap(tmp[pos[i]],tmp[i]);
swap(pos[tmp[pos[i]]],pos[tmp[i]]);
}
if(sw.size()>m)return 0;
for(i=0;i<n;i++)tmp[i]=s[i],pos[tmp[i]]=i;
for(i=0;i<sw.size();i++){
swap(tmp[x[i]],tmp[y[i]]);
swap(pos[tmp[x[i]]],pos[tmp[y[i]]]);
res.push_back({pos[sw[i].first],pos[sw[i].second]});
swap(tmp[pos[sw[i].first]],tmp[pos[sw[i].second]]);
swap(pos[tmp[pos[sw[i].first]]],pos[tmp[pos[sw[i].second]]]);
}
for(;i<m;i++)res.push_back({0,0});
return 1;
}
int findSwapPairs(int N,int S[],int m,int X[],int Y[],int P[],int Q[]){
n=N;
int i;
for(i=0;i<n;i++)s[i]=S[i];
for(i=0;i<m;i++)x[i]=X[i];
for(i=0;i<m;i++)y[i]=Y[i];
check(m);
for(i=0;i<m;i++)P[i]=res[i].first,Q[i]=res[i].second;
return m;
}
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'bool check(int)':
sorting.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(sw.size()>m)return 0;
| ~~~~~~~~~^~
sorting.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(i=0;i<sw.size();i++){
| ~^~~~~~~~~~
# | 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... |