結果
問題 |
No.1268 Fruit Rush 2
|
ユーザー |
|
提出日時 | 2020-10-23 22:26:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 2,207 ms |
コンパイル使用メモリ | 202,404 KB |
最終ジャッジ日時 | 2025-01-15 13:23:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(i,n) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n; scanf("%d",&n); vector<lint> a(n); rep(i,n) scanf("%lld",&a[i]); sort(a.begin(),a.end()); vector<lint> X; rep(i,n){ for(int d=-2;d<=2;d++){ if(a[i]+d>0) X.emplace_back(a[i]+d); } } sort(X.begin(),X.end()); X.erase(unique(X.begin(),X.end()),X.end()); int m=X.size(); vector<lint> dp(m); rep(i,m){ if(binary_search(a.begin(),a.end(),X[i])){ dp[i]+=1; } if(binary_search(a.begin(),a.end(),X[i]-1)){ int idx=lower_bound(X.begin(),X.end(),X[i]-2)-X.begin(); if(idx>=0 && X[idx]==X[i]-2){ dp[i]+=dp[idx]; } } } printf("%lld\n",accumulate(dp.begin(),dp.end(),0LL)); return 0; }