codechef AUG17 T1 Chef and Rainbow Array

Chef and Rainbow Array Problem Code: RAINBOWA

Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays.

An array is Rainbow if it has the following structure:

  • First a1 elements equal 1.
  • Next a2 elements equal 2.
  • Next a3 elements equal 3.
  • Next a4 elements equal 4.
  • Next a5 elements equal 5.
  • Next a6 elements equal 6.
  • Next a7 elements equal 7.
  • Next a6 elements equal 6.
  • Next a5 elements equal 5.
  • Next a4 elements equal 4.
  • Next a3 elements equal 3.
  • Next a2 elements equal 2.
  • Next a1 elements equal 1.
  • ai can be any non-zero positive integer.
  • There are no other elements in array.

Help Chef in finding out if the given array is a Rainbow Array or not.

Input

  • The first line of the input contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N, denoting the number of elements in the given array.
  • The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of array.

Output

  • For each test case, output a line containing "yes" or "no" (without quotes) corresponding to the case if the array is rainbow array or not.

Constraints

  • 1 ≤ T ≤ 100
  • 7 ≤ N ≤ 100
  • 1 ≤ Ai ≤ 10

Subtasks

  • Subtask 1 (100 points) : Original constraints

Example

Input
3
19
1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1
14
1 2 3 4 5 6 7 6 5 4 3 2 1 1
13
1 2 3 4 5 6 8 6 5 4 3 2 1

Output
yes
no
no

Explanation

The first example satisfies all the conditions.

The second example has 1 element of value 1 at the beginning and 2 elements of value 1 at the end.

The third one has no elements with value 7 after elements with value 6.

————————————————————————————————————————

cc暂时没给中文翻译 所以只好搬英文辣

不然我简述一下题意吧

就是要判断一个序列是否只出现并且都出现了1-7

还要求是个回文串并且只有一个峰(也就是单峰)

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int read(){
    int ans=0,f=1,c=getchar();
    while(c<‘0‘||c>‘9‘){if(c==‘-‘) f=-1; c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){ans=ans*10+(c-‘0‘); c=getchar();}
    return ans*f;
}
int T,n,s[257],c[257];
int main()
{
    T=read();
    while(T--){
        bool f=false;
        memset(c,0,sizeof(c));
        n=read();
        for(int i=1;i<=n;i++){
            s[i]=read();
            if(s[i]>7||s[i]<1) f=1;
            else c[s[i]]=1;
        }
        for(int i=1;i<=7;i++) if(!c[i]) f=1;
        if(f){printf("no\n"); continue;}
        int cnt=(n+1)/2;
        s[0]=-inf; s[n+1]=-inf;
        for(int i=1,j=n;i<=cnt;i++,j--)
            if(s[i]!=s[j]||s[i]<s[i-1]||s[j]<s[j+1]){
                printf("no\n");
                f=1;
                break;
            }
        if(!f) printf("yes\n");
    }
    return 0;
}

时间: 2024-08-05 23:41:41

codechef AUG17 T1 Chef and Rainbow Array的相关文章

codechef AUG17 T5 Chef And Fibonacci Array

Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ≥ 1, if Ai > 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, andAi+1 by one and increase Ai+2 by one. If Ai+2 doesn't exist, but Ai >

codechef AUG17 T2 Chef and Mover

Chef and Mover Problem Code: CHEFMOVR Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN. Bad news: Snuffles only loves to play with an array in which all the elements

codechef AUG17 T3 Greedy Candidates

Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleges. The interviews are over, and each company has selected some students. But since each student can end up finally in at most one company, a student

codechef AUG17 T4 Palindromic Game

Palindromic Game Problem Code: PALINGAM There are two players A, B playing a game. Player A has a string s with him, and player B has string t with him. Both s and t consist only of lower case English letters and are of equal length. A makes the firs

【CodeVS 5032】【省队集训2016 Day5 T1】Play with array

一开始我用分块大法,分成$\sqrt{n}$块,每个块上维护一个Splay,然后balabala维护一下,时间复杂度是$O(n\sqrt{n}logn)$.后来对拍的时候发现比$O(n^2)$的暴力跑得还慢,TA爷说是Splay常数太大2333333 标算是块状链表,什么balabala比较基础地维护,卡着空间开2333333 我把块的大小设为$[\frac{\sqrt{n}}{2},\sqrt{n}×2)$,在codevs上TLE,,, 后来把块的大小改成了$[\sqrt{n},\sqrt{n

@codechef - [email&#160;protected] Chef and Same Old Recurrence 2

目录 @[email protected] @[email protected] @accepted [email protected] @[email protected] @[email protected] 定义 dp 序列: \[dp(1) = K\dp(n) = A\times dp(n-1) + B\times \sum_{i=1}^{n-1}dp(i)\times dp(n-i)\] Q 次询问,每次询问给出 L, R,求 \(\sum_{i=L}^{R}dp(i)^2\),对 1

codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理

Description All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are th

CodeChef A String Game(SG)

A String Game Problem code: ASTRGAME Submit All Submissions All submissions for this problem are available. Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Th

maxcompute 2.0复杂数据类型之array

含义类似于Java中的array.有序.可重复. 场景什么样的数据,适合使用array类型来存储呢?这里列举了几个我在开发中实际用到的场景. 2.1 标签类的数据为什么说标签类数据适合使用array类型呢?(1)标签一般是一个只有key.没有value的结构:(2)标签的数量(枚举值个数)会非常多:(3)标签的变化会比较频繁:(4)标签会过期:因此,比起"创建多个字段"."使用指定分隔符分隔的字符串"."使用map"等方法,使用array是更合适