제출 #252180

#제출 시각아이디문제언어결과실행 시간메모리
252180Hehehe정렬하기 (IOI15_sorting)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "sorting.h"

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll H = 2e3 + 11;

//ifstream in(".in");
//ofstream out(".out");

int pos[H];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

    int n = N, m = M, cur = 0;


    for(int i = 0; i < n; i++){
        pos[S[i]] = i;
        if(X[i] == 0 && Y[i] == 0)cur++;
    }

    vector<pi>ans;

    if(cur == n){//subtask 1, 2

        for(int i = 0; i < n; i++){
            if(S[i] == i)continue;
            ans.push_back({i, pos[i]});
            int x = i, y = S[i];
            swap(S[i], S[pos[i]]);
            pos[y] = pos[i];
            pos[x] = x;
        }

        int k = 0;
        for(auto it : ans){
            P[k] = it.ff;
            Q[k] = it.ss;
            k++;
        }

        return sz(ans);
    }else{//subtask 3
        
        swap(S[0], S[1]); //Ermek first move
        pos[S[0]] = 0;
        pos[S[1]] = 1;

        ans.push_back({pos[0], 1});
        pos[S[1]] = pos[0];
        pos[0] = 0;
        //we put 0 on pos 1 then he swaps (0, 1) so we have the form 0, x, ..

        ans.push_back(pos[1], 1);
        pos[S[0]] = pos[1];
        pos[1] = 1;
        //we put 1 on pos 1 then he swaps (0, 1) so we have the form 1, 0, ..

        S[0] = 1;
        S[1] = 0;
        
        for(int i = 2; i < n; i++){
            if(S[i] == i)continue;
            ans.push_back({i, pos[i]});
            int x = i, y = S[i];
            swap(S[i], S[pos[i]]);
            pos[y] = pos[i];
            pos[x] = x;

            //his move
            swap(S[0], S[1]);
        }

        if(S[0] != 0)ans.push_back({0, 1});

        int k = 0;
        for(auto it : ans){
            P[k] = it.ff;
            Q[k] = it.ss;
            k++;
        }

        return sz(ans);

    }
}

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:66:32: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, int)'
         ans.push_back(pos[1], 1);
                                ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from sorting.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   candidate expects 1 argument, 2 provided
sorting.cpp:26:16: warning: unused variable 'm' [-Wunused-variable]
     int n = N, m = M, cur = 0;
                ^