Submission #1246322

#TimeUsernameProblemLanguageResultExecution timeMemory
1246322KALARRYHack (APIO25_hack)C++20
0 / 100
7 ms1848 KiB
//chockolateman
#include<bits/stdc++.h>
#include <vector>
#include "hack.h"

using namespace std;

const int S = 31623;

int counter = 0;

vector<int> nums;
vector<long long> temp;

long long query_pair(int x)
{
    temp.clear();
    temp.push_back(1);
    temp.push_back(1+x);
    counter += 2;
    return collisions(temp);
}

int hack(){
    counter = 0;
    temp.clear();
    if(nums.empty())
    {
        nums.push_back(0); //make it 1-indexed
        for(int i = 1 ; i < S ; i++)
            nums.push_back(nums.back() + 1);
        for(int i = 1 ; i <= S ; i++)
            nums.push_back(nums.back() + S);
    }
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    shuffle(nums.begin()+1, nums.end(), rng);
    vector<long long> x;
    vector<long long> xf,xs,xf1,xf2,xs1,xs2,y;
    for(auto k : nums)
        if(k != 0)
            x.push_back(k);
    while ((int)x.size() > 2) {
        int m = (int)x.size();
        xf.clear();
        xs.clear();
        for (int i=0; i < m/2; ++i) xf.push_back(x[i]);
        for (int i=m/2; i < m; ++i) xs.push_back(x[i]);

        if (collisions(xf) != 0) {
            x = xf;
            continue;
        }

        if (collisions(xs) != 0) {
            x = xs;
            continue;
        }

        xf1.clear();
        xf2.clear();
        m = (int)xf.size();
        for (int i=0; i < m/2; ++i) xf1.push_back(xf[i]);
        for (int i=m/2; i < m; ++i) xf2.push_back(xf[i]);
        
        xs1.clear();
        xs2.clear();
        m = (int)xs.size();
        for (int i=0; i < m/2; ++i) xs1.push_back(xs[i]);
        for (int i=m/2; i < m; ++i) xs2.push_back(xs[i]);

        y.clear();
        for (auto el : xf1) y.push_back(el);
        for (auto el : xs1) y.push_back(el);
        if (collisions(y) != 0) {
            x = y;
            continue;
        }

        y.clear();
        for (auto el : xf2) y.push_back(el);
        for (auto el : xs1) y.push_back(el);
        if (collisions(y) != 0) {
            x = y;
            continue;
        }

        y.clear();
        for (auto el : xf1) y.push_back(el);
        for (auto el : xs2) y.push_back(el);
        if (collisions(y) != 0) {
            x = y;
            continue;
        }

        y.clear();
        for (auto el : xf2) y.push_back(el);
        for (auto el : xs2) y.push_back(el);
            x = y;
    }
    long long diff = x[1]-x[0];
    vector<long long> di;
        for (long long d=2LL; d*d <= diff; ++d) {
        if (diff % d == 0LL) {
            di.push_back(d);
            di.push_back(diff/d);
        }
    }
    di.push_back(diff);
    sort(di.begin(), di.end());
    int dsz = (int)di.size();

    for (int p=0; p < dsz; ++p) {
        vector<long long> v;
        v.push_back(1LL);
        v.push_back(di[p]+1LL);
        if (collisions(v) == 1) return di[p];
    }
}

Compilation message (stderr)

hack.cpp: In function 'int hack()':
hack.cpp:118:1: warning: control reaches end of non-void function [-Wreturn-type]
  118 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...