Submission #1203349

#TimeUsernameProblemLanguageResultExecution timeMemory
1203349aigormMutating DNA (IOI21_dna)C++20
Compilation error
0 ms0 KiB
#define pb push_back
#define ll long long
using namespace std;

// A => 0
// C => 1
// T => 2

bool gc;

vector<int> A, B;

typedef vector<array<int, 3>> pref;

vector<pref> pref_tbl;

void init(string a, string b)
{
    gc = true;
    // cerr << "A\n";
    //  adder.clear();
    //              A  C  T
    pref adder = {{0, 0, 0},
                  {0, 0, 0},
                  {0, 0, 0}};
    pref_tbl.clear();

    int abc[3];

    for (int i = 0; i < a.size(); i++)
    {
        if (b[i] == 'A')
        {
            B.pb(0);
            abc[0]++;
        }
        else if (b[i] == 'C')
        {
            B.pb(1);
            abc[1]++;
        }
        else if (b[i] == 'T')
        {
            B.pb(2);
            abc[2]++;
        }
    }
    // cerr << "B\n";

    pref_tbl.pb(adder);
    for (int i = 0; i < b.size(); i++)
    {
        // cpp_dump(adder);
        // cpp_dump(pref_tbl);
        if (a[i] == 'A')
        {
            A.pb(0);
            abc[0]--;
            if (b[i] == 'C')
                adder[0][1]++;
            if (b[i] == 'T')
                adder[0][2]++;
        }
        else if (a[i] == 'C')
        {
            A.pb(1);
            abc[1]--;
            if (b[i] == 'A')
                adder[1][0]++;
            if (b[i] == 'T')
                adder[1][2]++;
        }
        else if (a[i] == 'T')
        {
            A.pb(2);
            abc[2]--;
            if (b[i] == 'A')
                adder[2][0]++;
            if (b[i] == 'C')
                adder[2][1]++;
        }
        pref_tbl.pb(adder);
    }
    // cerr << "C\n";
    if (abc[0] != 0 || abc[1] != 0 || abc[2] != 0)
        gc = false;
}

int get_distance(int x, int y)
{
    // cerr << "D\n";

    if (!gc)
        return -1;

    // cpp_dump(pref_tbl);

    int ans = 0;

    pref curr = pref_tbl[y + 1];
    // cerr << "D'\n";

    curr[0][1] -= pref_tbl[x][0][1];
    curr[0][2] -= pref_tbl[x][0][2];
    // cerr << "D''\n";

    curr[1][0] -= pref_tbl[x][1][0];
    curr[1][2] -= pref_tbl[x][1][2];
    // cerr << "D'''\n";

    curr[2][0] -= pref_tbl[x][2][0];
    curr[2][1] -= pref_tbl[x][2][1];

    // cerr << "E\n";
    for (int i = x; i <= y; i++)
    {
        // cerr << "F\n";

        // cpp_dump(curr);
        // cpp_dump(i, A[i], B[i]);
        // cpp_dump(curr[A[i]][B[i]], curr[B[i]][A[i]]);

        if (A[i] == B[i])
            continue;

        if (curr[A[i]][B[i]] == 0 && curr[B[i]][A[i]] == 0) // oba już zamienione
            continue;

        if (curr[A[i]][B[i]] > 0 && curr[B[i]][A[i]] > 0) // oba możemy zamienić miejscami
        {
            ans++;
            curr[A[i]][B[i]]--;
            curr[B[i]][A[i]]--;
            continue;
        }

        int trzeci;
        if (A[i] != 0 && B[i] != 0)
            trzeci = 0;
        else if (A[i] != 1 && B[i] != 1)
            trzeci = 1;
        else if (A[i] != 2 && B[i] != 2)
            trzeci = 2;

        if (curr[A[i]][B[i]] > 0) // A na B ale nie B na A
        {
            curr[A[i]][trzeci]++;
            curr[A[i]][B[i]]--;
            curr[B[i]][trzeci]--;
            ans++;
            continue;
        }
        else if (curr[A[i]][B[i]] > 0) // A na B ale nie B na A
        {
            curr[B[i]][trzeci]++;
            curr[B[i]][A[i]]--;
            curr[A[i]][trzeci]--;
            ans++;
            continue;
        }
        else
            cerr << "error0\n";
    }
    // cerr << "G\n";
    return ans;
}

Compilation message (stderr)

