Submission #432600

# Submission time Handle Problem Language Result Execution time Memory
432600 2021-06-18T11:31:54 Z 2qbingxuan Sorting (IOI15_sorting) C++14
0 / 100
2 ms 460 KB
#include "sorting.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\e[1;32m(" << s << ") = ("), ..., (std::cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\e[0m\n";
}
#else
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    vector<int> targ(N);
    for (int i = 0; i < N; i++) targ[i] = i;
    for (int i = M-1; i >= 0; i--)
        swap(targ[X[i]], targ[Y[i]]);
    vector<int> s(S, S+N);
    vector<int> pos(N);
    for (int i = 0; i < N; i++)
        pos[s[i]] = i;
    vector<pair<int,int>> ans;
    for (int i = 0, it = 0; i < M; i++) {
        {
            int a = X[i], b = Y[i];
            swap(targ[a], targ[b]);
            swap(pos[s[a]], pos[s[b]]);
            swap(s[a], s[b]);
        }
        {
            while (it < N && pos[it] == pos[targ[pos[it]]]) ++it;
            if (it == N) {
                ans.emplace_back(0, 0);
            } else {
                ;
                int a = pos[it];
                int b = pos[targ[a]];
                swap(pos[s[a]], pos[s[b]]);
                swap(s[a], s[b]);
                ans.emplace_back(a, b);
            }
        }
    }
    pary(all(s));
    for (size_t i = 0; i < ans.size(); i++)
        tie(P[i], Q[i]) = ans[i];
    return ans.size();
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:60:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   60 |     return ans.size();
      |            ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -