Submission #717154

#TimeUsernameProblemLanguageResultExecution timeMemory
717154hcngMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define long long long
#define endl '\n'

typedef vector<long> vec;

long func(char c) {
    if (c == 'A') return 0;
    if (c == 'T') return 1;
    if (c == 'C') return 2;
}

vector<vector<vec>> psum = vector<vector<vec>>(n + 1, vector<vec>(3, vec(3, 0)));

void init(string u, string v) {
    for (long i = 0; i < n; i++) {
        psum[i + 1].assign(psum[i].begin(), psum[i].end());
        psum[i + 1][func(u[i])][func[v[i]]]++;
    }
}

int get_distance(int l, int r) {
    vector<vec> mat(3, vec(3));
    for (long i = 0; i < 3; i++) {
        for (long j = 0; j < 3; j++) {
            mat[i][j] = psum[r][i][j] - psum[l - 1][i][j];
        }
    }
    long sum1, sum2;
    for (long i = 0; i < 3; i++) {
        sum1 = 0;
        for (long j = 0; j < 3; j++) {
            sum1 += mat[i][j];
        }
        sum2 = 0;
        for (long j = 0; j < 3; j++) {
            sum2 += mat[j][i];
        }
        if (sum1 != sum2) {
            break;
        }
    }
    if (sum1 != sum2) {
        cout << -1 << endl;
        continue;
    }
    long ans = 0;
    for (long i = 0; i < 3; i++) {
        for (long j = 0; j < i; j++) {
            long temp = min(mat[i][j], mat[j][i]);
            mat[i][j] -= temp;
            mat[j][i] -= temp;
            ans += temp;
        }
    }
    ans += mat[0][1] + mat[1][0];
    return ans;
}

Compilation message (stderr)

dna.cpp:15:48: error: 'n' was not declared in this scope; did you mean 'yn'?
   15 | vector<vector<vec>> psum = vector<vector<vec>>(n + 1, vector<vec>(3, vec(3, 0)));
      |                                                ^
      |                                                yn
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:18:26: error: 'n' was not declared in this scope
   18 |     for (long i = 0; i < n; i++) {
      |                          ^
dna.cpp:20:42: warning: array subscript has type 'char' [-Wchar-subscripts]
   20 |         psum[i + 1][func(u[i])][func[v[i]]]++;
      |                                          ^
dna.cpp:20:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
dna.cpp:20:42: error: invalid conversion from 'long long int (*)(char)' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   20 |         psum[i + 1][func(u[i])][func[v[i]]]++;
      |                                 ~~~~~~~~~^
      |                                          |
      |                                          long long int (*)(char)
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::reference = long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:47:9: error: continue statement not within a loop
   47 |         continue;
      |         ^~~~~~~~
dna.cpp: In function 'long long int func(char)':
dna.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
   13 | }
      | ^