其他分享
首页 > 其他分享> > Codeforces Global Round 2

Codeforces Global Round 2

作者:互联网

本来想一场上紫;真没想到结果集体凉凉

A. Ilya and a Colorful Walk

Ilya lives in a beautiful city of Chordalsk.

There are nn houses on the street Ilya lives, they are numerated from 11 to nn from left to right; the distance between every two neighboring houses is equal to 11 unit. The neighboring houses are 11 and 22, 22 and 33, ..., n−1n−1 and nn. The houses nn and 11 are not neighboring.

The houses are colored in colors c1,c2,…,cnc1,c2,…,cn so that the ii-th house is colored in the color cici. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.

Ilya wants to select two houses ii and jj so that 1≤i<j≤n1≤i<j≤n, and they have different colors: ci≠cjci≠cj. He will then walk from the house iito the house jj the distance of (j−i)(j−i) units.

Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.

Help Ilya, find this maximum possible distance.

Input

The first line contains a single integer nn (3≤n≤3000003≤n≤300000) — the number of cities on the street.

The second line contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤n1≤ci≤n) — the colors of the houses.

It is guaranteed that there is at least one pair of indices ii and jj so that 1≤i<j≤n1≤i<j≤n and ci≠cjci≠cj.

Output

Print a single integer — the maximum possible distance Ilya can walk.


题目大意

找出最大的j-i满足a_j≠a_i,(i<j)。

题目分析

对于a_i≠a_n,就是n-i;对于a_i=a_n,先找出最大的a_pos≠a_n,贡献就是pos-i。

 1 #include<bits/stdc++.h>
 2 const int maxn = 300035;
 3 
 4 int a[maxn],lst[maxn],ans,n,pos;
 5 
 6 int read()
 7 {
 8     char ch = getchar();
 9     int num = 0, fl = 1;
10     for (; !isdigit(ch); ch = getchar())
11         if (ch=='-') fl = -1;
12     for (; isdigit(ch); ch = getchar())
13         num = (num<<1)+(num<<3)+ch-48;
14     return num*fl;
15 }
16 int main()
17 {
18     n = read();
19     for (int i=1; i<=n; i++) a[i] = read(), lst[i] = -1;
20     for (int i=1; i<n; i++)
21         if (a[i]!=a[n]) ans = std::max(ans, n-i), pos = i;
22     for (int i=1; i<pos; i++)
23         if (a[i]==a[n]) ans = std::max(ans, pos-i);
24     printf("%d\n",ans);
25     return 0;
26 } 

 

B. Alyona and a Narrow Fridge

Alyona has recently bought a miniature fridge that can be represented as a matrix with hh rows and 22 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part.

An example of a fridge with h=7h=7 and two shelves. The shelves are shown in black. The picture corresponds to the first example.

Alyona has nn bottles of milk that she wants to put in the fridge. The ii-th bottle is aiai cells tall and 11 cell wide. She can put a bottle on some shelf if the corresponding space above the shelf is at least as tall as the bottle. She can not put a bottle on top of another bottle (if there is no shelf between them). Two bottles can not share a cell.

Alyona is interested in the largest integer kk such that she can put bottles 11, 22, ..., kk in the fridge at the same time. Find this largest kk.

Input

The first line contains two integers nn and hh (1≤n≤1031≤n≤103, 1≤h≤1091≤h≤109) — the number of bottles and the height of the fridge.

The second line contains nn integers a1a1, a2a2, ..., anan (1≤ai≤h1≤ai≤h) — the heights of the bottles.

Output

Print the single integer kk — the maximum integer such that Alyona can put the bottles 11, 22, ..., kk in the fridge at the same time. If Alyona can put all bottles in the fridge, print nn. It is easy to see that Alyona can always put at least one bottle in the fridge.


题目大意

有一个hx2的冰箱,

题目分析

postscript

标签:11,Alyona,nn,Ilya,Global,Codeforces,fridge,houses,Round
来源: https://www.cnblogs.com/antiquality/p/10664119.html