#P7384. 「EZEC-6」分组
「EZEC-6」分组
Description
You are given numbers. Split them into any number of groups (they do not need to be contiguous). For each group, take the bitwise OR of the numbers in that group, and then sum the results of all groups. Under the condition that this total sum is minimized, find the maximum possible number of groups.
Input Format
The first line contains a positive integer .
The second line contains non-negative integers .
Output Format
Output one positive integer: the maximum number of groups in an optimal solution.
6
1 1 4 5 1 4
1
7
1 9 1 9 8 1 0
2
8
1 9 2 6 0 8 1 7
2
9
3 1 4 1 5 9 2 6 5
1
9
9 9 8 2 4 4 3 5 3
1
6
1 2 3 4 8 12
2
Hint
Below is one possible construction for each sample.
For sample , is also a solution that minimizes the answer, but produces more groups.
This problem uses bundled test scoring.
- Subtask : , points.
- Subtask : , points.
- Subtask : , points.
- Subtask : , and the testdata is guaranteed to be random, points.
- Subtask : , points.
- Subtask : , points.
Constraints: for all testdata, , .
If you do not know what bitwise OR is, please click here.
This problem enables O2 optimization by default.
This problem provides an input optimization method.
Using read(x); to read any integer x is equivalent to scanf("%d", &x);, where %d can be automatically recognized as the corresponding type.
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
r=0;bool w=0; char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
r=w?-r:r;
}
Translated by ChatGPT 5
京公网安备 11011102002149号