結果
| 問題 |
No.1606 Stuffed Animals Keeper
|
| コンテスト | |
| ユーザー |
tute7627
|
| 提出日時 | 2021-04-16 00:36:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 3,000 ms |
| コード長 | 649 bytes |
| コンパイル時間 | 2,093 ms |
| コンパイル使用メモリ | 195,832 KB |
| 最終ジャッジ日時 | 2025-01-20 18:03:18 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int>a(n);
int cnt = 0;
for(int i = 0; i < n;i++){
cin >> a[i];
if(a[i] == 0)cnt++;
}
const int inf = 1e9;
vector<int>dp(cnt + 1, inf);
dp[0] = 0;
int cost = 0, num = 0;
a.push_back(2);
for(int i = 0; i <= n; i++){
if(a[i] == 2){
for(int j = cnt; j >= 0; j--){
if(j + num <= cnt){
dp[j + num] = min(dp[j + num], dp[j] + cost);
}
}
cost = 0;
num = 0;
}
else{
num++;
cost += a[i];
}
}
if(dp[cnt] == inf)cout << -1 << endl;
else cout << dp[cnt] << endl;
}
tute7627