提出 #1557845


ソースコード 拡げる

#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  size_t n;
  cin >> n;
  vector<int> a(n);
  cin >> a;

  map<int, size_t> cnt;
  for(const auto i: a) ++cnt[i];

  sort(begin(a), end(a));
  a.erase(unique(begin(a), end(a)), end(a));

  size_t out = 0;
  for(const auto i: a)
  {
    out = max({out, cnt[i - 2] + cnt[i - 1] + cnt[i]});
    out = max({out, cnt[i - 1] + cnt[i] + cnt[i + 1]});
    out = max({out, cnt[i] + cnt[i + 1] + cnt[i + 2]});
  }

  cout << out;
  return EXIT_SUCCESS;
}

提出情報

提出日時
問題 C - Together
ユーザ behzad_nouri
言語 C++14 (GCC 5.4.1)
得点 300
コード長 1667 Byte
結果 AC
実行時間 82 ms
メモリ 6912 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 9
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
0_000.txt AC 1 ms 256 KiB
0_001.txt AC 1 ms 256 KiB
0_002.txt AC 1 ms 256 KiB
1_003.txt AC 1 ms 256 KiB
1_004.txt AC 9 ms 640 KiB
1_005.txt AC 12 ms 640 KiB
1_006.txt AC 12 ms 640 KiB
1_007.txt AC 16 ms 640 KiB
1_008.txt AC 82 ms 6912 KiB