dna.cpp:11:1: error: 'vector' does not name a type
   11 | vector<int> A, B;
      | ^~~~~~
dna.cpp:13:16: error: 'array' was not declared in this scope
   13 | typedef vector<array<int, 3>> pref;
      |                ^~~~~
dna.cpp:1:1: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
  +++ |+#include <array>
    1 | #define pb push_back
dna.cpp:13:16: error: 'array' was not declared in this scope
   13 | typedef vector<array<int, 3>> pref;
      |                ^~~~~
dna.cpp:13:16: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
dna.cpp:13:16: error: 'array' was not declared in this scope
dna.cpp:13:16: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
dna.cpp:13:16: error: 'array' was not declared in this scope
dna.cpp:13:16: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
dna.cpp:13:16: error: 'array' was not declared in this scope
dna.cpp:13:16: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
dna.cpp:13:16: error: 'array' was not declared in this scope
dna.cpp:13:16: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
dna.cpp:13:9: error: 'vector' does not name a type
   13 | typedef vector<array<int, 3>> pref;
      |         ^~~~~~
dna.cpp:15:8: error: 'pref' was not declared in this scope
   15 | vector<pref> pref_tbl;
      |        ^~~~
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:8: error: 'pref' was not declared in this scope
dna.cpp:15:1: error: 'vector' does not name a type
   15 | vector<pref> pref_tbl;
      | ^~~~~~
dna.cpp:17:6: error: variable or field 'init' declared void
   17 | void init(string a, string b)
      |      ^~~~
dna.cpp:17:11: error: 'string' was not declared in this scope
   17 | void init(string a, string b)
      |           ^~~~~~
dna.cpp:1:1: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'?
  +++ |+#include <string>
    1 | #define pb push_back
dna.cpp:17:21: error: 'string' was not declared in this scope
   17 | void init(string a, string b)
      |                     ^~~~~~
dna.cpp:17:21: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'?
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:100:5: error: 'pref' was not declared in this scope
  100 |     pref curr = pref_tbl[y + 1];
      |     ^~~~
dna.cpp:103:5: error: 'curr' was not declared in this scope
  103 |     curr[0][1] -= pref_tbl[x][0][1];
      |     ^~~~
dna.cpp:103:19: error: 'pref_tbl' was not declared in this scope
  103 |     curr[0][1] -= pref_tbl[x][0][1];
      |                   ^~~~~~~~
dna.cpp:123:13: error: 'A' was not declared in this scope
  123 |         if (A[i] == B[i])
      |             ^
dna.cpp:123:21: error: 'B' was not declared in this scope
  123 |         if (A[i] == B[i])
      |                     ^
dna.cpp:126:18: error: 'A' was not declared in this scope
  126 |         if (curr[A[i]][B[i]] == 0 && curr[B[i]][A[i]] == 0) // oba już zamienione
      |                  ^
dna.cpp:126:24: error: 'B' was not declared in this scope
  126 |         if (curr[A[i]][B[i]] == 0 && curr[B[i]][A[i]] == 0) // oba już zamienione
      |                        ^
dna.cpp:129:18: error: 'A' was not declared in this scope
  129 |         if (curr[A[i]][B[i]] > 0 && curr[B[i]][A[i]] > 0) // oba możemy zamienić miejscami
      |                  ^
dna.cpp:129:24: error: 'B' was not declared in this scope
  129 |         if (curr[A[i]][B[i]] > 0 && curr[B[i]][A[i]] > 0) // oba możemy zamienić miejscami
      |                        ^
dna.cpp:138:13: error: 'A' was not declared in this scope
  138 |         if (A[i] != 0 && B[i] != 0)
      |             ^
dna.cpp:138:26: error: 'B' was not declared in this scope
  138 |         if (A[i] != 0 && B[i] != 0)
      |                          ^
dna.cpp:145:18: error: 'A' was not declared in this scope
  145 |         if (curr[A[i]][B[i]] > 0) // A na B ale nie B na A
      |                  ^
dna.cpp:145:24: error: 'B' was not declared in this scope
  145 |         if (curr[A[i]][B[i]] > 0) // A na B ale nie B na A
      |                        ^
dna.cpp:162:13: error: 'cerr' was not declared in this scope
  162 |             cerr << "error0\n";
      |             ^~~~
dna.cpp:1:1: note: 'std::cerr' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
  +++ |+#include <iostream>
    1 | #define pb push_back