Submission #973201

# Submission time Handle Problem Language Result Execution time Memory
973201 2024-05-01T15:59:43 Z HoriaHaivas ICC (CEOI16_icc) C++14
0 / 100
1 ms 856 KB
/*
    "care a facut teste cu Lattice reduction attack e ciudat"
    "linistiti va putin"
    - 2023 -
*/
#include<bits/stdc++.h>
#include "icc.h"
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")

using namespace std;

int n;
int root[101];
int sz[101];
int comp[101][101];
bool connected[101][101];
int aquery[101];
int aqsz;
int bquery[101];
int bqsz;
int c[101];
int d[101];
bool seen[101];

void unite(int a, int b)
{
    a=root[a];
    b=root[b];
    if(sz[a]<sz[b])
    {
        swap(a,b);
    }
    int i;
    for (i=1; i<=sz[b]; i++)
    {
        sz[a]++;
        comp[a][sz[a]]=comp[b][i];
        root[comp[b][i]]=a;
    }
}

/*
int query(int sza, int szb, int a[], int b[])
{
    int i,j;
    for (i=1; i<=sza; i++)
    {
        for (j=1; j<=szb; j++)
        {
            if (connected[a[i]][b[j]])
            {
                return 1;
            }
        }
    }
    return 0;
}
*/

void add(int type, int &sza, int b[], int szb)
{
    if (type==1)
    {
        int i;
        for (i=1; i<=szb; i++)
        {
            sza++;
            c[sza]=b[i];
        }
    }
    else if (type==2)
    {
        int i;
        for (i=1; i<=szb; i++)
        {
            sza++;
            aquery[sza]=b[i];
        }
    }
    else if (type==3)
    {
        int i;
        for (i=1; i<=szb; i++)
        {
            sza++;
            bquery[sza]=b[i];
        }
    }
}

bool compara(int j)
{
    int i;
    for (i=1; i<=n; i++)
    {
        seen[i]=0;
    }
    int x;
    for (i=1; i<=n; i++)
    {
        x=root[i];
        if (!seen[x])
        {
            if (x&(1<<j))
                add(2,aqsz,comp[x],sz[x]);
            else
                add(3,bqsz,comp[x],sz[x]);
            seen[x]=1;
        }
    }
    /*
    //debugs(j);
    //debugs(aqsz);
    //debug(bqsz);
    for (i=1;i<=aqsz;i++)
    {
         //debug(aquery[i]);
    }
    for (i=1;i<=bqsz;i++)
    {
         //debug(bquery[i]);
    }
    */
    return query(aqsz,bqsz,aquery,bquery);
}

pair<int,int> find_road()
{
    int i,j;
    for (i=0; i<7 && (1<<i)<=n; i++)
    {
        aqsz=0;
        bqsz=0;
        //debugs(i);
        //debug(compara(i));
        if (compara(i)==1)
        {
            break;
        }
    }
    int r,pas,apoz,bpoz,csize;
    r=0;
    pas=(1<<7);
    while (pas)
    {
        if (r+pas<=aqsz)
        {
            csize=0;
            add(1,csize,aquery,r+pas);
            if (!query(r+pas,bqsz,c,bquery))
                r+=pas;
        }
        pas=pas/2;
    }
    r++;
    apoz=aquery[r];
    r=0;
    pas=(1<<7);
    d[0]=0;
    d[1]=apoz;
    while (pas)
    {
        if (r+pas<=bqsz)
        {
            csize=0;
            add(1,csize,bquery,r+pas);
            if (!query(r+pas,1,c,d))
                r+=pas;
        }
        pas=pas/2;
    }
    r++;
    bpoz=bquery[r];
    return {apoz,bpoz};
}

/*
void build_road()
{
    int a,b;
    cin >> a >> b;
    connected[a][b]=1;
    connected[b][a]=1;
}

void setroad(int a, int b)
{
    cout << "am gasit lol : ";
    cout << a << " " << b << "\n";
    unite(a,b);
}
*/

void run(int _n)
{
    n=_n;
    int pasi,i;
    pair<int,int> ans;
    for (i=1; i<=n; i++)
    {
        root[i]=i;
        comp[i][1]=i;
        sz[i]=1;
    }
    pasi=0;
    while (pasi<n-1)
    {
        //build_road();///asta trebuie comentat
        ans=find_road();
        unite(ans.first,ans.second);
        //setroad(ans.first,ans.second);
        pasi++;
    }
}

Compilation message

icc.cpp: In function 'std::pair<int, int> find_road()':
icc.cpp:131:11: warning: unused variable 'j' [-Wunused-variable]
  131 |     int i,j;
      |           ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 440 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 604 KB Query cities not in range [1, n]
2 Halted 0 ms 0 KB -