답안 #443685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443685 2021-07-11T11:44:20 Z valerikk Secret Permutation (RMI19_permutation) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#ifdef EVAL
#include "permutation.h"
#endif

typedef long long ll;
using namespace std;

#ifndef EVAL
int N;
int P[256 + 10];
#endif

int query(vector<int> v) {
#ifdef EVAL
    for (int &i : v) {
        i++;
    }
    return query(v);
#else
    int sum = 0;
    for (int i = 1; i < v.size(); i++)
        sum += abs(P[v[i]] - P[v[i - 1]]);
    return sum;
#endif
}

void answer(vector<int> p) {
    for (int &i : p) {
        i++;
    }
#ifdef EVAL
    answer(p);
#else
    for (int i = 0; i < p.size(); i++)
        cout << p[i] << " ";
#endif
}

void solve(int n) {
    auto get = [&](int a, int b, int c) {
        vector<int> p;
        for (int i = 0; i < n; i++) {
            if (i != a && i != b && i != c)
                p.push_back(i);
        }
        p.push_back(c);
        p.push_back(a);
        p.push_back(b);
        auto q = p;
        swap(q[n - 2], q[n - 1]);
        return query(p) - query(q);
    };

    int id = 1;
    for (int i = 2; i < n; i++) {
        if (get(id, i, 0) < 0)
            id = i;
    }
    vector<pair<int, int>> l, r;
    for (int i = 1; i < n; i++) {
        if (i != id) {
            int d = get(i, 0, id);
            if (d < 0)
                l.emplace_back(d, i);
            else
                r.emplace_back(d, i);
        }
    }
    vector<int> res(n);
    int cur = 0;
    res[id] = cur++;
    sort(l.begin(), l.end());
    for (auto [d, i] : l) res[i] = cur++;
    res[0] = cur++;
    sort(r.begin(), r.end());
    for (auto [d, i] : r) res[i] = cur++;
    answer(res);
}

#ifndef EVAL
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    solve(N);
}
#endif

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc3CwysC.o: in function `query(std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0x1d0): multiple definition of `query(std::vector<int, std::allocator<int> >)'; /tmp/ccZnQv8E.o:permutation.cpp:(.text+0x4b0): first defined here
/usr/bin/ld: /tmp/cc3CwysC.o: in function `answer(std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0x280): multiple definition of `answer(std::vector<int, std::allocator<int> >)'; /tmp/ccZnQv8E.o:permutation.cpp:(.text+0x600): first defined here
collect2: error: ld returned 1 exit status