답안 #986099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986099 2024-05-19T17:57:22 Z alexdd CEOI16_icc (CEOI16_icc) C++17
61 / 100
136 ms 644 KB
#include "icc.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(219348);
int n;
vector<int> comps[105];
int unde[105];
vector<int> ord,ord2;
int aska[105],askb[105],sa,sb;
int wirtz(int poz)
{
    sa=sb=0;
    for(int i=0;i<=poz;i++)
        for(auto x:comps[ord[i]])
            aska[sa++]=x;
    for(int i=poz+1;i<ord.size();i++)
        for(auto x:comps[ord[i]])
            askb[sb++]=x;
    return query(sa,sb,aska,askb);
}
int boniface(int c1, int poz1, int c2)
{
    sa=sb=0;
    for(int i=0;i<=poz1;i++)
        aska[sa++]=comps[c1][i];
    for(auto x:comps[c2])
        askb[sb++]=x;
    return query(sa,sb,aska,askb);
}
int frimpong(int le1, int ri1, int le2, int ri2)
{
    sa=sb=0;
    for(int i=le1;i<=ri1;i++)
        aska[sa++]=ord2[i];
    for(int i=le2;i<=ri2;i++)
        askb[sb++]=ord2[i];
    return query(sa,sb,aska,askb);
}
void run(int N)
{
    n=N;
    for(int i=1;i<=n;i++)
    {
        ord.push_back(i);
        comps[i].push_back(i);
        unde[i]=i;
    }
    for(int pas=1;pas<n;pas++)
    {
        do
        {
            shuffle(ord.begin(),ord.end(),rnd);
        }while(!wirtz((int)ord.size()/2-1));
        ord2.clear();
        for(auto c:ord)
        {
            shuffle(comps[c].begin(),comps[c].end(),rnd);
            for(auto x:comps[c])
                ord2.push_back(x);
        }
        int aux=0;
        for(int i=0;i<=(int)ord.size()/2-1;i++)
            aux += (int)comps[ord[i]].size();
        int st,dr,ans;
        st=aux;
        dr=(int)ord2.size()-2;
        ans=(int)ord2.size()-1;
        while(dr-st+1>3)
        {
            int mij=(st+dr)/2;
            if(frimpong(0,aux-1,aux,mij))
            {
                ans=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        for(int i=st;i<=dr;i++)
        {
            if(frimpong(0,aux-1,aux,i))
            {
                ans=i;
                break;
            }
        }
        int vri = ord2[ans];

        st=0;
        dr=aux-2;
        ans=aux-1;
        while(dr-st+1>2)
        {
            int mij=(st+dr)/2;
            if(frimpong(0,mij,aux,(int)ord2.size()-1))
            {
                ans=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        for(int i=st;i<=dr;i++)
        {
            if(frimpong(0,i,aux,(int)ord2.size()-1))
            {
                ans=i;
                break;
            }
        }
        int vle = ord2[ans];

        setRoad(vle,vri);

        int cle=unde[vle],cri=unde[vri];
        for(auto x:comps[cri])
        {
            comps[cle].push_back(x);
            unde[x]=cle;
        }
        comps[cri].clear();
        shuffle(comps[cle].begin(),comps[cle].end(),rnd);
        bool sters=0;
        for(int i=0;i<ord.size();i++)
        {
            if(ord[i]==cri)
            {
                sters=1;
                ord.erase(ord.begin()+i);
                break;
            }
        }
    }
}

Compilation message

icc.cpp: In function 'int wirtz(int)':
icc.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=poz+1;i<ord.size();i++)
      |                     ~^~~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:124:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |         for(int i=0;i<ord.size();i++)
      |                     ~^~~~~~~~~~~
icc.cpp:123:14: warning: variable 'sters' set but not used [-Wunused-but-set-variable]
  123 |         bool sters=0;
      |              ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Ok! 112 queries used.
2 Correct 5 ms 604 KB Ok! 106 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 604 KB Ok! 544 queries used.
2 Correct 41 ms 604 KB Ok! 865 queries used.
3 Correct 39 ms 604 KB Ok! 825 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 600 KB Ok! 1573 queries used.
2 Correct 136 ms 628 KB Ok! 2140 queries used.
3 Correct 108 ms 644 KB Ok! 1708 queries used.
4 Correct 107 ms 620 KB Ok! 1765 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 604 KB Ok! 1640 queries used.
2 Correct 110 ms 616 KB Ok! 1742 queries used.
3 Correct 114 ms 616 KB Ok! 1844 queries used.
4 Correct 97 ms 616 KB Ok! 1593 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 117 ms 632 KB Too many queries! 1919 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 616 KB Too many queries! 1950 out of 1625
2 Halted 0 ms 0 KB -