Submission #4032741


Source Code Expand

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i != 0) {
      if (A[i] - A[i - 1] > 1) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (A[0] > 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (A[i] != A[i - 1] + 1) {
      ans += A[i - 1];
    }
  }
  ans += A[N - 1];

  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task C - Sequence Growing Easy
User null_null
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2423 Byte
Status AC
Exec Time 60 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 49
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 1792 KB
02.txt AC 2 ms 1792 KB
03.txt AC 2 ms 1792 KB
04.txt AC 2 ms 1792 KB
05.txt AC 2 ms 1792 KB
06.txt AC 2 ms 1792 KB
07.txt AC 57 ms 1792 KB
08.txt AC 56 ms 1792 KB
09.txt AC 56 ms 1792 KB
10.txt AC 56 ms 1792 KB
11.txt AC 3 ms 1792 KB
12.txt AC 2 ms 1792 KB
13.txt AC 3 ms 1792 KB
14.txt AC 3 ms 1792 KB
15.txt AC 56 ms 1792 KB
16.txt AC 56 ms 1792 KB
17.txt AC 58 ms 1792 KB
18.txt AC 56 ms 1792 KB
19.txt AC 60 ms 1792 KB
20.txt AC 59 ms 1792 KB
21.txt AC 46 ms 1792 KB
22.txt AC 42 ms 1792 KB
23.txt AC 46 ms 1792 KB
24.txt AC 39 ms 1792 KB
25.txt AC 55 ms 1792 KB
26.txt AC 56 ms 1792 KB
27.txt AC 55 ms 1792 KB
28.txt AC 55 ms 1792 KB
29.txt AC 55 ms 1792 KB
30.txt AC 54 ms 1792 KB
31.txt AC 2 ms 1792 KB
32.txt AC 2 ms 1792 KB
33.txt AC 34 ms 1792 KB
34.txt AC 45 ms 1792 KB
35.txt AC 57 ms 1792 KB
36.txt AC 60 ms 1792 KB
37.txt AC 57 ms 1792 KB
38.txt AC 57 ms 1792 KB
39.txt AC 60 ms 1792 KB
40.txt AC 60 ms 1792 KB
41.txt AC 1 ms 256 KB
42.txt AC 1 ms 256 KB
43.txt AC 1 ms 256 KB
44.txt AC 1 ms 256 KB
45.txt AC 1 ms 256 KB
46.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB