CCO Preparation Test 6 P2 - An Easy Problem

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 0.6s
Memory limit: 32M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal

Given an array A with N non-negative integers ai (1iN), find the longest subsequence B, where bi&bi1 is not 0.

NOTE: & is the bitwise and operation. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. The two adjacent elements in the subsequence B don't have to be consecutive in the original array A.

Input Specification

The first line consists of one integer N (1N100000).

The second line consists of N non-negative integers, ai (0ai109).

Output Specification

One integer, the longest length of the subsequence B.

Sample Input 1

Copy
4
1 2 3 4

Sample Output 1

Copy
2

Sample Input 2

Copy
8
1 2 1 2 1 2 1 4

Sample Output 2

Copy
4

Comments

There are no comments at the moment.