Submission #1103112

#TimeUsernameProblemLanguageResultExecution timeMemory
1103112agrim_09Mutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define py cout << "YES" << endl;
#define pn cout << "NO" << endl;
#define pb push_back
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 2e5;
vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
 
// Check for queue, priorioty_queue, stack, ordered_set solutions
// stack => LIFO (whatever goes in last comes out last)
// queue => FIFO (whatever goes in first comes out first)
// priority_queue => Dynamic queries of minimum/maximum
// ordered_set => set in vector form
//[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element]
 
// To comment multiple lines : ctrl + /
// To find and replace : ctrl+H
 
int val(char a, char b){
    if(a==b){
        return -1;
    }
    if(a=='1'){
       return (b-'2');
    }
    if(a=='2'){
        if(b=='1'){
            return 2;
        }
        return 3;
    }
    if(a=='3'){
        if(b=='1'){
            return 4;
        }
        return 5;
    }
    return -1;
}
int n; vector<vector<int>>cnt; string s1, s2;

void init(string p, string q){
    s1 = p, s2 = q;
    n = s1.size(); vector<int>temp(6,0);
    for(int i = 0;i<n;i++){
        cnt.pb(temp);
    }

    int tmp = val(s1[0],s2[0]);
    if(tmp!=-1){
        cnt[0][val(s1[0],s2[0])] = 1;
    }
 
    for(int i = 1;i<n;i++){
        for(int j = 0;j<6;j++){
            cnt[i][j] = cnt[i-1][j];
        }
        int tmp = val(s1[i],s2[i]);
        if(tmp!=-1){
            cnt[i][val(s1[i],s2[i])]++;
        }
    }
}

int get_distance(int l, int r){
    int x1 = cnt[r][0], x2 = cnt[r][1], y1 = cnt[r][2], y2 = cnt[r][3];
    int z1 = cnt[r][4], z2 = cnt[r][5];

    if(l>0){
        x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
        z1 -= cnt[l-1][4], z2 -= cnt[l-1][5]; 
    }

    int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
    set<int>front; set<int>end;

    int r1 = abs(x1-y1), r2 =abs(x2-z1), r3 = abs(y2-z2);

    if(x1>y1){
        front.insert(1); end.insert(2); 
    }
    if(y1>x1){
        front.insert(2); end.insert(1);
    }
    if(x2>z1){
        front.insert(1); end.insert(3);
    }
    if(z1>x2){
        front.insert(3); end.insert(1); 
    }
    if(y2>z2){
        front.insert(2); end.insert(3); 
    }
    if(z2>y2){
        front.insert(3); end.insert(2); 
    }

    bool yes = (front==end and r1==r2 and r2==r3);
    if(yes){
        return ans + 2*r1;
    }
    else{
        return -1;
    }
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cch1jRAX.o: in function `main':
grader.cpp:(.text.startup+0x39d): undefined reference to `get_distance(int, int)'
collect2: error: ld returned 1 exit status