Task: | Edit distance |
Sender: | jeroenrobben |
Submission time: | 2018-09-22 15:16:06 +0300 |
Language: | Java |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | UNKNOWN | -- | details |
#2 | UNKNOWN | -- | details |
#3 | UNKNOWN | -- | details |
#4 | UNKNOWN | -- | details |
#5 | UNKNOWN | -- | details |
#6 | UNKNOWN | -- | details |
#7 | UNKNOWN | -- | details |
#8 | UNKNOWN | -- | details |
#9 | UNKNOWN | -- | details |
#10 | UNKNOWN | -- | details |
#11 | UNKNOWN | -- | details |
#12 | UNKNOWN | -- | details |
#13 | UNKNOWN | -- | details |
#14 | UNKNOWN | -- | details |
#15 | UNKNOWN | -- | details |
#16 | UNKNOWN | -- | details |
#17 | UNKNOWN | -- | details |
#18 | UNKNOWN | -- | details |
#19 | UNKNOWN | -- | details |
Code
import java.util.Arrays; import java.util.Scanner; public class EditDistance { public static int[] calculatedDistances; static String inputOne; static String inputTwo; static int lengthInputOne; static int indexZeroCost; public static void main(String[] args) { Scanner scan = new Scanner(System.in); inputOne = scan.nextLine(); inputTwo = scan.nextLine(); // inputOne = "LOVE"; // inputTwo = "LOVER"; lengthInputOne = inputOne.length(); calculatedDistances = new int[(lengthInputOne+1) * (inputTwo.length()+1)]; Arrays.fill(calculatedDistances, -1); indexZeroCost = calculatedDistances[0] = 0; System.out.println(distance(inputOne.length(), inputTwo.length())); scan.close(); } private static int distance(int a, int b) { if(a == 0) { return b; } if(b == 0) { return a; } // int index = b*lengthInputOne + a; int index = a*inputTwo.length() + b; int calculated = calculatedDistances[index]; if(calculated != -1) return calculated; return calculatedDistances[index] = Math.min(distance(a, b - 1) + 1, Math.min(distance(a-1, b) + 1, distance(a-1, b-1) + cost(a,b))); } private static int cost(int a, int b) { return inputOne.charAt(a-1) == inputTwo.charAt(b-1) ? 0 : 1; } }
Test details
Test 1
Verdict: UNKNOWN
input |
---|
NEABJPJOI RFMQRJKJKIA |
correct output |
---|
8 |
user output |
---|
(not available) |
Test 2
Verdict: UNKNOWN
input |
---|
TWXFUABGBNLTBFNSUVQW GPNJILFXJUIZPLTVUIB |
correct output |
---|
19 |
user output |
---|
(not available) |
Test 3
Verdict: UNKNOWN
input |
---|
HSMOWJXKGRWSMD JMRTLLNPXKKXZC |
correct output |
---|
14 |
user output |
---|
(not available) |
Test 4
Verdict: UNKNOWN
input |
---|
NGPYCNPO UQPXWVLGHC |
correct output |
---|
9 |
user output |
---|
(not available) |
Test 5
Verdict: UNKNOWN
input |
---|
SQTCKWAMFJEBV IUWGGNJOMQFP |
correct output |
---|
13 |
user output |
---|
(not available) |
Test 6
Verdict: UNKNOWN
input |
---|
VDREWLLHMEVGFGBXJJOSSLHNJBOTRK... |
correct output |
---|
4047 |
user output |
---|
(not available) |
Test 7
Verdict: UNKNOWN
input |
---|
EIIUUQXSAFMTRSEZSFYNSAGHUWTSGY... |
correct output |
---|
3769 |
user output |
---|
(not available) |
Test 8
Verdict: UNKNOWN
input |
---|
HVOXUVAZYFBKEWQXVGJMYXCCXBWRNW... |
correct output |
---|
3806 |
user output |
---|
(not available) |
Test 9
Verdict: UNKNOWN
input |
---|
AWGASQANDZQTVKXQDKWNADQDBXKCOK... |
correct output |
---|
4069 |
user output |
---|
(not available) |
Test 10
Verdict: UNKNOWN
input |
---|
WXAAJJALZRLGLSXDPUPURULYINBFGX... |
correct output |
---|
3874 |
user output |
---|
(not available) |
Test 11
Verdict: UNKNOWN
input |
---|
A A |
correct output |
---|
0 |
user output |
---|
(not available) |
Test 12
Verdict: UNKNOWN
input |
---|
A B |
correct output |
---|
1 |
user output |
---|
(not available) |
Test 13
Verdict: UNKNOWN
input |
---|
AA A |
correct output |
---|
1 |
user output |
---|
(not available) |
Test 14
Verdict: UNKNOWN
input |
---|
A AA |
correct output |
---|
1 |
user output |
---|
(not available) |
Test 15
Verdict: UNKNOWN
input |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
5000 |
user output |
---|
(not available) |
Test 16
Verdict: UNKNOWN
input |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
0 |
user output |
---|
(not available) |
Test 17
Verdict: UNKNOWN
input |
---|
B AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
5000 |
user output |
---|
(not available) |
Test 18
Verdict: UNKNOWN
input |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
5000 |
user output |
---|
(not available) |
Test 19
Verdict: UNKNOWN
input |
---|
KITTEN SITTING |
correct output |
---|
3 |
user output |
---|
(not available) |