結果
問題 | No.921 ずんだアロー |
ユーザー |
|
提出日時 | 2019-11-08 22:29:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,151 bytes |
コンパイル時間 | 1,077 ms |
コンパイル使用メモリ | 96,248 KB |
実行使用メモリ | 7,800 KB |
最終ジャッジ日時 | 2024-09-15 01:41:18 |
合計ジャッジ時間 | 2,047 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<queue> using namespace std; #define int long long #define endl "\n" const long long INF = (long long)1e18; const long long MOD = 1'000'000'007; string yn(bool f){return f?"Yes":"No";} string YN(bool f){return f?"YES":"NO";} signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); const int MAX = 110'000; int N; int a = 0, b = 0; vector<int> A; vector<pair<int,int>> B; vector<vector<int>> dp; cin>>N; A.resize(N); for(int i = 0; i < N; i++){ cin>>A[i]; if(B.size() == 0) B.push_back({1,A[i]}); else if(B.back().second == A[i]) B.back().first++; else B.push_back({1,A[i]}); } dp.resize(2, vector<int>(B.size()+10)); for(int i = 0; i < B.size(); i++){ dp[0][i+1] = max(dp[0][i+1], dp[0][i]+B[i].first-1); dp[0][i+1] = max(dp[0][i+1], dp[1][i]+ max(0ll,B[i].first-2)); dp[1][i+1] = max(dp[1][i+1], dp[0][i]+B[i].first); dp[1][i+1] = max(dp[1][i+1], dp[1][i]+B[i].first-1); } cout<<max(dp[1][B.size()], dp[0][B.size()])<<endl; return 0; }