답안 #231084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231084 2020-05-12T16:02:58 Z nicolaalexandra CEOI16_icc (CEOI16_icc) C++14
90 / 100
163 ms 640 KB
/// sincer nu inteleg dc sunt asa proasta
#include <bits/stdc++.h>
#include "icc.h"
#define DIM 200
using namespace std;

int n;
int v[DIM],t[DIM],aux[DIM],a[DIM],b[DIM];

/*int query (int n, int m, int a[], int b[]){
    int ans;
    cout<<n<<" ";
    for (int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
    cout<<m<<" ";
    for (int i=0;i<m;i++)
        cout<<b[i]<<" ";
    cout<<endl;
    cin>>ans;
    return ans;
}
void setRoad (int x, int y){
    cout<<x<<" "<<y<<endl;
}*/

int get_rad (int x){
    while (t[x] > 0)
        x = t[x];
    return x;
}
void _union (int x, int y){
    int radx = get_rad (x), rady = get_rad (y);

    if (t[radx] < t[rady]){
        t[radx] += t[rady];
        t[rady] = radx;
    } else {
        t[rady] += t[radx];
        t[radx] = rady;
    }

}

void run (int n){
    int k,k2,el,i,x,y;
    for (i=1;i<=n;i++)
        t[i] = -1;
    for (int pas=1;pas<n;pas++){
        /// impart componentele conexe in doua multimi

        for (int bit=0;bit<9;bit++){
            k = 0, k2 = 0;

            for (i=1;i<=n;i++){
                int val = get_rad(i);
                if (val&(1<<bit))
                    a[k++] = i;
                else b[k2++] = i;
            }

            if (!k || !k2)
                continue;

            if (query(k,k2,a,b)){ /// am gasit cele doua multimi

                while (k > 1){
                    int mid = k/2;

                    if (query(mid,k2,a,b))
                        k = mid;
                    else {
                        for (int i=mid;i<k;i++)
                            a[i-mid] = a[i];
                        k -= mid;
                    }
                }
                x = a[0];


                while (k2 > 1){
                    int mid = k2/2;

                    if (query(k,mid,a,b))
                        k2 = mid;
                    else {
                        for (int i=mid;i<k2;i++)
                            b[i-mid] = b[i];
                        k2 -= mid;
                    }
                }
                y = b[0];

                setRoad(x,y);

                _union (x,y);

                break;
            }
        }
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:46:14: warning: unused variable 'el' [-Wunused-variable]
     int k,k2,el,i,x,y;
              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 512 KB Ok! 101 queries used.
2 Correct 11 ms 512 KB Ok! 105 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 512 KB Ok! 544 queries used.
2 Correct 55 ms 512 KB Ok! 692 queries used.
3 Correct 51 ms 512 KB Ok! 678 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 640 KB Ok! 1365 queries used.
2 Correct 160 ms 512 KB Ok! 1664 queries used.
3 Correct 130 ms 512 KB Ok! 1363 queries used.
4 Correct 142 ms 512 KB Ok! 1509 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 600 KB Ok! 1442 queries used.
2 Correct 139 ms 512 KB Ok! 1491 queries used.
3 Correct 163 ms 636 KB Ok! 1665 queries used.
4 Correct 126 ms 512 KB Ok! 1345 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 512 KB Ok! 1647 queries used.
2 Correct 154 ms 512 KB Ok! 1654 queries used.
3 Correct 151 ms 640 KB Ok! 1652 queries used.
4 Correct 149 ms 632 KB Ok! 1578 queries used.
5 Correct 131 ms 512 KB Ok! 1427 queries used.
6 Correct 148 ms 568 KB Ok! 1591 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 156 ms 512 KB Too many queries! 1650 out of 1625
2 Halted 0 ms 0 KB -