Submission #1558512
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define TASK "" #define openfile ({freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);}) const int N = 100005; int n; int a[N]; map <int, int> f; int main() { //openfile; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], f[a[i]]++; sort(a + 1, a + 1 + n); if (f.size() == 1) { return cout << n, 0; } else if (f.size() == 2) { if (a[n] - a[1] == 1 || a[n] - a[1] == 2) return cout << n, 0; int cnt1 = 0, cnt2 = 0; for (int i = 1; i <= n; i++) if (a[i] == a[1]) cnt1++; else if (a[i] == a[n]) cnt2++; return cout << max(cnt1, cnt2), 0; } else { int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, f[a[i]] + f[a[i] - 1] + f[a[i] + 1]); } cout << ans << "\n"; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Together |
User | sesshomalong |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 813 Byte |
Status | AC |
Exec Time | 92 ms |
Memory | 5120 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
1_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 22 ms | 640 KB |
1_005.txt | AC | 39 ms | 640 KB |
1_006.txt | AC | 41 ms | 640 KB |
1_007.txt | AC | 47 ms | 640 KB |
1_008.txt | AC | 92 ms | 5120 KB |