제출 #712596

#제출 시각아이디문제언어결과실행 시간메모리
712596danikoynovDNA 돌연변이 (IOI21_dna)C++17
22 / 100
1578 ms2436 KiB
#include "dna.h"
#include <bits/stdc++.h>

using namespace std;


string s, t;
void init(std::string a, std::string b)
{
    s = a;
    t = b;
}

int get_distance(int x, int y)
{
    string s1 = s.substr(x, y - x + 1);
    string t1 = t.substr(x, y - x + 1);
    int ans = 0;
    int cnt1 = 0, cnt2 = 0, diff = 0;
    for (int i = 0; i < s1.size(); i ++)
    {
        if (s1[i] == 'A')
            cnt1 ++;
        if (t1[i] == 'A')
            cnt2 ++;
        if (s1[i] != t1[i])
            diff ++;
    }
    if (cnt1 != cnt2)
        return -1;
    return diff / 2;
    for (int i = 0; i < t1.size(); i ++)
    {
        int j = i;
        while(j < s1.size() && s1[j] != t1[i])
            j ++;
        if (j == s1.size())
            return -1;
            if (i == j)
                continue;
        swap(s1[i], s1[j]);
        ans ++;
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < s1.size(); i ++)
      |                     ~~^~~~~~~~~~~
dna.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < t1.size(); i ++)
      |                     ~~^~~~~~~~~~~
dna.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while(j < s1.size() && s1[j] != t1[i])
      |               ~~^~~~~~~~~~~
dna.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (j == s1.size())
      |             ~~^~~~~~~~~~~~
dna.cpp:37:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   37 |         if (j == s1.size())
      |         ^~
dna.cpp:39:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   39 |             if (i == j)
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...