2022 December Bronze 3. Reverse Engineering

Problem Info

2022 December Bronze 3. Reverse Engineering
Link

Question

Include a specific question if you have one.

What I’ve Tried

Passes cases 1-5 and fails the rest. I downloaded case 6 and output LIE for every case when the intended solution should only have the first three cases as LIE

My Work

#include <bits/stdc++.h>

using namespace std;

int all[120][120];
int main()
{
    int t;
    cin >> t;
    for (int tt=0  ; tt<t ; tt++)
    {
        memset(all,0,sizeof(all));
        int n,m;
        cin >> n >> m;
        set<string> id;
        map<string,int> val;
        int inok=1;

        for (int mm=0 ; mm<m ; mm++)
        {
            string seq;
            int state;
            cin >> seq >> state;
            if (id.count(seq)>0 && val[seq]!=state) {cout << "LIE\n"; inok=0;}
            id.insert(seq);
            val[seq] = state;

            for (int i=0 ; i<n ; i++) all[mm][i] = int(seq[i]-'0');
            all[mm][n] = state;
        }
        if (!inok) continue;

        int allok=0;
        for (int i=0 ; i<n ; i++)
        {
            for (int j=0 ; j<n ; j++)
            {
                for (int ii : {0,1})
                    {
                        for (int jj : {0,1})
                            {
                                int a=-1, b=-1, c=-1, ok=1;
                                for (int k=0 ; k<m ; k++)
                                {
                                    int curstat = all[k][n];
                                    if (all[k][i]==ii)
                                    {
                                        if (a==-1) a=curstat;
                                        else if (a != curstat) ok=0;
                                    }
                                    else if (all[k][j]==jj)
                                    {
                                        if (b==-1) b=curstat;
                                        else if (b != curstat) ok=0;

                                    }
                                    else
                                    {
                                        if (c==-1) c=curstat;
                                        else if(c != curstat) ok=0;
                                    }
                                }

                                if (ok) {cout<<"OK\n"; allok=1; break;}

                            }
                            if (allok) break;
                    }
                    if(allok) break;
            }
            if (allok) break;
        }

        if (!allok) cout << "LIE\n";


    }
    return 0;
}

The first part gets input, the set and map are used to detect conflicting input cases. The second part brute forces and tries to see if any combination of indices will suffice the conditions.

1 Like