Submission #625241

#TimeUsernameProblemLanguageResultExecution timeMemory
625241Ooops_sorryArt Collections (BOI22_art)C++17
100 / 100
1939 ms564 KiB
#include<bits/stdc++.h>
#ifndef LOCAL
    #include "art.h"
#endif // LOCAL

#define pb push_back

using namespace std;

#ifdef LOCAL

void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...) {
    va_list args;
    va_start(args, msg);
    vfprintf(stdout, msg, args);
    fprintf(stdout, "\n");
    va_end(args);
    exit(0);
}

namespace {
    int N;
    int Q = 0;
    const int MAX_Q = 4000;
    const int MAX_N = 4000;
    vector<int> solution;
}  // namespace

int publish(vector<int> R) {
    printf("publish({");
    for(int i = 0; i < int(R.size()); ++i) {
        if(i == 0)
            printf("%d", R[i]);
        else
            printf(", %d", R[i]);
    }
    printf("})\n");
    fflush(stdout);

    if (++Q > MAX_Q)
        result("Too many published rankings!");

    if (int(R.size()) != N)
        result("Invalid published ranking!");

    set<int> chosen;
    for(auto &x : R) {
        if(x < 1 || x > N || chosen.count(x))
            result("Invalid published ranking!");
        chosen.insert(x);
    }
    vector<int> positions(N+1);
    for(int i = 0; i < N; ++i)
        positions[R[i]] = i;

    int complaints = 0;
    for(int i = 0; i < N; ++i) {
        cout << positions[solution[i]] << ' ';
        for(int j = i+1; j < N; ++j) {
            if(positions[solution[i]] > positions[solution[j]])
                ++complaints;
        }
    }
    cout << endl;
    return complaints;
}

void __attribute__((noreturn)) answer(vector<int> R) {
    printf("answer({");
    for(int i = 0; i < int(R.size()); ++i) {
        if(i == 0)
            printf("%d", R[i]);
        else
            printf(", %d", R[i]);
    }
    printf("})\n");
    fflush(stdout);


    if(R == solution)
        result("Correct: %d published ranking(s).", Q);
    else
        result("Wrong answer!");
}

#endif

int ask(int i, int n) {
    vector<int> a;
    int now = 0;
    for (int j = n - i + 1; j <= n; j++) a.pb(j);
    for (int j = 1; j <= n - i; j++) a.pb(j);
    return publish(a);
}

void solve(int n) {
    vector<int> a, ans(n);
    for (int i = 0; i < n; i++) {
        a.pb(ask(i, n));
    }
    for (int i = 0; i < n; i++) {
        int now = a[i];
        int nxt = a[(i + 1) % n];
        for (int j = 1; j <= n; j++) {
            if (2 * j - n - 1 == nxt - now) {
                ans[j - 1] = n - i;
                break;
            }
            if (n == j) assert(0);
        }
    }
    answer(ans);
}

#ifdef LOCAL

int main() {
    if (scanf("%d", &N) != 1 || N < 2 || N > MAX_N)
        result("Invalid input!");

    solution.resize(N);
    set<int> chosen;
    vector<int> arr(N);
    iota(arr.begin(), arr.end(), 1);
    random_shuffle(arr.begin(), arr.end());
    int i = 0;
    for(int j = 0; j < N; j++) {
        solution[j] = arr[i++];
        chosen.insert(solution[j]);
    }
    for (auto to : solution) {
        cout << to << ' ';
    }
    cout << endl;
    solve(N);

    result("No answer!");
}

#endif

Compilation message (stderr)

art.cpp: In function 'int ask(int, int)':
art.cpp:90:9: warning: unused variable 'now' [-Wunused-variable]
   90 |     int now = 0;
      |         ^~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...