{"id":297139,"date":"2020-01-14T21:00:08","date_gmt":"2020-01-14T21:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297139"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297139","title":{"rendered":"\u041e\u0445 \u0443\u0436 \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 C\/C++"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484002\/\">\u042d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u043e\u0434\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0442\u043e\u0433\u043e\u0432 \u043d\u0430 \u043f\u043e\u0441\u0442 <a href=\"https:\/\/habr.com\/ru\/post\/483864\/\">\u201c\u0411\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c C++; \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c PHP\u201d<\/a><\/p>\n<p>  \u041d\u0435\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u043b\u043e \u2014 \u00ab\u0441\u043f\u043e\u0440\u0438\u0442\u044c\u00bb \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u044b\u0441\u043b\u0435\u0439 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442. \u0410\u0432\u0442\u043e\u0440 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u043b <a href=\"https:\/\/habr.com\/ru\/post\/483592\/#comment_21121506\">\u0442\u0443\u0442<\/a>, <a href=\"https:\/\/habr.com\/ru\/post\/483592\/#comment_21120802\">\u0442\u0443\u0442<\/a>, \u0438 \u0435\u0449\u0435 <a href=\"https:\/\/duckduckgo.com\/?q=0xd34df00d\" rel=\"nofollow\">\u043c\u043d\u043e\u0433\u043e \u0433\u0434\u0435<\/a>, \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0430\u0436 \u0438 \u0431\u043e\u0433\u0430\u0442\u044b\u0439 \u043e\u043f\u044b\u0442 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u0421++.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u00ab\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u00bb \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0438\u0437 \u043d\u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 C \u0438 C++  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043a\u043e\u0434 C<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt;  static long lev_dist (const char *s1,           const char *s2) {     unsigned long m, n;     unsigned long i, j;     long *v0, *v1;     long ret, *temp;      m = strlen (s1);     n = strlen (s2);      \/* Edge cases. *\/     if (m == 0) {         return n;     } else if (n == 0) {         return m;     }      v0 = malloc (sizeof (long) * (n + 1));     v1 = malloc (sizeof (long) * (n + 1));      if (v0 == NULL || v1 == NULL) {         fprintf (stderr, \"failed to allocate memory\\n\");         exit (-1);     }      for (i = 0; i &lt;= n; ++i) {         v0[i] = i;     }     memcpy (v1, v0, n + 1);      for (i = 0; i &lt; m; ++i) {         v1[0] = i + 1;          for (j = 0; j &lt; n; ++j) {             const long subst_cost = (s1[i] == s2[j]) ? v0[j] : (v0[j] + 1);             const long del_cost = v0[j + 1] + 1;             const long ins_cost = v1[j] + 1;  #if !defined(__GNUC__) || defined(__llvm__)             if (subst_cost &lt; del_cost) {                 v1[j + 1] = subst_cost;             } else {                 v1[j + 1] = del_cost;             } #else             v1[j + 1] = (subst_cost &lt; del_cost) ? subst_cost : del_cost; #endif             if (ins_cost &lt; v1[j + 1]) {                 v1[j + 1] = ins_cost;             }         }          temp = v0;         v0 = v1;         v1 = temp;     }      ret = v0[n];     free (v0);     free (v1);     return ret; }  int main () {     const int len = 15000;     int i;     char s1[15001], *s2 = s1, s3[15001];     clock_t start_time, exec_time;      for (i = 0; i &lt; len; ++i) {         s1[i] = 'a';         s3[i] = 'b';     }     s1[len] = s3[len] = '\\0';      start_time = clock ();      printf (\"%ld\\n\", lev_dist (s1, s2));     printf (\"%ld\\n\", lev_dist (s1, s3));      exec_time = clock () - start_time;     fprintf (stderr,              \"Finished in %.3fs\\n\",              ((double) exec_time) \/ CLOCKS_PER_SEC);     return 0; }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;algorithm&gt; #include &lt;iostream&gt; #include &lt;numeric&gt; #include &lt;vector&gt; #include &lt;string&gt;  size_t lev_dist(const std::string&amp; s1, const std::string&amp; s2) {   const auto m = s1.size();   const auto n = s2.size();    std::vector&lt;int64_t&gt; v0;   v0.resize(n + 1);   std::iota(v0.begin(), v0.end(), 0);    auto v1 = v0;    for (size_t i = 0; i &lt; m; ++i)   {     v1[0] = i + 1;      for (size_t j = 0; j &lt; n; ++j)     {       auto delCost = v0[j + 1] + 1;       auto insCost = v1[j] + 1;       auto substCost = s1[i] == s2[j] ? v0[j] : (v0[j] + 1);        v1[j + 1] = std::min({ delCost, insCost, substCost });     }      std::swap(v0, v1);   }    return v0[n]; }  int main() {     std::string s1(20000, 'a');     std::string s2(20000, 'a');     std::string s3(20000, 'b');      std::cout &lt;&lt; lev_dist(s1, s2) &lt;&lt; std::endl;     std::cout &lt;&lt; lev_dist(s1, s3) &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0422\u0440\u0438 \u0433\u0440\u0443\u0431\u0435\u0439\u0448\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u041c\u0435\u0442\u043e\u0434\u043e\u043b\u043e\u0433\u0438\u044f \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u0412 \u043a\u043e\u0434\u0435 \u043d\u0430 \u0421 \u0437\u0430\u043c\u0435\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u0434\u0435, \u0430 \u0421++ \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442, \u0435\u0441\u043b\u0438 \u0437\u0430\u043c\u0435\u0440\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0447\u0435\u0440\u0435\u0437 time (*nix \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445) \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0435\u043a\u0430 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/li>\n<li>\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u043e \u0438 \u0432\u044b\u0432\u043e\u0434 \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u0434\u0430\u0436\u0435 \u0432 \u0442\u0430\u043a\u0438\u0445, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u00ab\u0440\u043e\u0434\u043d\u044b\u0445\u00bb \u044f\u0437\u044b\u043a\u0430\u0445 \u0421\/\u0421++, \u0432\u044b\u0432\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 printf \u0438 cout \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u2014 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0430 \u043d\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/li>\n<li>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0430 \u0434\u0432\u0443\u0445 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043d\u043e \u043d\u0435 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e CPU \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044b \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u043a\u043e\u0434\u0430:<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 \u0421 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435<br \/> \n<pre><code class=\"cpp\"> char s1[15001], *s2 = s1, s3[15001];<\/code><\/pre>\n<p>   \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 s2 \u044d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 s1. \u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0435\u0441\u0442\u0435   <\/p>\n<pre><code class=\"cpp\">printf (\"%ld\\n\", lev_dist (s1, s2));<\/code><\/pre>\n<p>   \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 2 \u0440\u0430\u0437\u0430 \u0440\u0435\u0436\u0435 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442.<br \/>   \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 <\/p>\n<pre><code class=\"cpp\">char s1[15001], s2[15001], s3[15001];<\/code><\/pre>\n<p> \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 s2.<br \/>   \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0434 \u043d\u0430 C \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 20-30% \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0447\u0435\u043c \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043e.<\/li>\n<li>\u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 C++ \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e.<br \/>  \u041c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u043e\u043a 20000 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0445 15000, \u0445\u043e\u0442\u044c \u0430\u0432\u0442\u043e\u0440 \u0438 \u0443\u043a\u0430\u0437\u0430\u043b \u0447\u0442\u043e \u0438\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b (\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0438) \u044d\u0442\u043e \u043b\u0443\u043a\u0430\u0432\u0441\u0442\u0432\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u041a\u0435\u0448 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u0430\u0434\u0430\u044e\u0442, \u0438\u0442\u043e\u0433\u043e 1-5% \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043e.<\/li>\n<li>\u041d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430, \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439<br \/> \n<pre><code class=\"cpp\">v1[j + 1] = std::min({ delCost, insCost, substCost });<\/code><\/pre>\n<p>  \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0435\u043a \u043d\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0420\u0435\u0448\u0430\u0435\u0442\u044c\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u0434\u0438\u043e\u043c\u043e\u0439 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u0442\u0440\u0435\u0445  <\/p>\n<pre><code class=\"cpp\"> v1[j + 1] = std::min(std::min(delCost, insCost), substCost);<\/code><\/pre>\n<p>  \u0438\u0442\u043e\u0433 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c 250-300% \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043e.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430:<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u0430 \u0433\u0434\u0435 \u0438\u0434\u0435\u0442 \u00ab\u043f\u043b\u043e\u0442\u043d\u0430\u044f\u00bb \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u043d\u0438\u0445 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0434\u0438\u043d \u043f\u0440\u044f\u043c\u043e\u0439 if \u0438 \u0434\u0432\u0430 \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0438\u0441\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 (std::min). \u0415\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u0430\n<pre><code class=\"cpp\">min = x ^ ((y ^ x) &amp; -(x &gt; y))<\/code><\/pre>\n<p> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 x, y. \u0417\u0430\u043c\u0435\u043d\u0438\u0432 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430  <\/p>\n<pre><code class=\"cpp\">auto z = substCost ^ ((insCost ^ substCost) &amp; -(substCost &gt; insCost)); v1[j + 1] = z ^ ((delCost ^ z) &amp; -(z &gt; delCost));<\/code><\/pre>\n<p>  \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 1-10% (\u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0447\u0442\u043e \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437\u043d\u043e\u0440\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445)<\/li>\n<li>\u0421\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u044c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438\n<pre><code class=\"cpp\">substCost = s1[i] == s2[j] ? v0[j] : (v0[j] + 1);<\/code><\/pre>\n<p> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u043a\u0443 \u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435, \u0447\u0442\u043e \u0442\u043e\u0436\u0435 \u0434\u0430\u0441\u0442 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043d\u0430 1-4%, \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0430\u043c, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c.<\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/484002\/\"> https:\/\/habr.com\/ru\/post\/484002\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484002\/\">\u042d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u043e\u0434\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0442\u043e\u0433\u043e\u0432 \u043d\u0430 \u043f\u043e\u0441\u0442 <a href=\"https:\/\/habr.com\/ru\/post\/483864\/\">\u201c\u0411\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c C++; \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c PHP\u201d<\/a><\/p>\n<p>  \u041d\u0435\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0435 \u0434\u0435\u043b\u043e \u2014 \u00ab\u0441\u043f\u043e\u0440\u0438\u0442\u044c\u00bb \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u044b\u0441\u043b\u0435\u0439 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442. \u0410\u0432\u0442\u043e\u0440 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u043b <a href=\"https:\/\/habr.com\/ru\/post\/483592\/#comment_21121506\">\u0442\u0443\u0442<\/a>, <a href=\"https:\/\/habr.com\/ru\/post\/483592\/#comment_21120802\">\u0442\u0443\u0442<\/a>, \u0438 \u0435\u0449\u0435 <a href=\"https:\/\/duckduckgo.com\/?q=0xd34df00d\" rel=\"nofollow\">\u043c\u043d\u043e\u0433\u043e \u0433\u0434\u0435<\/a>, \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0430\u0436 \u0438 \u0431\u043e\u0433\u0430\u0442\u044b\u0439 \u043e\u043f\u044b\u0442 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u0421++.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297139","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297139"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297139\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}