Submission #930742

# Submission time Handle Problem Language Result Execution time Memory
930742 2024-02-20T11:05:37 Z socpite Mouse (info1cup19_mouse) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include"grader.h"
using namespace std;

const int maxn = 260;
int MAGIC = 12;

mt19937 rng(69420);

int n = 260;

vector<int> crr;

int cnt[maxn][maxn];
int pp[maxn][maxn];
int dead[maxn][maxn];
vector<int> possible[maxn];

vector<vector<int>> amon;
vector<int> perm;
int id[maxn];

bool cmp(int a, int b){
    return possible[a].size() < possible[b].size();
}

void backtrack(int x) {
    if(pos == n+1){
        amon.push_back(crr);
        return;
    }
    int pos = id[x];
    for(int i: possible[pos]){
        if(crr[i]){
            continue;
        }
        bool chk = 1;
        for(int j = 0; j < MAGIC; j++){
            int tmp = pp[j][pos] - i;
            if(tmp < 0)tmp += n;
            if(!cnt[j][tmp]){
                
                chk = 0;
                break;
            } 
        }
        if(!chk)continue;
        for(int j = 0; j < MAGIC; j++){
            int tmp = pp[j][pos] - i;
            if(tmp < 0)tmp += n;
            cnt[j][tmp]--;
        }
        crr[i] = pos;
        backtrack(x+1);
        crr[i] = 0;
        for(int j = 0; j < MAGIC; j++){
            int tmp = pp[j][pos] - i;
            if(tmp < 0)tmp += n;
            cnt[j][tmp]++;
        }
    }
}

// int query(vector<int> Q){
//     int cnt = 0;
//     for(int i = 0; i < n; i++){
//         if(Q[i] == perm[i])cnt++;
//     }
//     // cout << cnt << endl;
//     return cnt;
// }

void solve(int N){
    n = N;
    if(n <= 50)MAGIC = 7;
    else MAGIC = 11;
    crr.assign(n, 0);
    for(int i = 1; i <= n; i++)perm.push_back(i);
    shuffle(perm.begin(), perm.end(), rng);
    vector<int> rd = perm;
    for(int i = 0; i < MAGIC; i++){
        shuffle(rd.begin(), rd.end(), rng);
        for(int j = 0; j < n; j++)pp[i][rd[j]] = j;
        for(int j = 0; j < n; j++){
            cnt[i][j] = query(rd);
            if(cnt[i][j] == n)return;
            if(cnt[i][j] == 0){
                for(int k = 0; k < n; k++)dead[rd[j]][j] = 1;
            }
            rd.push_back(rd[0]);
            rd.erase(rd.begin());
        }
    }
    for(int i = 1; i <= n; i++){
        id[i] = i;
        for(int j = 0; j < n; j++)if(!dead[i][j])possible[i].push_back(j);
        // cout << possible[i].size() << endl;
    }
    sort(id+1, id+n+1, cmp);
    // return;
    backtrack(1);
    // cout << amon.size();
    query(amon[0]);
}

Compilation message

mouse.cpp: In function 'void backtrack(int)':
mouse.cpp:28:8: error: 'pos' was not declared in this scope; did you mean 'pow'?
   28 |     if(pos == n+1){
      |        ^~~
      |        pow