Submission #2166806
Source Code Expand
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)
template <typename Tp> void in(Tp &x) {
char ch = getchar(), f = 1; x = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') ch = getchar(), f = -1;
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
template <typename Tp> void out(Tp x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
return;
}
template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}
const int MAXN = 100010;
int n, A[MAXN];
int tot[MAXN];
void wa()
{
puts("No"); exit(0);
}
int main()
{
in(n); FOR(i, 1, n) in(A[i]);
int pos = -1;
FOR(i, 2, n) if (A[i] != A[1]) pos = i;
if (pos != -1) {
if (A[pos] != A[1] + 1 && A[pos] != A[1] - 1) wa();
FOR(i, pos + 1, n) if (A[i] != A[pos] && A[i] != A[1]) wa();
}
if (pos == -1) {
if (A[1] + 1 != n) {
if (A[1] * 2 > n) wa();
}
}
else {
int all = 0;
if (A[pos] == A[1] + 1) all = A[pos];
else all = A[1];
int tot = 0;
FOR(i, 1, n) if (A[i] == all - 1) tot++;
if ((all - tot) * 2 + tot > n || n - tot < 2) wa();
}
puts("Yes");
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Colorful Hats |
User |
xy20130630 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1588 Byte |
Status |
WA |
Exec Time |
6 ms |
Memory |
640 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 0_05.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 0_05.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
0_03.txt |
AC |
1 ms |
256 KB |
0_04.txt |
AC |
1 ms |
256 KB |
0_05.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
3 ms |
640 KB |
1_03.txt |
AC |
6 ms |
640 KB |
1_04.txt |
AC |
6 ms |
640 KB |
1_05.txt |
AC |
6 ms |
640 KB |
1_06.txt |
AC |
6 ms |
640 KB |
1_07.txt |
AC |
6 ms |
640 KB |
1_08.txt |
WA |
3 ms |
640 KB |
1_09.txt |
AC |
6 ms |
640 KB |
1_10.txt |
WA |
3 ms |
640 KB |
1_11.txt |
AC |
6 ms |
640 KB |
1_12.txt |
AC |
6 ms |
640 KB |
1_13.txt |
AC |
6 ms |
640 KB |
1_14.txt |
AC |
6 ms |
640 KB |
1_15.txt |
AC |
1 ms |
256 KB |
1_16.txt |
AC |
1 ms |
256 KB |
1_17.txt |
AC |
6 ms |
640 KB |