Submission #493849

# Submission time Handle Problem Language Result Execution time Memory
493849 2021-12-13T07:34:39 Z balbit Mouse (info1cup19_mouse) C++14
100 / 100
81 ms 456 KB
#include "grader.h"
#include <bits/stdc++.h>
//#define int ll
using namespace std;
#define ll long long
#define y1 zck_is_king
#define pii pair<ll, ll>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 300;

int targ[6] = {1,6,2,3,5,4};

int GET(vector<int> q) {
    for( int &x : q) ++x;
#ifndef BALBIT
    int ar = query(q);
#else
    int ar = 0;
    REP(i, SZ(q)) ar += q[i] == targ[i];
#endif
    if (ar == SZ(q)) {
        exit(0);
    }
    return ar;
}

bool yes[maxn][maxn];
vector<pii> pairs; // pairs of points that point to each other, a<b

void gogo(vector<int> pp, vector<pii> &ty, int l, int r, int num) { // is there a difference <= position k
    if (num == 0) return;
    if (l == r) {
    bug(l,r,num);
        assert(num <= 2);

        pairs.pb(ty[l]);
        return;
    }
    int mid = (l+r)/2;
    vector<int> tmp = pp;
    for (int j = l; j<=mid; ++j) {
        swap(tmp[ty[j].f], tmp[ty[j].s]);
    }
    int nleft = GET(tmp);
    gogo(pp, ty, l, mid, nleft);
    gogo(pp, ty, mid+1,r,num-nleft);
}

void work(vector<int> org, vector<pii> tries) {
    if (SZ(tries) == 0) return;
    vector<int> tmp = org;
    for (pii p : tries) {
        swap(tmp[p.f], tmp[p.s]);
    }
    gogo(org, tries, 0, SZ(tries)-1, GET(tmp));
}

vector<int> g[maxn];
bool done[maxn];

void solve(int n) {
    vector<int> a(n);
    REP(i,n) a[i] = i;
    random_shuffle(ALL(a));
    while (GET(a)) {
        random_shuffle(ALL(a));
    }

    for (int x : a) {
        bug(x+1);
    }

    for (int df = 1; df < n; ++df) REP(parity, 2) {
        vector<pii> papa;
        REP(i,n) {
            if ((i / (df)) % 2 == parity) {
                if (i + df < n) {
                    papa.pb({i, i+df});
                }
            }
        }
//        bug("OIJFEOWIFJ");
//        for (pii p: papa) {
//            bug(p.f, p.s);
//        }
        work(a, papa);
    }

    for (pii p : pairs) {
        bug(p.f, p.s);
        g[p.f].pb(p.s); g[p.s].pb(p.f);
    }

    int num = 0;

    REP(i,n) {
        bug(i, done[i]);
        if (!done[i]) {
            // ok go!
            if (SZ(g[i]) == 1) {
                // two-way
                swap(a[i], a[g[i][0]]);
                bug("doubles", i, g[i][0]);
                done[i] = done[g[i][0]] = 1;
                num += 2;
                bug(i, g[i][0]);

//                #ifdef BALBIT
//                assert(GET(a) == num);
//                #endif // BALBIT

            }else{
                bug(i, "complex");
                vector<int> tmp = a;
                int cnt = 1;
                int at = g[i][0];
                int prv = i;
                done[i] = 1;
                int yat = -1;
                for (; at != i; yat = at, at = g[at][0] ^ g[at][1] ^ prv, prv = yat) {
                    bug(prv, at);
                    swap(tmp[at], tmp[prv]);
                    ++cnt;
                    done[at] = 1; // UPDATE PRV
                }
                bug(cnt);
//                swap(tmp[at], tmp[prv]);
                REP(i, n) {
                    bug(i, tmp[i]+1);
                }

                int yo = GET(tmp);
                if (yo == num + cnt) {
                    // worked!
                    bug("worked!");
                    a = tmp;
                }else{
                    int at = g[i][1];
                    int prv = i;
                    int yat = -1;
                    for (; at != i; yat = at, at = g[at][0] ^ g[at][1] ^ prv, prv = yat) {
                        swap(a[at], a[prv]);
                        bug(at, prv);
                    }
//                    swap(a[at], a[prv]);
                }

//                #ifdef BALBIT
//                assert(GET(a) == num+cnt);
//                #endif // BALBIT

                num += cnt;

            }
        }
    }
    GET(a);
    assert(0);
}
//
//signed main(){
//    IOS();
//    solve(6);
//
//
//}

