結果
問題 |
No.1818 6 Operations
|
ユーザー |
![]() |
提出日時 | 2022-01-23 20:48:26 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,811 bytes |
コンパイル時間 | 2,505 ms |
コンパイル使用メモリ | 78,612 KB |
実行使用メモリ | 136,896 KB |
最終ジャッジ日時 | 2024-11-30 02:18:40 |
合計ジャッジ時間 | 15,939 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 2 WA * 28 |
ソースコード
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][mCount]); } } 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(); } }