結果
問題 | No.225 文字列変更(medium) |
ユーザー | h sak |
提出日時 | 2020-11-04 01:11:42 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,469 bytes |
コンパイル時間 | 3,204 ms |
コンパイル使用メモリ | 78,144 KB |
実行使用メモリ | 49,868 KB |
最終ジャッジ日時 | 2024-07-22 09:28:09 |
合計ジャッジ時間 | 6,176 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
41,224 KB |
testcase_01 | AC | 101 ms
45,568 KB |
testcase_02 | AC | 50 ms
36,288 KB |
testcase_03 | AC | 50 ms
36,204 KB |
testcase_04 | AC | 56 ms
36,744 KB |
testcase_05 | WA | - |
testcase_06 | AC | 53 ms
36,764 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 53 ms
36,552 KB |
testcase_10 | AC | 55 ms
36,724 KB |
testcase_11 | AC | 53 ms
36,724 KB |
testcase_12 | AC | 108 ms
45,508 KB |
testcase_13 | AC | 111 ms
49,868 KB |
testcase_14 | AC | 112 ms
45,608 KB |
testcase_15 | AC | 108 ms
45,612 KB |
testcase_16 | AC | 111 ms
45,684 KB |
testcase_17 | AC | 110 ms
45,792 KB |
testcase_18 | AC | 112 ms
45,840 KB |
testcase_19 | AC | 111 ms
45,504 KB |
testcase_20 | AC | 115 ms
45,644 KB |
testcase_21 | AC | 109 ms
45,616 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { //https://qiita.com/drken/items/a5e6fe22863b7992efdb //#10 public static void main(String[] args) { FastScanner scan = new FastScanner(); long mod = 998244353L; int n = scan.nextInt(); int m = scan.nextInt(); // long k = scan.nextLong(); // long[] a = new long[n]; // long[] v = new long[n]; // long[] z = new long[n]; // int bit = 0; String s = scan.next(); String t = scan.next(); long [][] dp = new long[s.length()+1][t.length()+1]; //dp[s.length][t.length] : Sのs.length文字までとTの・・・での最長ぶぶん文字列 // long count = 0L; // double min = 200; // for (int i = 0; i < n; i++) { // a[i] = scan.nextLong(); // v[i] = scan.nextLong(); // z[i] = scan.nextLong(); // } dp[0][0]= 0L; for (int i = 1; i < s.length(); i++) { dp[i][0] = i; } for (int i = 1; i < t.length(); i++) { dp[0][i] = i; } for (int i = 0; i < s.length(); i++) { for (int j = 0; j < t.length(); j++) { if(s.charAt(i)==t.charAt(j)) { dp[i+1][j+1] = dp[i][j]; } else { dp[i+1][j+1] = Math.min(dp[i][j]+1, dp[i+1][j]+1); dp[i+1][j+1] = Math.min(dp[i+1][j+1], dp[i][j+1]+1); } } } System.out.println(dp[s.length()][t.length()]); } static long dp(int bit, int now, long[][] dp , int n, long[]x, long[]y, long[]z) { if(dp[bit][now] >0) { return dp[bit][now]; } if (bit == (1<<n) -1) { long tmp = Math.abs(x[0] -x[now]) + Math.abs(y[0] - y[now]) + Math.max(0, z[0]-z[now]); dp[bit][now]= tmp; return tmp; } long min = Long.MAX_VALUE; for (int i = 0; i < n; i++) { if((bit & 1<<i) != 0) continue; long d = dp(bit | 1<<i, i, dp, n, x, y, z); long tmp = d + Math.abs(x[i] -x[now]) + Math.abs(y[i] - y[now]) + Math.max(0, z[i]-z[now]); min = tmp < min ? tmp : min; } dp[bit][now]= min; return min; } static boolean nextPermutation(int[] a) { int n=a.length; int p=n-1; while (p-1>=0 && a[p-1]>a[p]) --p; if (p==0) return false; int q=p; while (q+1<n && a[p-1]<a[q+1]) ++q; swap(p-1,q,a); int s=p; int t=n-1; while (s<t) swap(s++,t--,a); return true; } static void swap(int i,int j,int[] a) { a[i]^=a[j];a[j]^=a[i];a[i]^=a[j]; } // void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} private static class DSU { int[] root; int[] height; // long[] a; //customizable // long[] b; //customizable int n; DSU(int n) { this.n = n; root = new int[n]; height = new int[n]; // a = new long[n]; // b = new long[n]; for(int i = 0; i < n; i++) root[i] = i; } int findParent(int idx) { if(root[idx] != idx) { root[idx] = findParent(root[idx]); return root[idx]; } return idx; } boolean union(int x, int y) { int parX = findParent(x); int parY = findParent(y); if(parX == parY) return false; if(height[parX] < height[parY]) { root[parY] = parX; height[parX] += height[parY]+1; // a[parX] +=a[parY]; //customizable // b[parX] +=b[parY]; //customizable } else { root[parX] = parY; height[parY] += height[parX]+1; // a[parY] +=a[parX]; //customizable // b[parY] +=b[parX]; //customizable } return true; } } static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} } }