CSES - E4590 2018 2 - Results
Submission details
Task:Edit distance
Sender:natalia
Submission time:2018-09-22 15:50:44 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1UNKNOWN--details
#2UNKNOWN--details
#3UNKNOWN--details
#4UNKNOWN--details
#5UNKNOWN--details
#6UNKNOWN--details
#7UNKNOWN--details
#8UNKNOWN--details
#9UNKNOWN--details
#10UNKNOWN--details
#11UNKNOWN--details
#12UNKNOWN--details
#13UNKNOWN--details
#14UNKNOWN--details
#15UNKNOWN--details
#16UNKNOWN--details
#17UNKNOWN--details
#18UNKNOWN--details
#19UNKNOWN--details

Code

#include <iostream>
#include <string>

inline int min(int x, int y){
    return y ^ ((x ^ y) & -(x < y));
}


int main(int argc, const char * argv[]) {
    
    std::string word1, word2;
    std::cin >> word1;
    std::cin >> word2;
    
    //std::getline(std::cin, word1);
    //std::getline(std::cin, word2);
    
    int cols = word1.length();
    int rows = word2.length();
    
    int* data = (int*)malloc((rows + 1) * (cols + 1) * sizeof(int));
    
    data[0] = 0;
    for(int i = 1; i <= cols; i++)
        data[i] = i;
    
    for(int i = 1; i <= rows; i++)
        data[i * (cols + 1)] = i;
    
    
    for(int i = 1; i <= rows; i++){
        for(int j = 1; j <= cols; j++){
            int own = word1[j - 1] != word2[i - 1];
            int other = std::min(data[(i - 1) * (cols + 1) + j - 1] + own, std::min(data[(i - 1) * (cols + 1) + j] + 1, data[i * (cols + 1) + j - 1] + 1));
            
            //std::cout << "i=" << i << " j=" << j << " own=" << own << " other=" << other << "\n";
            
            data[i * (cols + 1) + j] = other;
        }
    }
    
    /*
    for(int i = 0; i <= rows; i++){
        for(int j = 0; j <= cols; j++){
            std::cout << data[i * (cols + 1) + j] << "\t";
        }
        std::cout << "\n";
    }
    std::cout << "\n";
     */
    
    
    std::cout << data[rows * (cols + 1) + cols] << "\n";
    
    return 0;
}


/*
 std::ios::sync_with_stdio();
 
 char* word1 = (char*)malloc(5000 * sizeof(char));
 char* word2 = (char*)malloc(5000 * sizeof(char));
 
 
 std::cin.getline (word1, 5000);
 
 std::cout << word1 << "\n";
 
 free(word1);
 free(word2);
 
 
 return 0;
 */


/*
 for(int i = 0; i <= rows; i++){
 for(int j = 0; j <= cols; j++){
 std::cout << data[i * (cols + 1) + j] << "\t";
 }
 std::cout << "\n";
 }
 std::cout << "\n";
 */


/*
 for(int i = 0; i <= rows; i++){
 for(int j = 0; j <= cols; j++){
 std::cout << data[i * (cols + 1) + j] << "\t";
 }
 std::cout << "\n";
 }
 std::cout << "\n";
 */

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)