답안 #608954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608954 2022-07-27T11:27:50 Z Duy_e Monster Game (JOI21_monster) C++17
컴파일 오류
0 ms 0 KB
#include "monster.h"

using namespace std;

const long long N = 2e2 + 5;vector <int> save;

void rec(int l, int r, vector <int> &v) {
    if (l >= r) return;
    int pivot = l + rand() % (r - l + 1);
    vector <int> lef, rig;
    save.push_back(v[pivot]);

    
    for (int i = l; i <= r; i ++) if (i != pivot) {
        if (Query(v[pivot], v[i])) 
            lef.push_back(v[i]);
        else 
            rig.push_back(v[i]);
    }

    lef.push_back(v[pivot]);
    for (int i: rig) lef.push_back(i);

    int mid = 0;
    pivot = v[pivot];
    for (int i = 0; i < (r - l + 1); i ++) {
        if (lef[i] == pivot) mid = l + i;
        v[l + i] = lef[i];
    }
    cout << "here: " << pivot << '\n';
    for (int i: v) cout << i << ' '; cout << '\n';
    rec(l, mid - 1, v); rec(mid + 1, r, v);
}

vector<int> Solve(int n) {

  	vector<int> T(n);

    for (int i = 0; i < n; i ++) T[i] = i;

    rec(0, n - 1, T);

    reverse(save.begin(), save.end());
    cout << '\n';
    for (int pivot: save) {
        cout << pivot << '\n';
        for (int i = 0; i < n; i ++)
            if (T[i] == pivot) {
                if (i == 0) {
                    int l = i + 1, r = i + 2;
                    if (Query(T[i], T[r])) swap(T[i], T[r]);
                    break;
                }

                if (i == n - 1) {
                    cout << "check\n";
                    int l = i - 2, r = i - 1;
                    if (Query(T[l], T[i])) swap(T[l], T[i]);
                    break;
                }

                if (true) {
                    int l = i - 1, r = i + 1;
                    if (Query(T[l], T[r])) swap(T[l], T[r]);
                }
            } 
    }

    for (int i: T) cout << i << ' '; cout << '\n';

    vector <int> ret(n);
    for (int i = 0; i < n; i ++) {
        ret[T[i]] = i;
    }


	return ret;
}

Compilation message

monster.cpp: In function 'void rec(int, int, std::vector<int>&)':
monster.cpp:9:21: error: 'rand' was not declared in this scope
    9 |     int pivot = l + rand() % (r - l + 1);
      |                     ^~~~
monster.cpp:30:5: error: 'cout' was not declared in this scope
   30 |     cout << "here: " << pivot << '\n';
      |     ^~~~
monster.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include "monster.h"
  +++ |+#include <iostream>
    2 | 
monster.cpp:31:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   31 |     for (int i: v) cout << i << ' '; cout << '\n';
      |     ^~~
monster.cpp:31:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   31 |     for (int i: v) cout << i << ' '; cout << '\n';
      |                                      ^~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:43:5: error: 'reverse' was not declared in this scope
   43 |     reverse(save.begin(), save.end());
      |     ^~~~~~~
monster.cpp:44:5: error: 'cout' was not declared in this scope
   44 |     cout << '\n';
      |     ^~~~
monster.cpp:44:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
monster.cpp:50:25: warning: unused variable 'l' [-Wunused-variable]
   50 |                     int l = i + 1, r = i + 2;
      |                         ^
monster.cpp:57:36: warning: unused variable 'r' [-Wunused-variable]
   57 |                     int l = i - 2, r = i - 1;
      |                                    ^
monster.cpp:69:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   69 |     for (int i: T) cout << i << ' '; cout << '\n';
      |     ^~~
monster.cpp:69:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   69 |     for (int i: T) cout << i << ' '; cout << '\n';
      |                                      ^~~~