Submission #980063

# Submission time Handle Problem Language Result Execution time Memory
980063 2024-05-11T21:04:54 Z asdfgrace Art Collections (BOI22_art) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "art.h"
using namespace std;

#define dbg(x) x
#define prt(x) dbg(cerr << x)
#define pv(x) dbg(cerr << #x << " = " << x << '\n')
#define pv2(x) dbg(cerr << #x << " = " << x.first << ',' << x.second << '\n')
#define parr(x) dbg(prt(#x << " = { "); for (auto y : x) prt(y << ' '); prt("}\n");)
#define parr2(x) dbg(prt(#x << " = { "); for (auto [y, z] : x) prt(y << ',' << z << "  "); prt("}\n");)
#define parr2d(x) dbg(prt(#x << ":\n"); for (auto arr : x) {parr(arr);} prt('\n'));
#define parr2d2(x) dbg(prt(#x << ":\n"); for (auto arr : x) {parr2(arr);} prt('\n'));

/*
number of pairs (x, y)
so that g.at[x] < g.at[y] and r.at[x] > r.at[y]
what about pairs (x, y)
so that g.at[x] > g.at[y] and r.at[y] < r.at[x]
basically
number of "inversions" when you replace each value i in r with g.at[i]
when there are 0 inversions you just submit whatever you guessed g was
useful guesses?
identity permutation first obvs
g.at[i] = i for all i
gives number of inversions in r
can probably then find contribution of each index?
if we swap any two elements, does it reduce the number of inversions?
if yes, swap them; else don't
this should make n^2 guesses ez it's like bubble sort
can some other sort be applied here?
maybe some kind of sort calculating contribution of each elem?
like take the first element and make it last
so you find the rank of the first elem?
so you find how much the number of inversions changes by
and basically
the increase in the number of inversions
is probably useful
and can be used to determine the position of the element
dif = (elems after v[0]) - (elems before v[0])
-dif = (elems before v[0]) - (elems after v[0])

*/

void solve(int N) {
  vector<int> v(N), at(N);
  iota(v.begin(), v.end(), 1);
  for (int i = 0; i < N; i++) {
    int inv1 = publish(v);
    vector<int> v2;
    for (int i = 1; i < N; i++) v2.push_back(v[i]);
    v2.push_back(v[0]);
    int inv2 = publish(v2);
    int dif = inv1 - inv2, ind = (n - 1 + dif) / 2;
    at[v[0] - 1] = ind;
    swap(v, v2);
  }
  vector<int> res(N);
  for (int i = 0; i < N; i++) {
    res[at[i]] = i + 1;
  }
  answer(res);
}

Compilation message

art.cpp: In function 'void solve(int)':
art.cpp:53:35: error: 'n' was not declared in this scope
   53 |     int dif = inv1 - inv2, ind = (n - 1 + dif) / 2;
      |                                   ^
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) {
      |        ~~~~~~~~~^~~~