# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871564 |
2023-11-11T05:55:07 Z |
Muhammad_Aneeq |
ICC (CEOI16_icc) |
C++17 |
|
260 ms |
1312 KB |
#include <vector>
#include <set>
#include "icc.h"
using namespace std;
vector<int>g;
int const N=110;
vector<int>chi[N]={};int par[N]={};
bool w=0;
bool q(vector<int>x,vector<int>y)
{
vector<int>a,b;
for (auto i:x)
for (auto j:chi[i])
a.push_back(j);
for (auto i:y)
for (auto j:chi[i])
b.push_back(j);
int* c=new int[a.size()];int *d=new int[b.size()];
for (int i=0;i<a.size();i++)
c[i]=a[i];
for (int i=0;i<b.size();i++)
d[i]=b[i];
int z=query(a.size(),b.size(),c,d);
return z;
}
bool q1(vector<int>a,vector<int>b)
{
int* c=new int[a.size()];int *d=new int[b.size()];
for (int i=0;i<a.size();i++)
c[i]=a[i];
for (int i=0;i<b.size();i++)
d[i]=b[i];
int z=query(a.size(),b.size(),c,d);
return z;
}
bool check(int l,int r)
{
// cout<<l<<' '<<r<<endl;
int mid=(l+r)/2;
vector<int>a,b;
for (int i=l;i<=mid;i++)
a.push_back(g[i]);
for (int i=mid+1;i<=r;i++)
b.push_back(g[i]);
return q(a,b);
}
int root(int x)
{
if (x==par[x])
return x;
return (par[x]=root(par[x]));
}
void merge1(int x,int y)
{
x=root(x);
y=root(y);
for (auto i:chi[y])
chi[x].push_back(i);
chi[y]={};
par[y]=x;
}
void cq1(int r,int l)
{
set<int>a,b;
for (auto i:chi[r])
a.insert(i);
for (auto i:chi[l])
b.insert(i);
int x=*(begin(a));
while (a.size())
{
x=*begin(a);
a.erase(x);
if (q1({begin(a),end(a)},{begin(b),end(b)})==0)
break;
}
int y=*begin(b);
while (b.size())
{
y=*begin(b);
b.erase(y);
if (q1({x},{begin(b),end(b)})==0)
break;
}
setRoad(x,y);
}
void cq(int l,int r)
{
int mid=(l+r)/2;
set<int>a,b;
for (int i=l;i<=mid;i++)
a.insert(g[i]);
for (int i=mid+1;i<=r;i++)
b.insert(g[i]);
int x=*(begin(a));
while (a.size())
{
x=*begin(a);
a.erase(x);
if (q({begin(a),end(a)},{begin(b),end(b)})==0)
break;
}
int y=*begin(b);
while (b.size())
{
y=*begin(b);
b.erase(y);
if (q({x},{begin(b),end(b)})==0)
break;
}
cq1(x,y);
merge1(x,y);
vector<int>temp;
for (auto i:g)
{
if (i==y)
continue;
temp.push_back(i);
}
g=temp;
}
void DnC(int l,int r)
{
if (r-l+1==1)
return;
int mid=(l+r)/2;
DnC(l,mid);
DnC(mid+1,r);
if (!w)
{
if (check(l,r))
{
w=1;
cq(l,r);
}
}
}
void run(int n)
{
for (int i=1;i<=n;i++)
{
par[i]=i;
g.push_back(i);
chi[i].push_back(i);
}
for (int i=0;i<n-1;i++)
{
w=0;
DnC(0,g.size()-1);
}
}
Compilation message
icc.cpp: In function 'bool q(std::vector<int>, std::vector<int>)':
icc.cpp:19:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i=0;i<a.size();i++)
| ~^~~~~~~~~
icc.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i=0;i<b.size();i++)
| ~^~~~~~~~~
icc.cpp: In function 'bool q1(std::vector<int>, std::vector<int>)':
icc.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=0;i<a.size();i++)
| ~^~~~~~~~~
icc.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i=0;i<b.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
608 KB |
Ok! 301 queries used. |
2 |
Correct |
10 ms |
604 KB |
Ok! 305 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
129 ms |
968 KB |
Too many queries! 3419 out of 2500 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
220 ms |
1272 KB |
Number of queries more than 4500 out of 2250 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
260 ms |
1312 KB |
Number of queries more than 4000 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
1144 KB |
Number of queries more than 3550 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
161 ms |
892 KB |
Number of queries more than 3250 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |