結果
| 問題 | No.1818 6 Operations | 
| コンテスト | |
| ユーザー |  auaua | 
| 提出日時 | 2022-01-22 15:32:14 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 145 ms / 2,500 ms | 
| コード長 | 1,651 bytes | 
| コンパイル時間 | 1,908 ms | 
| コンパイル使用メモリ | 173,852 KB | 
| 実行使用メモリ | 116,352 KB | 
| 最終ジャッジ日時 | 2024-11-27 12:48:28 | 
| 合計ジャッジ時間 | 5,027 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=2;
const ll MAX=100010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;
void solve(){
    ll n,m;cin>>n>>m;
    vector<ll>a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    vector<ll>c(0),d(0);
    rep(i,n){
        c.pb(0);
        rep(j,a[i])c.pb(1);
    }
    rep(i,m){
        d.pb(0);
        rep(j,b[i])d.pb(1);
    }
    ll x=c.size(),y=d.size();
    vector<vector<ll> >dp(x,vector<ll>(y,inf));
    if(c[0]==d[0])dp[0][0]=0;
    else dp[0][0]=1;
    rep(i,x){
        rep(j,y){
            if(i+1<x){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
                if(j+1<y){
                    if(c[i+1]==d[j+1])dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
                    else dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+1);
                }
            }
            if(j+1<y){
                dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
            }
        }
    }
    cout<<dp[x-1][y-1]<<endl;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
            
            
            
        