Submission #731575

# Submission time Handle Problem Language Result Execution time Memory
731575 2023-04-27T14:49:54 Z abcvuitunggio ICC (CEOI16_icc) C++17
90 / 100
139 ms 632 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 (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]);
            break;
        }
    }
}
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++){
      |                      ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 108 queries used.
2 Correct 5 ms 432 KB Ok! 107 queries used.
# Verdict Execution time Memory Grader output
1 Correct 27 ms 468 KB Ok! 534 queries used.
2 Correct 43 ms 468 KB Ok! 689 queries used.
3 Correct 37 ms 484 KB Ok! 682 queries used.
# Verdict Execution time Memory Grader output
1 Correct 104 ms 632 KB Ok! 1408 queries used.
2 Correct 123 ms 492 KB Ok! 1682 queries used.
3 Correct 101 ms 488 KB Ok! 1476 queries used.
4 Correct 111 ms 488 KB Ok! 1491 queries used.
# Verdict Execution time Memory Grader output
1 Correct 111 ms 532 KB Ok! 1517 queries used.
2 Correct 121 ms 496 KB Ok! 1486 queries used.
3 Correct 131 ms 492 KB Ok! 1660 queries used.
4 Correct 111 ms 468 KB Ok! 1394 queries used.
# Verdict Execution time Memory Grader output
1 Correct 122 ms 484 KB Ok! 1637 queries used.
2 Correct 122 ms 488 KB Ok! 1666 queries used.
3 Correct 137 ms 492 KB Ok! 1677 queries used.
4 Correct 125 ms 488 KB Ok! 1614 queries used.
5 Correct 121 ms 488 KB Ok! 1467 queries used.
6 Correct 113 ms 488 KB Ok! 1581 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 488 KB Too many queries! 1655 out of 1625
2 Halted 0 ms 0 KB -