結果
| 問題 |
No.1606 Stuffed Animals Keeper
|
| コンテスト | |
| ユーザー |
たたき@競プロ
|
| 提出日時 | 2023-09-01 05:12:14 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 3,000 ms |
| コード長 | 885 bytes |
| コンパイル時間 | 5,670 ms |
| コンパイル使用メモリ | 332,368 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-03 06:16:36 |
| 合計ジャッジ時間 | 7,253 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
int n;cin>>n;
vc<pp>v; v.pb({0,0});
rep(i,n){
int a;cin>>a;
if(a==2)v.pb({0,0});
if(a==0)v.back().fi++;
if(a==1)v.back().se++;
}
int s=0,c=0;
n=v.size();
rep(i,n)s+=v[i].se+v[i].fi,c+=v[i].fi;
vc<int>dp(c+1,1e8); dp[0]=0;
rep(i,n){
int t=v[i].fi+v[i].se;
auto pre=dp;
//rep(j,c+1)dp[j]=pre[j]+v[i].fi;
rep(j,c+1)if(j+t<=c)dp[j+t]=min(dp[j+t],pre[j]+v[i].se);
}
if(dp[c]==1e8)cout<<-1;
else cout<<dp[c];
}
たたき@競プロ