Submission #39704

# Submission time Handle Problem Language Result Execution time Memory
39704 2018-01-17T13:54:25 Z igzi ICC (CEOI16_icc) C++14
100 / 100
169 ms 2220 KB
#include <bits/stdc++.h>
#define maxN 101
#include "icc.h"

using namespace std;

vector <int> x,a,b,v[maxN];
int N,p[maxN];
/*void setRoad(int x,int y){
    cout<<x<<"    "<<y<<endl;
}
int query(int A,int B,int a[],int b[]){
    for(int i=0;i<A;i++) cout<<a[i]<<" ";
    cout<<endl;
    for(int i=0;i<B;i++) cout<<b[i]<<" ";
    cout<<endl;
    int c;
    cin>>c;
    return c;
}*/

int Query(vector <int> a,vector <int> b) {
  int tmp[2][maxN],i;
  for (i = 0; i < a.size(); ++i){
    tmp[0][i]=a[i];
  }
  for (i = 0; i < b.size(); ++i){
    tmp[1][i]=b[i];}
  query(a.size(),b.size(),tmp[0],tmp[1]);
}
void formiraj(int n,int d){
    a.clear(); b.clear();
    for(int i=0;i<n;i++){
        int r=i/d;
        if(r%2) b.push_back(x[i]);
        else a.push_back(x[i]);
    }
}
pair <int,int> resi(vector <int> &a,vector <int> &b){
    pair <int,int> ans;
    ans=make_pair(-1,-1);
    int i;
    vector <int> s;
    int A,B;
    A=a.size();
    B=b.size();
    int l=0,d=A-1,m;
    while(d>l){
        m=(l+d)/2;
        for(i=l;i<=m;i++){
            s.push_back(a[i]);
        }
        if(Query(b,s)) d=m;
        else l=m+1;
        s.clear();
    }
    ans.first=a[l];
    l=0,d=B-1;
    while(d>l){
        m=(l+d)/2;
        for(i=l;i<=m;i++){
            s.push_back(b[i]);
        }
        if(Query(a,s)) d=m;
        else l=m+1;
        s.clear();
    }
    ans.second=b[l];
    return ans;
}

int stepen(int n){
    int x=1;
    while(2*x<n){
        x*=2;
    }
    return x;
}
void spoj(int x,int y){
    if(y<x) swap(x,y);
    for(int i=0;i<v[y].size();i++){
        v[x].push_back(v[y][i]);
        p[v[y][i]]=x;
    }
    v[y].clear();
}

void run(int n){
    N=n;
    int i,A=0,B=0,s;
    for(i=1;i<=N;i++){
            v[i].push_back(i);
            p[i]=i;
        }
    while(n>1){
        s=stepen(n);
        int d=s,j;
        x.clear();
        for(i=1;i<=N;i++){
            if(!v[i].empty()) x.push_back(i);
        }
        while(d>0){
        formiraj(x.size(),d);
        for (i = 0; i < a.size(); ++i){
    for(j=0;j<v[a[i]].size();j++){
        if(v[a[i]][j]!=a[i]) a.push_back(v[a[i]][j]);
    }
  }
  for (i = 0; i < b.size(); ++i){
    for(j=0;j<v[b[i]].size();j++){
        if(v[b[i]][j]!=b[i]) b.push_back(v[b[i]][j]);
    }
  }
        if(Query(a,b)) break;
        a.clear(); b.clear();
        d=d/2;
        }
        pair <int,int> r;
        r=resi(a,b);
        a.clear(); b.clear();
        setRoad(r.first,r.second);
        spoj(p[r.first],p[r.second]);
        n--;
    }
}

Compilation message

icc.cpp: In function 'int Query(std::vector<int>, std::vector<int>)':
icc.cpp:24:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < a.size(); ++i){
                 ^
icc.cpp:27:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < b.size(); ++i){
                 ^
icc.cpp:30:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
icc.cpp: In function 'void spoj(int, int)':
icc.cpp:81:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[y].size();i++){
                  ^
icc.cpp: In function 'void run(int)':
icc.cpp:104:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < a.size(); ++i){
                       ^
icc.cpp:105:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(j=0;j<v[a[i]].size();j++){
              ^
icc.cpp:109:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < b.size(); ++i){
                 ^
icc.cpp:110:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(j=0;j<v[b[i]].size();j++){
              ^
icc.cpp:90:11: warning: unused variable 'A' [-Wunused-variable]
     int i,A=0,B=0,s;
           ^
icc.cpp:90:15: warning: unused variable 'B' [-Wunused-variable]
     int i,A=0,B=0,s;
               ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2088 KB Ok! 108 queries used.
2 Correct 6 ms 2084 KB Ok! 102 queries used.
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2088 KB Ok! 543 queries used.
2 Correct 43 ms 2084 KB Ok! 643 queries used.
3 Correct 46 ms 2212 KB Ok! 633 queries used.
# Verdict Execution time Memory Grader output
1 Correct 119 ms 2220 KB Ok! 1455 queries used.
2 Correct 133 ms 2212 KB Ok! 1599 queries used.
3 Correct 149 ms 2220 KB Ok! 1581 queries used.
4 Correct 146 ms 2220 KB Ok! 1527 queries used.
# Verdict Execution time Memory Grader output
1 Correct 146 ms 2212 KB Ok! 1555 queries used.
2 Correct 143 ms 2216 KB Ok! 1549 queries used.
3 Correct 169 ms 2216 KB Ok! 1525 queries used.
4 Correct 129 ms 2216 KB Ok! 1517 queries used.
# Verdict Execution time Memory Grader output
1 Correct 126 ms 2220 KB Ok! 1506 queries used.
2 Correct 143 ms 2216 KB Ok! 1521 queries used.
3 Correct 153 ms 2216 KB Ok! 1598 queries used.
4 Correct 136 ms 2216 KB Ok! 1537 queries used.
5 Correct 123 ms 2216 KB Ok! 1514 queries used.
6 Correct 126 ms 2216 KB Ok! 1547 queries used.
# Verdict Execution time Memory Grader output
1 Correct 129 ms 2220 KB Ok! 1574 queries used.
2 Correct 133 ms 2220 KB Ok! 1501 queries used.