結果
| 問題 |
No.1606 Stuffed Animals Keeper
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-11-18 04:35:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,665 bytes |
| コンパイル時間 | 1,196 ms |
| コンパイル使用メモリ | 112,280 KB |
| 実行使用メモリ | 818,048 KB |
| 最終ジャッジ日時 | 2024-09-26 05:38:26 |
| 合計ジャッジ時間 | 3,758 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | MLE * 1 -- * 47 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<cassert>
#include<set>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int> a(n);
for(int i = 0;i<n;i++) cin>>a[i];
vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n+1,vector<int>(3,1e9)));
dp[0][0][2] = 0;
for(int i = 0;i<n;i++){
if(a[i]==2){
for(int j = 0;j<=n;j++){
dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][0]);
dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][1]);
dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][2]);
}
continue;
}
for(int j = 0;j<=n;j++){
if(a[i]==0){
if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][0]);
if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][2]);
dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][1]+1);
dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][2]+1);
}else{
if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][0]+1);
if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][2]+1);
dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][1]);
dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][2]);
}
}
}
int ans = 1e9;
int cnt = 0;
for(int i = 0;i<n;i++) if(a[i]==0) cnt++;
ans = dp[n][cnt][0];
ans = min(ans,dp[n][cnt][1]);
ans = min(ans,dp[n][cnt][2]);
if(ans==1e9) ans = -1;
else ans = ans / 2;
cout<<ans<<endl;
}
momoyuu