結果

問題 No.1818 6 Operations
ユーザー tenten
提出日時 2022-01-22 21:20:48
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,819 bytes
コンパイル時間 2,740 ms
コンパイル使用メモリ 78,232 KB
実行使用メモリ 136,940 KB
最終ジャッジ日時 2024-11-27 23:01:34
合計ジャッジ時間 14,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
int nCount = 0;
HashSet<Integer> nSet = new HashSet<>();
for (int i = 0; i < n; i++) {
nSet.add(nCount);
nCount += sc.nextInt() + 1;
}
int mCount = 0;
HashSet<Integer> mSet = new HashSet<>();
for (int i = 0; i < m; i++) {
mSet.add(mCount);
mCount += sc.nextInt() + 1;
}
int[][] dp = new int[nCount+1][mCount+1];
for (int[] arr : dp) {
Arrays.fill(arr, Integer.MAX_VALUE);
}
dp[0][0] = 0;
for (int i = 0; i < nCount; i++) {
for (int j = 0; j < mCount; j++) {
if (nSet.contains(i) == mSet.contains(j)) {
dp[i + 1][j + 1] = Math.min(dp[i + 1][j + 1], dp[i][j]);
}
dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j] + 1);
dp[i][j + 1] = Math.min(dp[i][j + 1], dp[i][j] + 1);
}
}
System.out.println(dp[nCount - 1][mCount - 1]);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0