This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
int ok(vector<int>&a) {
forn(i,a.size()) if (a[i]!=i) return 0;
return 1;
}
struct DSU {
vector<int> p,sz;
DSU(int n) {
forn(i,n) p.pb(i), sz.pb(1);
}
int get(int u) {
return p[u]==u?u:get(p[u]);
}
void uni(int u, int v) {
u=get(u), v=get(v);
if (u==v) return;
if (sz[u]<sz[v]) swap(u,v);
sz[u]+=sz[v];
p[v]=u;
}
};
int findSwapPairs(int n, int _p[], int m, int _x[], int _y[], int p[], int q[]) {
vector<int> a;
forn(i,n) a.pb(_p[i]);
if (ok(a)) return 0;
vector<int> x,y;
forn(i,m) x.pb(_x[i]), y.pb(_y[i]);
x.pb(0), y.pb(0);
int z=1;
forn(i,m) z&=x[i]==y[i]&&x[i]==0;
if (z) {
int t=0;
while (!ok(a)) {
forn(i,n) {
if (a[i]!=i) {
p[t]=i, q[t]=a[i];
swap(a[i],a[a[i]]);
++t;
break;
}
}
}
return t;
}
z=1;
forn(i,m) z&=(x[i]==0) && (y[i]==1);
if (z) {
int t=0;
forn(it,m) {
swap(a[0],a[1]);
int b=0;
forn(i,n) {
if (i<2) continue;
if (a[i]!=i) {
p[t]=i, q[t]=a[i];
swap(a[i],a[a[i]]);
++t;
b=1;
break;
}
}
if (b) continue;
if (ok(a)) {
p[t]=0, q[t]=0; ++t;
return t;
} else {
p[t]=0, q[t]=1; ++t;
return t;
}
}
}
exit(1);
return 0;
}
Compilation message (stderr)
sorting.cpp: In function 'int ok(std::vector<int>&)':
sorting.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forn(i,n) for(int i=0;i<n;++i)
......
8 | forn(i,a.size()) if (a[i]!=i) return 0;
| ~~~~~~~~~~
sorting.cpp:8:5: note: in expansion of macro 'forn'
8 | forn(i,a.size()) if (a[i]!=i) return 0;
| ^~~~
# | 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... |