Submission #1103113

#TimeUsernameProblemLanguageResultExecution timeMemory
1103113agrim_09Mutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include "dna.h"
 
// 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)

dna.cpp:34:8: error: 'vector' does not name a type
   34 | int n; vector<vector<int>>cnt; string s1, s2;
      |        ^~~~~~
dna.cpp:34:32: error: 'string' does not name a type; did you mean 'stdin'?
   34 | int n; vector<vector<int>>cnt; string s1, s2;
      |                                ^~~~~~
      |                                stdin
dna.cpp:36:6: error: variable or field 'init' declared void
   36 | void init(string p, string q){
      |      ^~~~
dna.cpp:36:11: error: 'string' was not declared in this scope
   36 | void init(string p, string q){
      |           ^~~~~~
dna.cpp:36:11: note: suggested alternatives:
In file included from /usr/include/c++/10/string:39,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
dna.cpp:36:21: error: 'string' was not declared in this scope
   36 | void init(string p, string q){
      |                     ^~~~~~
dna.cpp:36:21: note: suggested alternatives:
In file included from /usr/include/c++/10/string:39,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:60:14: error: 'cnt' was not declared in this scope; did you mean 'int'?
   60 |     int x1 = cnt[r][0], x2 = cnt[r][1], y1 = cnt[r][2], y2 = cnt[r][3];
      |              ^~~
      |              int
dna.cpp:64:28: error: 'x2' was not declared in this scope; did you mean 'x1'?
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                            ^~
      |                            x1
dna.cpp:64:47: error: 'y1' was not declared in this scope; did you mean 'z1'?
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                                               ^~
      |                                               z1
dna.cpp:64:66: error: 'y2' was not declared in this scope
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                                                                  ^~
dna.cpp:65:28: error: 'z2' was not declared in this scope; did you mean 'z1'?
   65 |         z1 -= cnt[l-1][4], z2 -= cnt[l-1][5];
      |                            ^~
      |                            z1
dna.cpp:68:22: error: 'y1' was not declared in this scope; did you mean 'z1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                      ^~
      |                      z1
dna.cpp:68:15: error: 'min' was not declared in this scope; did you mean 'std::min'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |               ^~~
      |               std::min
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/string:40,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: 'std::min' declared here
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
dna.cpp:68:32: error: 'x2' was not declared in this scope; did you mean 'x1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                ^~
      |                                x1
dna.cpp:68:45: error: 'y2' was not declared in this scope
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                             ^~
dna.cpp:68:48: error: 'z2' was not declared in this scope; did you mean 'z1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                                ^~
      |                                                z1
dna.cpp:69:5: error: 'set' was not declared in this scope
   69 |     set<int>front; set<int>end;
      |     ^~~
dna.cpp:69:9: error: expected primary-expression before 'int'
   69 |     set<int>front; set<int>end;
      |         ^~~
dna.cpp:69:24: error: expected primary-expression before 'int'
   69 |     set<int>front; set<int>end;
      |                        ^~~
dna.cpp:74:9: error: 'front' was not declared in this scope
   74 |         front.insert(1); end.insert(2);
      |         ^~~~~
dna.cpp:74:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   74 |         front.insert(1); end.insert(2);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:77:9: error: 'front' was not declared in this scope
   77 |         front.insert(2); end.insert(1);
      |         ^~~~~
dna.cpp:77:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   77 |         front.insert(2); end.insert(1);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:80:9: error: 'front' was not declared in this scope
   80 |         front.insert(1); end.insert(3);
      |         ^~~~~
dna.cpp:80:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   80 |         front.insert(1); end.insert(3);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:83:9: error: 'front' was not declared in this scope
   83 |         front.insert(3); end.insert(1);
      |         ^~~~~
dna.cpp:83:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   83 |         front.insert(3); end.insert(1);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:86:9: error: 'front' was not declared in this scope
   86 |         front.insert(2); end.insert(3);
      |         ^~~~~
dna.cpp:86:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   86 |         front.insert(2); end.insert(3);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:89:9: error: 'front' was not declared in this scope
   89 |         front.insert(3); end.insert(2);
      |         ^~~~~
dna.cpp:89:26: error: 'end' was not declared in this scope; did you mean 'std::end'?
   89 |         front.insert(3); end.insert(2);
      |                          ^~~
      |                          std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:92:17: error: 'front' was not declared in this scope
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                 ^~~~~
dna.cpp:92:24: error: 'end' was not declared in this scope; did you mean 'std::end'?
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                        ^~~
      |                        std::end
In file included from /usr/include/c++/10/string:54,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
dna.cpp:92:36: error: 'r2' was not declared in this scope; did you mean 'r1'?
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                                    ^~
      |                                    r1
dna.cpp:92:47: error: 'r3' was not declared in this scope; did you mean 'r1'?
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                                               ^~
      |                                               r1