NC244829. Make it Equal
描述
输入描述
The first line contains one integers . As described in the statement .
Then the second line contains integers .
输出描述
Output an integer in a single line , indicates the answer.
示例1
输入:
3 5 4 4
输出:
2
示例2
输入:
4 10 10 10 1
输出:
3
C++(g++ 7.5.0) 解法, 执行用时: 40ms, 内存消耗: 672K, 提交时间: 2023-05-10 20:40:08
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int t=0,a,b; cin>>a; for(int i=2;i<=n;i++){ cin>>b; if(b!=a)t=1; } if(t==1)cout<<n-1; else cout<<n; }
C++(clang++ 11.0.1) 解法, 执行用时: 18ms, 内存消耗: 408K, 提交时间: 2022-10-22 13:37:57
#include<cstdio> int n,x; bool flag=1;int b; int main() { scanf("%d",&n);scanf("%d",&b); for(int i=2;i<=n;i++)scanf("%d",&x),flag&=x==b; printf("%d\n",flag?n:n-1); }
pypy3 解法, 执行用时: 130ms, 内存消耗: 36288K, 提交时间: 2023-05-18 18:48:20
n = int(input()) s = set(list(map(int, input().split()))) print(n if len(s) == 1 else n - 1)
Python3 解法, 执行用时: 70ms, 内存消耗: 19172K, 提交时间: 2022-10-24 23:36:56
n=input() print(n if len(set(input().split()))==1else int(n)-1)