Submission #1557436


Source Code Expand

/* Written by Filip Hlasek 2017 */
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>

#define FOR(i, a, b)   for (int i = (a); i <= (b); i++)
#define FORD(i, a, b)  for (int i = (a); i >= (b); i--)
#define REP(i, b)      for (int i =  0 ; i <  (b); i++)

using namespace std;

#define MAXN 111111
int cnt[MAXN];

int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  REP(i, N) {
    int a;
    scanf("%d", &a);
    cnt[a]++;
  }
  int ans = 0;
  REP(i, MAXN - 1) ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2]);
  printf("%d\n", ans);
  return 0;
}

Submission Info

Submission Time
Task C - Together
User fhlasek
Language C++14 (GCC 5.4.1)
Score 300
Code Size 759 Byte
Status AC
Exec Time 10 ms
Memory 640 KB

Compile Error

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:26:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
                  ^
./Main.cpp:29:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a);
                    ^
./Main.cpp:33:66: warning: iteration 111109u invokes undefined behavior [-Waggressive-loop-optimizations]
   REP(i, MAXN - 1) ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2]);
                                                                  ^
./Main.cpp:17:44: note: containing loop
 #define REP(i, b)      for (int i =  0 ; i <  (b); i++)
                                            ^
./Main.cpp:33:3: note: in expansion of macro ‘REP’
   REP(i, MAXN - 1) ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2]);
   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 9
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 8 ms 256 KB
1_005.txt AC 10 ms 256 KB
1_006.txt AC 10 ms 256 KB
1_007.txt AC 10 ms 256 KB
1_008.txt AC 10 ms 640 KB