제출 #715986

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

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;



struct cus
{
    int AT = 0, AC = 0, TC = 0;
    int ans = 0;
};

struct SegTree
{
    int size;
    vector<cus> tree;

    void init(int n)
    {
        size = 1;

        while (size < n) size *= 2;

        tree.resize(2*size);
    }

    void build(int l, int r, int x, string &a, string &b)
    {
        if (l + 1 == r)
        {
            if (l >= a.length()) return;

            if (a[l] == 'A' && b[l] == 'T')
            {
                if (tree[x].AT < 0) tree[x].ans++;

                tree[x].AT++;
            }
            else if (a[l] == 'T' && b[l] == 'A')
            {
                if (tree[x].AT > 0) tree[x].ans++;

                tree[x].AT--;
            }
            else if (a[l] == 'T' && b[l] == 'C')
            {
                if (tree[x].TC < 0) tree[x].ans++;

                tree[x].TC++;
            }
            else if (a[l] == 'C' && b[l] == 'T')
            {
                if (tree[x].TC > 0) tree[x].ans++;

                tree[x].TC--;
            }
            else if (a[l] == 'A' && b[l] == 'C')
            {
                if (tree[x].AC < 0) tree[x].ans++;

                tree[x].AC++;
            }
            else if (a[l] == 'C' && b[l] == 'A')
            {
                if (tree[x].AC > 0) tree[x].ans++;

                tree[x].AC--;
            }

            return;
        }

        int mid = (l + r) >> 1;

        build(l, mid, 2*x+1, a, b);
        build(mid, r, 2*x+2, a, b);

        tree[x].ans += min(abs(tree[2*x+1].AC), abs(tree[2*x+2].AC));
        tree[x].ans += min(abs(tree[2*x+1].AT), abs(tree[2*x+2].AT));
        tree[x].ans += min(abs(tree[2*x+1].TC), abs(tree[2*x+2].TC));
        tree[x].AC = tree[2*x+1].AC + tree[2*x+2].AC;
        tree[x].AT = tree[2*x+1].AT + tree[2*x+2].AT;
        tree[x].TC = tree[2*x+1].TC + tree[2*x+2].TC;
    }

    void build(string &a, string &b)
    {
        build(0, size, 0, a, b);
    }

    cus get(int lx, int rx, int l, int r, int x)
    {
        if (l >= lx && r <= rx)
        {
            return tree[x];
        }
        if (l >= rx || r <= lx)
        {
            cus temp;
            return temp;
        }

        int mid = (l + r) >> 1;

        cus a = get(lx, rx, l, mid, 2*x+1);
        cus b = get(lx, rx, mid, r, 2*x+2);

        a.ans += min(abs(a.AC), abs(b.AC));
        a.ans += min(abs(a.AT), abs(b.AT));
        a.ans += min(abs(a.TC), abs(b.TC));
        a.AC += b.AC;
        a.AT += b.AT;
        a.TC += b.TC;

        return a;
    }

    int get(int l, int r)
    {
        cus s = get(l, r + 1, 0, size, 0);

        if (s.AT + s.AC != 0) return -1;
        if (s.AT - s.TC != 0) return -1;
        if (s.AC + s.TC != 0) return -1;

        s.AT = abs(s.AT);
        s.AC = abs(s.AC);
        s.TC = abs(s.TC);

        return min({s.AT + s.AC, s.AC + s.TC});
    }
};
string a, b;
SegTree st;

void init(string t1, string t2)
{
    st.init(t1.length());
    st.build(t1, t2);
}

int get_distance(int x, int y)
{
    return st.get(x, y);
}

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

dna.cpp: In member function 'void SegTree::build(int, int, int, std::string&, std::string&)':
dna.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (l >= a.length()) return;
      |                 ~~^~~~~~~~~~~~~
#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...