結果
| 問題 |
No.1268 Fruit Rush 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-11 18:39:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 3,329 bytes |
| コンパイル時間 | 2,084 ms |
| コンパイル使用メモリ | 198,828 KB |
| 最終ジャッジ日時 | 2025-01-15 22:08:30 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using i128 = __int128_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using u128 = __uint128_t; using vi32 = vector<i32>; using vi64 = vector<i64>; using vu32 = vector<u32>; using vu64 = vector<u64>; using pi32 = pair<i32, i32>; using pi64 = pair<i64, i64>; using pu32 = pair<u32, u32>; using pu64 = pair<u64, u64>; using vpi32 = vector<pi32>; using vpi64 = vector<pi64>; using vpu32 = vector<pu32>; using vpu64 = vector<pu64>;
using f32 = float;
using f64 = double;
const char alphabetl[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
const char alphabetu[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
const i32 dx[4] = { 1, 0, -1, 0 };
const i32 dy[4] = { 0, 1, 0, -1 };
const double pi = 3.141592653589793238462643383279502884197169;
const double napier = 2.718281828459045235360287471352662497757247;
static const double EPS = 1e-8;
static const i64 INF64 = 1e18;
static const i32 INF32 = (1 << 30) - 1;
static const i64 MOD = (i64) 1e9 + 7;
const int NM = 100100;
#define cauto const auto&
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define itn int
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=0; i<=(int)(n); i++)
#define rrep(i,n) for(int i=(n-1); i>=0; i--)
#define rreps(i,n) for(int i=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define FOREQ(i,a,b) for(int i=a; i<=(int)(b); i++)
#define RFOR(i,a,b) for(int i=a; i>(int)(b); i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define PRINT(n) cout << n << "\n";
#define PRINT2(n, m) cout << n << " " << m << " "<< "\n";
#define IN(a, x, b) (a<=x && x<b)
#define pb push_back
#define fst first
#define snd second
template<class T1, class T2>
bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2>
bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
void Main();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(15);
Main();
return 0;
}
void Main(){
// your code here!
int N;
cin >> N;
vi64 A(N);
rep(i,N) cin >> A[i];
sort(ALL(A));
vi32 dp(N+1,0);
for(int i=N; i>=0; i--){
if(i+1<N && A[i]+2 == A[i+1]) dp[i] = dp[i+1]+1;
if(i+2<N && A[i]+2 == A[i+2]) dp[i] = dp[i+2]+1;
}
i64 ans=N;
for(int i=0; i+1<N;i++) {
if(A[i]+1!=A[i+1]) continue;
ans+=dp[i+1]+1;
}
cout<<ans<<endl;
}