結果

問題 No.1268 Fruit Rush 2
コンテスト
ユーザー kotatsugame
提出日時 2020-10-24 01:55:04
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 389 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 687 ms
コンパイル使用メモリ 81,148 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-03 05:00:19
合計ジャッジ時間 9,001 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge5_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #
raw source code

#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[2<<17];
long ans;
int cnt[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	for(int i=N;i--;)
	{
		if(A[i+1]==A[i]+2)cnt[i]=cnt[i+1]+1;
		else if(A[i+2]==A[i]+2)cnt[i]=cnt[i+2]+1;
		else cnt[i]=1;
	}
	for(int i=0;i<N;i++)
	{
		ans++;
		if(A[i]+1==A[i+1])ans+=cnt[i+1];
	}
	cout<<ans<<endl;
}
0