NC232086. Generate 7 Colors
描述
输入描述
The first line contains an integer --- the number of test cases.
Each test case is described by integers in one line --- the pieces Albedo needs for colors respectively.
输出描述
For each test, output an integer in one line --- the minimum number of operations to generate exact pieces for all colors. If it's impossible to do it, output -1.
示例1
输入:
3 2 2 2 2 1 1 1 3 3 3 3 1 1 1 1 1 1 1 1 1 1000000000
输出:
1 2 -1
说明:
For test case , Albedo can use operation and generate the sequence .C++ 解法, 执行用时: 353ms, 内存消耗: 1316K, 提交时间: 2021-12-19 16:00:50
#include<bits/stdc++.h> using namespace std; int _,a[7]; int main () { cin>>_; while (_--) { for (int i=0;i<7;i++) cin>>a[i]; int f=1; for (int i=0;i<6;i++) if (a[i]<a[i+1]) f=0; if (!f) { cout<<"-1\n"; continue; } cout<<max(1,a[0]-a[6])<<'\n'; } }
Python3 解法, 执行用时: 897ms, 内存消耗: 5496K, 提交时间: 2022-03-07 16:52:18
for _ in range(int(input())): a=list(map(int,input().split())) f=1 for i in range(6,0,-1): if a[i]>a[i-1]: f=0 break if f: print(max(1,a[0]-a[-1])) else: print(-1)