ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Global Round 2

2019-04-07 09:51:00  阅读:583  来源: 互联网

标签:11 Alyona nn Ilya Global Codeforces fridge houses Round


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

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有