Submission #1039875

# Submission time Handle Problem Language Result Execution time Memory
1039875 2024-07-31T11:18:37 Z c2zi6 Sorting (IOI15_sorting) C++14
20 / 100
5 ms 348 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 {\
        while (ans.size() && ans.back().ff == ans.back().ss) ans.pop_back();\
        rep(i, ans.size()) {\
            P[i] = ans[i].ff;\
            Q[i] = ans[i].ss;\
        }\
        return ans.size();\
    }
#define UPDATE(u, v) {\
        if (issorted()) ANSWER;\
        swap(a[u], a[v]);\
        rep(i, n) ind[a[i]] = i;\
    }
#define MYSTEP(u, v) {\
        ans.pb({u, v});\
        UPDATE(u, v);\
        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;
    };
    int ptr = 0;
    UPDATE(X[ptr], Y[ptr]);
    ptr++;

    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:40:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   40 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:43:25: note: in expansion of macro 'ANSWER'
   43 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:67:5: note: in expansion of macro 'UPDATE'
   67 |     UPDATE(X[ptr], Y[ptr]);
      |     ^~~~~~
sorting.cpp:36:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   36 |         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:43:25: note: in expansion of macro 'ANSWER'
   43 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:49:9: note: in expansion of macro 'UPDATE'
   49 |         UPDATE(u, v);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:70:9: note: shadowed declaration is here
   70 |     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:40:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   40 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:43:25: note: in expansion of macro 'ANSWER'
   43 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:49:9: note: in expansion of macro 'UPDATE'
   49 |         UPDATE(u, v);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:45:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   45 |         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(u, v);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:70:9: note: shadowed declaration is here
   70 |     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:36:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   36 |         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:43:25: note: in expansion of macro 'ANSWER'
   43 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:50:9: note: in expansion of macro 'UPDATE'
   50 |         UPDATE(X[ptr], Y[ptr]);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:70:9: note: shadowed declaration is here
   70 |     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:40:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   40 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:43:25: note: in expansion of macro 'ANSWER'
   43 |         if (issorted()) ANSWER;\
      |                         ^~~~~~
sorting.cpp:50:9: note: in expansion of macro 'UPDATE'
   50 |         UPDATE(X[ptr], Y[ptr]);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:45:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
   45 |         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:50:9: note: in expansion of macro 'UPDATE'
   50 |         UPDATE(X[ptr], Y[ptr]);\
      |         ^~~~~~
sorting.cpp:71:9: note: in expansion of macro 'MYSTEP'
   71 |         MYSTEP(ind[i], i);
      |         ^~~~~~
sorting.cpp:70:9: note: shadowed declaration is here
   70 |     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:40:24: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   40 |         return ans.size();\
      |                ~~~~~~~~^~
sorting.cpp:73:5: note: in expansion of macro 'ANSWER'
   73 |     ANSWER;
      |     ^~~~~~
sorting.cpp:54:39: warning: unused parameter 'M' [-Wunused-parameter]
   54 | 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 344 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 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 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -