結果

問題 No.1818 6 Operations
ユーザー 沙耶花沙耶花
提出日時 2022-01-21 21:59:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,500 ms
コード長 917 bytes
コンパイル時間 4,293 ms
コンパイル使用メモリ 261,692 KB
実行使用メモリ 59,856 KB
最終ジャッジ日時 2023-08-17 05:57:48
合計ジャッジ時間 7,682 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 33 ms
20,040 KB
testcase_09 AC 69 ms
35,676 KB
testcase_10 AC 33 ms
20,296 KB
testcase_11 AC 31 ms
19,048 KB
testcase_12 AC 53 ms
29,080 KB
testcase_13 AC 40 ms
24,216 KB
testcase_14 AC 48 ms
27,372 KB
testcase_15 AC 57 ms
31,336 KB
testcase_16 AC 45 ms
26,668 KB
testcase_17 AC 69 ms
37,928 KB
testcase_18 AC 103 ms
52,244 KB
testcase_19 AC 90 ms
50,092 KB
testcase_20 AC 103 ms
52,672 KB
testcase_21 AC 108 ms
53,472 KB
testcase_22 AC 82 ms
46,392 KB
testcase_23 AC 113 ms
56,720 KB
testcase_24 AC 93 ms
47,984 KB
testcase_25 AC 109 ms
59,856 KB
testcase_26 AC 96 ms
48,732 KB
testcase_27 AC 102 ms
51,144 KB
testcase_28 AC 33 ms
20,240 KB
testcase_29 AC 31 ms
18,920 KB
testcase_30 AC 109 ms
51,972 KB
testcase_31 AC 98 ms
55,100 KB
testcase_32 AC 114 ms
57,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

string get(vector<int> a){
	string ret = "1";
	rep(i,a.size()){
		rep(j,a[i])ret += '0';
		ret += '1';
	}
	return ret;
}

int main(){
	
	int n,m;
	cin>>n>>m;
	
	vector<int> a(n),b(m);
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	
	string s = get(a);
	string t = get(b);
	n = s.size(),m = t.size();
	vector dp(n+1,vector<int>(m+1,Inf));
	dp[0][0] = 0;
	
	rep(i,n+1){
		rep(j,m+1){
			if(i!=n){
				dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1);
			}
			if(j!=m){
				dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1);
			}
			if(i!=n&&j!=m){
				if(s[i]==t[j]){
					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);
				}
			}
		}
	}
	cout<<dp[n][m]<<endl;
	
	return 0;
}
0