Submission #291527

#TimeUsernameProblemLanguageResultExecution timeMemory
291527MarcoMeijerSorting (IOI15_sorting)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h>

using namespace std;

#include "sorting.h"

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

const int MX = 2e5+100;

int a[MX], sa[MX];

void swapA(int x, int y) {
    swap(a[x], a[y]);
    sa[a[x]] = x;
    sa[a[y]] = y;
}

int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[]) {
    RE(i,n) a[i]=sa[i]=i;
    RE(i,n) {
        swapA(sa[X[i]], sa[Y[i]]);
    }
    int R = 0;
    RE(i,n) {
        R++;

        int x=0, y=0;
        RE(j,n) if(S[j] == i) x = j;
        RE(j,n) if(a[j] == i) y = j;
        y = i;

        swap(S[x], S[y]);

        P[i] = x;
        Q[i] = y;

        bool sorted = 1;
        RE(i,n) if(S[i] != i) sorted = 0;
        if(sorted) break;
    }
    return R;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:58:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
   58 |         RE(i,n) if(S[i] != i) sorted = 0;
      |            ^
sorting.cpp:17:28: note: in definition of macro 'REP'
   17 | #define REP(a,b,c) for(int a=int(b); a<int(c); a++)
      |                            ^
sorting.cpp:58:9: note: in expansion of macro 'RE'
   58 |         RE(i,n) if(S[i] != i) sorted = 0;
      |         ^~
sorting.cpp:44:8: note: shadowed declaration is here
   44 |     RE(i,n) {
      |        ^
sorting.cpp:17:28: note: in definition of macro 'REP'
   17 | #define REP(a,b,c) for(int a=int(b); a<int(c); a++)
      |                            ^
sorting.cpp:44:5: note: in expansion of macro 'RE'
   44 |     RE(i,n) {
      |     ^~
sorting.cpp:38:39: warning: unused parameter 'm' [-Wunused-parameter]
   38 | int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...