結果
| 問題 |
No.1268 Fruit Rush 2
|
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-10-23 23:17:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 985 bytes |
| コンパイル時間 | 845 ms |
| コンパイル使用メモリ | 85,448 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-21 13:09:31 |
| 合計ジャッジ時間 | 3,016 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 12 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll a[200000];
void input(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
}
ll dp[200000];
void solve(){
sort(a, a+n);
ll ans = 0;
int cnt = 0;
for(int i = 0; i < n; i++){
if(i == 0 || a[i-1]+1 < a[i]){
if(cnt >= 2){
ans += dp[i-2];
}
dp[i] = 1;
cnt = 1;
}else{
if(cnt == 1){
dp[i] = 1;
}else{
dp[i] = dp[i-2]+1;
}
cnt++;
}
ans += dp[i];
// cout << dp[i] << ' ';
}
if(cnt >= 2){
ans += dp[n-2];
}
// cout << endl;
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
input();
solve();
}
milanis48663220