Codeforces Global Round 12 F問題 (2750pt)
Problem description
省略
省略
C++に変換後のコードはこちら
//no-unlocked
int N, A[1d5];
int h[1d5], sz;
{
REP(rd_int()){
int s, res, t;
rd(N,(A--)(N));
rep(i,N) h[i] = 0;
rep(i,N) h[A[i]]++;
rep(i,N) if(h[A[i]] > N-h[A[i]]+1) wt("-1"), break_continue;
rep(i,N) h[i] = 0;
s = sz = 0;
rep(i,N) if(i==N-1 || A[i]==A[i+1]){
h[A[s]]++;
h[A[i]]++;
sz += 2;
s = i+1;
}
rsortA(N,h);
t = h[0] - (sz - h[0]);
res = sz / 2 - 1;
if(t > 2) res += (t-2) / 2;
wt(res);
}
}
Current time: 2024年04月20日02時51分15秒
Last modified: 2020年12月11日22時53分24秒 (by laycrs)
Tags: Competitive_Programming_Incomplete Codeforces Codeforces_Global_Round_12
トップページに戻る
Logged in as: unknown user (not login)