Submission #1344122

#TimeUsernameProblemLanguageResultExecution timeMemory
1344122nikaa123Art Collections (BOI22_art)C++20
100 / 100
680 ms480 KiB
#include "art.h"
#include <bits/stdc++.h>
using namespace std;
//
// --- Sample implementation for the task art ---
//
// To compile this program with the sample grader, place:
//     art.h art_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
//     g++ -std=c++17 art_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
// 
void solve(int n) {
    
    #define all(x) (x).begin(),(x).end()
    #define eb emplace_back

    vector <int> v(n);
    iota(all(v),1);
    int c = publish(v);
    vector <int> pos(n+1,-1);
    auto f = [](int s, int d) {
        int a = -1; int b = -1;
        // a+b == s
        // a-b == d
        // 2a == s+d 
        a = (s+d)/2;
        // b = s - a;
        b = s - a;
        return make_pair(a,b);
    };  
    for (int i = 1; i <= n-1; i++) {
        v.erase(v.begin()); v.eb(i);
        int nc = publish(v);
        int sum = n-1;
        int dif = c - nc;
        auto [a,b] = f(sum,dif);
        // cout << i << " ---> " << a << " " << b << endl;
        pos[i] = a;
        c = nc;
    }
    vector <int> ans(n,-1);
    for (int i = 1; i <= n-1; i++) {
        ans[pos[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] == -1) {
            ans[i] = n;
            break;
        }
    }
    answer(ans);

}
#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...