답안 #833917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833917 2023-08-22T09:29:21 Z Ellinor 정렬하기 (IOI15_sorting) C++14
컴파일 오류
0 ms 0 KB
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>
#include <limits>
#include <map>
#include <assert.h>
#include <algorithm>
#include <list>
#include <iterator>
#include <fstream>
#include <random>
#include <unordered_map>
#include <array>

#define rep(i,a,b) for (int i = (a); i < b; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;
//typedef pair<int, int> pii;

// fast

vector<int> S;
vector<int> at;

#include "sorting.h" // !!

void swap(int a, int b)
{
    int tmp = S[a];
    S[a] = S[b];
    S[b] = tmp;

    at[S[a]] = a;
    at[S[b]] = b;
}

int findSwapPairs(int N, int ss[], int M, int X[], int Y[], int P[], int Q[])
{
    // P[0] = 0;
	// Q[0] = 0;

    S.assign(N, 0);
    rep(i,0,N) {
        S[i] = ss[i];
    }

    at.assign(N, 0);
    rep(i,0,N) {
        at[S[i]] = i;
    }

    int R = 0;
    rep(i,2,N)
    {
        if (S[i] != i) 
        {
            swap(X[R], Y[R]);
            R++;
            swap(at[i], i);
        }
    }

    // if (Y[0] == 0)
    // {
    //     if (S[0] != 0) R++;
    // }
    // else
    // {
    //     if (R % 2 == 0) if (S[0] != 0) R++;
    //     else if (S[1] != 0) R++;
    //     //
    // }

    if (S[0] != 0) R++;

	return R;
}

// 20p, 0, 0
// 16p, 0, 1, first all else, then 1 -> 1 (if needed)

Compilation message

sorting.cpp:29:1: error: 'vector' does not name a type
   29 | vector<int> S;
      | ^~~~~~
sorting.cpp:30:1: error: 'vector' does not name a type
   30 | vector<int> at;
      | ^~~~~~
sorting.cpp: In function 'void swap(int, int)':
sorting.cpp:36:15: error: 'S' was not declared in this scope
   36 |     int tmp = S[a];
      |               ^
sorting.cpp:40:5: error: 'at' was not declared in this scope; did you mean 'a'?
   40 |     at[S[a]] = a;
      |     ^~
      |     a
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:49:5: error: 'S' was not declared in this scope
   49 |     S.assign(N, 0);
      |     ^
sorting.cpp:54:5: error: 'at' was not declared in this scope
   54 |     at.assign(N, 0);
      |     ^~
sorting.cpp:44:40: warning: unused parameter 'M' [-Wunused-parameter]
   44 | int findSwapPairs(int N, int ss[], int M, int X[], int Y[], int P[], int Q[])
      |                                    ~~~~^
sorting.cpp:44:65: warning: unused parameter 'P' [-Wunused-parameter]
   44 | int findSwapPairs(int N, int ss[], int M, int X[], int Y[], int P[], int Q[])
      |                                                             ~~~~^~~
sorting.cpp:44:74: warning: unused parameter 'Q' [-Wunused-parameter]
   44 | int findSwapPairs(int N, int ss[], int M, int X[], int Y[], int P[], int Q[])
      |                                                                      ~~~~^~~