Compilation message

mouse.cpp: In function 'void solve(int)':
mouse.cpp:114:14: warning: unused variable 'x' [-Wunused-variable]
  114 |     for (int x : a) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Correct! Number of queries: 19
2 Correct 1 ms 200 KB Correct! Number of queries: 5
3 Correct 1 ms 200 KB Correct! Number of queries: 15
4 Correct 1 ms 200 KB Correct! Number of queries: 19
5 Correct 1 ms 200 KB Correct! Number of queries: 22
6 Correct 1 ms 200 KB Correct! Number of queries: 26
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Correct! Number of queries: 19
2 Correct 1 ms 200 KB Correct! Number of queries: 5
3 Correct 1 ms 200 KB Correct! Number of queries: 15
4 Correct 1 ms 200 KB Correct! Number of queries: 19
5 Correct 1 ms 200 KB Correct! Number of queries: 22
6 Correct 1 ms 200 KB Correct! Number of queries: 26
7 Correct 7 ms 312 KB Correct! Number of queries: 300
8 Correct 7 ms 200 KB Correct! Number of queries: 300
9 Correct 3 ms 304 KB Correct! Number of queries: 300
10 Correct 6 ms 312 KB Correct! Number of queries: 300
11 Correct 5 ms 308 KB Correct! Number of queries: 300
12 Correct 5 ms 200 KB Correct! Number of queries: 300
13 Correct 4 ms 200 KB Correct! Number of queries: 300
14 Correct 5 ms 200 KB Correct! Number of queries: 300
15 Correct 4 ms 300 KB Correct! Number of queries: 300
16 Correct 5 ms 200 KB Correct! Number of queries: 300
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Correct! Number of queries: 19
2 Correct 1 ms 200 KB Correct! Number of queries: 5
3 Correct 1 ms 200 KB Correct! Number of queries: 15
4 Correct 1 ms 200 KB Correct! Number of queries: 19
5 Correct 1 ms 200 KB Correct! Number of queries: 22
6 Correct 1 ms 200 KB Correct! Number of queries: 26
7 Correct 7 ms 312 KB Correct! Number of queries: 300
8 Correct 7 ms 200 KB Correct! Number of queries: 300
9 Correct 3 ms 304 KB Correct! Number of queries: 300
10 Correct 6 ms 312 KB Correct! Number of queries: 300
11 Correct 5 ms 308 KB Correct! Number of queries: 300
12 Correct 5 ms 200 KB Correct! Number of queries: 300
13 Correct 4 ms 200 KB Correct! Number of queries: 300
14 Correct 5 ms 200 KB Correct! Number of queries: 300
15 Correct 4 ms 300 KB Correct! Number of queries: 300
16 Correct 5 ms 200 KB Correct! Number of queries: 300
17 Correct 78 ms 456 KB Correct! Number of queries: 1900
18 Correct 65 ms 444 KB Correct! Number of queries: 1900
19 Correct 63 ms 328 KB Correct! Number of queries: 1900
20 Correct 79 ms 328 KB Correct! Number of queries: 2000
21 Correct 67 ms 340 KB Correct! Number of queries: 1900
22 Correct 47 ms 328 KB Correct! Number of queries: 1900
23 Correct 62 ms 328 KB Correct! Number of queries: 1900
24 Correct 71 ms 344 KB Correct! Number of queries: 2000
25 Correct 81 ms 332 KB Correct! Number of queries: 2000
26 Correct 59 ms 332 KB Correct! Number of queries: 2000