Submission #1040001

# Submission time Handle Problem Language Result Execution time Memory
1040001 2024-07-31T13:50:29 Z c2zi6 Sorting (IOI15_sorting) C++14
36 / 100
3 ms 604 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "sorting.h"

#define ANSWER {\
        rep(i, ans.size()) {\
            P[i] = ans[i].ff;\
            Q[i] = ans[i].ss;\
        }\
        return ans.size();\
    }
#define UPDATE(u, v) {\
        swap(a[u], a[v]);\
        rep(i, n) ind[a[i]] = i;\
    }
#define MYSTEP(u, v) {\
        ans.pb({u, v});\
        UPDATE(u, v);\
        if (issorted()) ANSWER;\
        UPDATE(X[ptr], Y[ptr]);\
        ptr++;\
    }

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    VPI ans;
    int n = N;
    VI a(n);
    rep(i, n) a[i] = S[i];
    VI ind(n);
    auto issorted = [&]() {
        rep(i, n) if (i != a[i]) return false;
        return true;
    };
    bool sub3 = false;
    if (X[0] == 0 && Y[0] == 1) sub3 = true;


    if (issorted()) ANSWER;
    int ptr = 0;
    UPDATE(X[ptr], Y[ptr]);
    ptr++;

    if (sub3) {
        if (ind[0] > 1) {
            if (ind[1] == 0) {
                MYSTEP(ind[0], 1);
            } else {
                MYSTEP(ind[0], 0);
            }
        }
        if (ind[1] > 1) {
            if (ind[0] == 1) {
                MYSTEP(ind[1], 0);
            } else {
                MYSTEP(ind[1], 1);
            }
        }
        replr(i, 2, n-1) {
            MYSTEP(ind[i], i);
        }
        MYSTEP(0, 0);
    } else {
        rep(i, n) {
            MYSTEP(ind[i], i);
        }
    }
    ANSWER;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:67:21: note: in expansion of macro 'ANSWER'
   67 |     if (issorted()) ANSWER;
      |                     ^~~~~~
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:75:17: note: in expansion of macro 'MYSTEP'
   75 |                 MYSTEP(ind[0], 1);
      |                 ^~~~~~
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:77:17: note: in expansion of macro 'MYSTEP'
   77 |                 MYSTEP(ind[0], 0);
      |                 ^~~~~~
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:82:17: note: in expansion of macro 'MYSTEP'
   82 |                 MYSTEP(ind[1], 0);
      |                 ^~~~~~
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:84:17: note: in expansion of macro 'MYSTEP'
   84 |                 MYSTEP(ind[1], 1);
      |                 ^~~~~~
sorting.cpp:43:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   43 |         rep(i, n) ind[a[i]] = i;\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:47:9: note: in expansion of macro 'UPDATE'
   47 |         UPDATE(u, v);\
      |         ^~~~~~
sorting.cpp:88:13: note: in expansion of macro 'MYSTEP'
   88 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:87:15: note: shadowed declaration is here
   87 |         replr(i, 2, n-1) {
      |               ^
sorting.cpp:7:33: note: in definition of macro 'replr'
    7 | #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
      |                                 ^
sorting.cpp:35:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   35 |         rep(i, ans.size()) {\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:88:13: note: in expansion of macro 'MYSTEP'
   88 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:87:15: note: shadowed declaration is here
   87 |         replr(i, 2, n-1) {
      |               ^
sorting.cpp:7:33: note: in definition of macro 'replr'
    7 | #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
      |                                 ^
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:88:13: note: in expansion of macro 'MYSTEP'
   88 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:43:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   43 |         rep(i, n) ind[a[i]] = i;\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:49:9: note: in expansion of macro 'UPDATE'
   49 |         UPDATE(X[ptr], Y[ptr]);\
      |         ^~~~~~
sorting.cpp:88:13: note: in expansion of macro 'MYSTEP'
   88 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:87:15: note: shadowed declaration is here
   87 |         replr(i, 2, n-1) {
      |               ^
sorting.cpp:7:33: note: in definition of macro 'replr'
    7 | #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
      |                                 ^
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:90:9: note: in expansion of macro 'MYSTEP'
   90 |         MYSTEP(0, 0);
      |         ^~~~~~
sorting.cpp:43:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   43 |         rep(i, n) ind[a[i]] = i;\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:47:9: note: in expansion of macro 'UPDATE'
   47 |         UPDATE(u, v);\
      |         ^~~~~~
sorting.cpp:93:13: note: in expansion of macro 'MYSTEP'
   93 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:92:13: note: shadowed declaration is here
   92 |         rep(i, n) {
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:35:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   35 |         rep(i, ans.size()) {\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:93:13: note: in expansion of macro 'MYSTEP'
   93 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:92:13: note: shadowed declaration is here
   92 |         rep(i, n) {
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:48:25: note: in expansion of macro 'ANSWER'
   48 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:93:13: note: in expansion of macro 'MYSTEP'
   93 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:43:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   43 |         rep(i, n) ind[a[i]] = i;\
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:49:9: note: in expansion of macro 'UPDATE'
   49 |         UPDATE(X[ptr], Y[ptr]);\
      |         ^~~~~~
sorting.cpp:93:13: note: in expansion of macro 'MYSTEP'
   93 |             MYSTEP(ind[i], i);
      |             ^~~~~~
sorting.cpp:92:13: note: shadowed declaration is here
   92 |         rep(i, n) {
      |             ^
sorting.cpp:9:28: note: in definition of macro 'rep'
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                            ^
sorting.cpp:39:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   39 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:96:5: note: in expansion of macro 'ANSWER'
   96 |     ANSWER;
      |     ^~~~~~
sorting.cpp:53:39: warning: unused parameter 'M' [-Wunused-parameter]
   53 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 504 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 416 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 504 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 440 KB Output is correct
16 Correct 0 ms 416 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 440 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -