Submission #731577

# Submission time Handle Problem Language Result Execution time Memory
731577 2023-04-27T14:52:38 Z abcvuitunggio ICC (CEOI16_icc) C++17
100 / 100
124 ms 604 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
int p[101];
vector <int> ve[101],root;
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int i, int j){
    i=f(i);
    j=f(j);
    if (i>j)
        swap(i,j);
    p[j]=i;
    for (int k:ve[j])
        ve[i].push_back(k);
    ve[j].clear();
}
int ask(int x, int y, int a[], int b[]){
    int A[x],B[y];
    for (int i=0;i<x;i++)
        A[i]=a[i];
    for (int j=0;j<y;j++)
        B[j]=b[j];
    return query(x,y,A,B);
}
int n;
void findroad(){
    root.clear();
    for (int i=1;i<=n;i++)
        if (f(i)==i)
            root.push_back(i);
    for (int i=0;(1<<i)<root.size();i++){
        int sa=0,sb=0;
        for (int j=0;j<root.size();j++)
            if ((j>>i)&1)
                sb+=ve[root[j]].size();
            else
                sa+=ve[root[j]].size();
        int a[sa],b[sb],x=0,y=0;
        for (int j=0;j<root.size();j++){
            if ((j>>i)&1)
                for (int u:ve[root[j]]){
                    b[y]=u;
                    y++;
                }
            else
                for (int u:ve[root[j]]){
                    a[x]=u;
                    x++;
                }
        }
        if ((1<<(i+1))>root.size()||query(sa,sb,a,b)){
            int l=1,r=sa,kq=-1,kq2=-1;
            while (l<=r){
                int mid=(l+r)>>1;
                if (ask(mid,sb,a,b)){
                    kq=mid;
                    r=mid-1;
                }
                else
                    l=mid+1;
            }
            l=1,r=sb;
            while (l<=r){
                int mid=(l+r)>>1;
                if (ask(sa,mid,a,b)){
                    kq2=mid;
                    r=mid-1;
                }
                else
                    l=mid+1;
            }
            setRoad(a[kq-1],b[kq2-1]);
            unite(a[kq-1],b[kq2-1]);
            return;
        }
    }
}
void run(int N){
    n=N;
    for (int i=1;i<=n;i++){
        p[i]=i;
        ve[i].push_back(i);
    }
    for (int i=1;i<n;i++)
        findroad();
}

Compilation message

icc.cpp: In function 'void findroad()':
icc.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0;(1<<i)<root.size();i++){
      |                  ~~~~~~^~~~~~~~~~~~
icc.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j=0;j<root.size();j++)
      |                      ~^~~~~~~~~~~~
icc.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int j=0;j<root.size();j++){
      |                      ~^~~~~~~~~~~~
icc.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if ((1<<(i+1))>root.size()||query(sa,sb,a,b)){
      |             ~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 108 queries used.
2 Correct 5 ms 468 KB Ok! 103 queries used.
# Verdict Execution time Memory Grader output
1 Correct 30 ms 500 KB Ok! 534 queries used.
2 Correct 46 ms 468 KB Ok! 659 queries used.
3 Correct 46 ms 480 KB Ok! 661 queries used.
# Verdict Execution time Memory Grader output
1 Correct 102 ms 496 KB Ok! 1407 queries used.
2 Correct 117 ms 480 KB Ok! 1590 queries used.
3 Correct 102 ms 480 KB Ok! 1455 queries used.
4 Correct 109 ms 468 KB Ok! 1490 queries used.
# Verdict Execution time Memory Grader output
1 Correct 101 ms 468 KB Ok! 1418 queries used.
2 Correct 110 ms 484 KB Ok! 1476 queries used.
3 Correct 120 ms 488 KB Ok! 1628 queries used.
4 Correct 98 ms 596 KB Ok! 1381 queries used.
# Verdict Execution time Memory Grader output
1 Correct 117 ms 484 KB Ok! 1602 queries used.
2 Correct 124 ms 468 KB Ok! 1634 queries used.
3 Correct 122 ms 468 KB Ok! 1632 queries used.
4 Correct 116 ms 604 KB Ok! 1605 queries used.
5 Correct 103 ms 480 KB Ok! 1466 queries used.
6 Correct 116 ms 588 KB Ok! 1578 queries used.
# Verdict Execution time Memory Grader output
1 Correct 122 ms 488 KB Ok! 1625 queries used.
2 Correct 116 ms 484 KB Ok! 1607 queries used.