Submission #1039940

#TimeUsernameProblemLanguageResultExecution timeMemory
1039940ZicrusSorting (IOI15_sorting)C++17
0 / 100
5 ms348 KiB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;

typedef long long ll;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    ll res = 0;
    vector<ll> s(N);
    for (int i = 0; i < N; i++) s[i] = S[i];

    vector<ll> order = s;
    ll g = M;
    for (int j = 0; j < M; j++) {
        swap(order[X[j]], order[Y[j]]);
        ll ooo = 0;
        for (int i = 0; i < N; i++) {
            if (order[i] != i) ooo++;
        }
        if (ooo/2 <= j) { g = j; break; }
    }

    for (int i = 0; i < g; i++) {
        swap(s[X[i]], s[Y[i]]);
        vector<ll> order = s;
        for (int j = i+1; j < M; j++) {
            swap(order[X[j]], order[Y[j]]);
        }
        int firstOut = -1, id = -1;
        for (int j = 0; j < N; j++) {
            if (order[j] != j) {
                firstOut = order[id = j];
                break;
            }
        }
        if (firstOut == -1) {
            P[res] = Q[res] = 0;
            res++;
        }
        else {
            ll v = *find(order.begin(), order.end(), id);

            ll id1 = find(s.begin(), s.end(), firstOut) - s.begin();
            ll id2 = find(s.begin(), s.end(), v) - s.begin();
            swap(s[id1], s[id2]);
            P[res] = id1;
            Q[res] = id2;
            res++;
        }

        firstOut = -1;
        for (int j = 0; j < N; j++) {
            if (s[j] != j) {
                firstOut = s[j];
                break;
            }
        }
        if (firstOut == -1) return res;
    }

    P[res] = Q[res] = 0;
    res++;
	return res;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:25:20: warning: declaration of 'order' shadows a previous local [-Wshadow]
   25 |         vector<ll> order = s;
      |                    ^~~~~
sorting.cpp:12:16: note: shadowed declaration is here
   12 |     vector<ll> order = s;
      |                ^~~~~
sorting.cpp:32:40: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 |                 firstOut = order[id = j];
      |                                        ^
sorting.cpp:46:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   46 |             P[res] = id1;
      |                      ^~~
sorting.cpp:47:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   47 |             Q[res] = id2;
      |                      ^~~
sorting.cpp:54:31: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   54 |                 firstOut = s[j];
      |                               ^
sorting.cpp:58:36: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   58 |         if (firstOut == -1) return res;
      |                                    ^~~
sorting.cpp:63:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   63 |  return res;
      |         ^~~
#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...