Submission #398583

# Submission time Handle Problem Language Result Execution time Memory
398583 2021-05-04T15:03:49 Z MarcoMeijer Mouse (info1cup19_mouse) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e18
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(,' ',;}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
// dp
template<class T> bool ckmin(T&a, T&b) { bool bl = a > b; a = min(a,b); return bl;}
template<class T> bool ckmax(T&a, T&b) { bool bl = a < b; a = max(a,b); return bl;}

//   begin program   //
const int MX = 5e5;
const int N = (1<<20);

int query(vi q);

vi findEmpty(int n) {
    vi perm;
    RE1(i,n) perm.pb(i);

    while(true) {
        random_shuffle(all(perm),[](int i){return rng()%i;});
        int res = query(perm);
        if(res == n) return {};
        if(res == 0) return perm;

void solve(int n) {
    vi f = findEmpty(n);
    if(f.empty()) return;

    vector<vii> rounds; rounds.resize(n);
    RE(i,n) RE(j,i) {
        int cr = (i+j)%n;

    // finding good swaps
    vii goodSwaps;
    FOR(v,rounds) {
        FOR(p,v) swap(f[], f[]);
        int res = query(f);
        FOR(p,v) swap(f[], f[]);
        if(res == n) return;
        while(res) {
            int lb=1, ub=v.size();
            while(lb != ub) {
                int mid=(lb+ub)/2;
                RE(i,mid) swap(f[v[i].fi], f[v[i].se]);
                int nRes = query(f);
                RE(i,mid) swap(f[v[i].fi], f[v[i].se]);
                if(nRes == n) return;
                if(nRes != res) lb=mid+1;
                else ub=mid;
            while(v.size() > lb) v.pop_back();

    // finding cycles
    vector<vi> adj; adj.resize(n);
    FOR(p,goodSwaps) {
    vi ans; ans.assign(n,0);
    vector<bool> used; used.assign(n,0);
    RE(i,n) {
        if(used[i]) continue;
        vi cycle = {i};
        while(!used[cycle.back()]) {
            int u = cycle.back();
            int nxt = -1;
            FOR(v,adj[u]) if(!used[v]) nxt = v;
            used[u] = 1;
            if(nxt != -1) cycle.pb(nxt);
        if(cycle.size() == 2) {
            ans[cycle[0]] = f[cycle[1]];
            ans[cycle[1]] = f[cycle[0]];
        } else {
            vi perm = f;
            int m = cycle.size();
            RE(i,m) perm[cycle[i]] = f[cycle[(i+1)%m]];
            int nRes = query(perm);
            if(nRes == n) return;
            if(nRes) {
                RE(i,m) ans[cycle[i]] = f[cycle[(i+1)%m]];
            } else {
                RE(i,m) ans[cycle[i]] = f[cycle[(i+m-1)%m]];


#define debug
#ifdef debug
int n, totQueries;
vi ans;

int query(vi q) {
    int res = 0;
    RE(i,n) if(ans[i] == q[i]) res++;
    if(res == n) OUTL("Correct!");
    return res;

int main() {
    IN(n); ans.assign(n,0);
    RE(i,n) IN(ans[i]);
    OUTL("Total queries: ",totQueries);

Compilation message

mouse.cpp: In function 'void solve(int)':
mouse.cpp:99:28: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   99 |             while(v.size() > lb) v.pop_back();
      |                   ~~~~~~~~~^~~~
/tmp/cc97Y7Xs.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccLdrbAU.o:mouse.cpp:(.text.startup+0x0): first defined here
/tmp/cc97Y7Xs.o: In function `query(std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x0): multiple definition of `query(std::vector<int, std::allocator<int> >)'
/tmp/ccLdrbAU.o:mouse.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status