Submission #493849

#TimeUsernameProblemLanguageResultExecution timeMemory
493849balbitMouse (info1cup19_mouse)C++14
100 / 100
81 ms456 KiB
#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 (stderr)

mouse.cpp: In function 'void solve(int)':
mouse.cpp:114:14: warning: unused variable 'x' [-Wunused-variable]
  114 |     for (int x : a) {
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...