ANSLEAK approach

@koulick424
hey, my approach was the same but it gave me only 37 points.
Can you tell me the exact difference between your approach and my approach.
Here is my code: CodeChef: Practical coding for everyone

The approach that I used was to keep track of the exams with the lower score, and for those choose the answer that appeared the more. I then updated the exams with lower score and repeated for every question. This approach got me about 90 points.

I also use the gready approach of choosing the “best” option possible for exams with low scores, but not for the lowest one, but for the k-th lowest, where k is a variable number from some initial value at the beginning to 1 near the end. That showed to be a decent approach until ACRush came into scene.

But I think this would give non AC verdict after rejudging

You don’t reset mval between each question.

Can you please explain why does it work ?

Well I printed answer randomly for each row using rand() function in c++. Got 81 XD .

2 Likes

Some users ansleak submission have been evaluated and this approach has yeild only 25 pts though.

1 Like

I had used random function which give me 75 points

1 Like

Has your submission be rejudged??

Are bhai bhai bhai … humbhi :sweat_smile:

I wasn’t able to implement my approach during the contest, but my approach was to find out the most frequent element in the array of answers for each question. If there were multiple most frequent elements in the array, then, if the array is a[n][k], then I would first make an array b[n] and for every i, b[i]=a[i][i%k], and then i’ll push back this b[i], for the i’th element in my answer vector, else I will push back the most frequent element from the array. Here is my code. Could someone please help me with what is actually wrong in it ?

#include <iomanip>
#include <algorithm>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
#include <chrono>
#include <cstdlib>
#include <cstdio>
#include <cstring>

typedef long long int ll;
#define test ll t; cin >> t; while(t--)
#define MOD pow(10,9)+7
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define print(x) cout << x << endl;
#define take(x) cin >> x;
#define forn(i,n) for(ll i=0;i<n;i++)


int main (){
  test {
    ll n,m,k;
    cin >> n >> m >> k;
    ll a[n][k];
    vector<ll>v1[n];
    forn(i,n){
      forn(j,k){
        cin >> a[i][j];
        v1[i].push_back(a[i][j]);
      }
    }
    vector<ll>v2;
    unordered_map<ll, ll> mp; 
    forn(i,n){ 
      forn(j,v1[i].size()){
        mp[v1[i][j]]++;  
      }
    }
    ll max=0;
    ll ans[n]={0};
    forn(i,n){
      forn(j,v1[i].size()){ 
        if(mp[v1[i][j]] != -1){ 
          if(mp[v1[i][j]]>max){
             max=mp[v1[i][j]];
             ans[i]=j;
          }
        } 
      }
    }
    forn(i,n){
      ll count=0;
      forn(j,v1[i].size()){
        if(mp[v1[i][j]]==max){
          count ++;
        }
      }
      if(count>=2){
        v2.push_back(v1[i][i%k]);
      }
      else {
        v2.push_back(v1[i][ans[i]]);
      }
    }
    forn(i,n){
      cout << v2[i] << " ";
    }
    cout << endl;
  }
}

@galencolin i am doing mval[i]=0 after processing it.

:grinning:

ha ab 74 hogaya

Below is the among the only solutions that got 100 points in the contest for ANSLEAK and it is 255 lines long!!

https://www.codechef.com/viewsolution/31839489

didn’t it throw NZEC error cause you did not use try-catch block even though the main function has throw Exception keyword??

1 Like

@adityxraj My code works.As I’m not accessing any negative indexes or any out of array memory,I don’t actually need try catch blocks.So my code doesn’t require them.But if you want to be on safer side you can use them.

1 Like

I did the same but think about a test case which has 4 answer sheets as follows:-
3 3 3 1
3 3 3 1
3 3 3 1
3 3 3 1
your program will give a output :- 3 3 3 3 (max possible worst score will be 0)
but the more appropriate answer for this will be :- 3 1 3 1(max possible worst score will be 2)

so the approach i followed is :-
step1: for the row which are having same element put it as it is in the answer
step2:for the remaining find the column which has min score and add its element in the ans
eg:-
4 4 4 4
1 2 3 4
2 2 3 4
1 2 1 2
After step 1:-
ans[]={4,0,0,0}
score={1,1,1,1}
Step2:-1:
1)
ans[]={4,1,0,0}
score={2,1,1,1}
2)
ans[]={4,1,2,0}
score[]={3,2,1,1}
3)
ans[]={4,1,2,1}
score[]={3,2,2,1}

I scored decent points using a fairly simple algorithm. Assume you have chosen answers for first x questions. Then we greedily find the best answer to the (x+1)th question by increasing the minimum over all forms and if the minimum was same for 2 or more answers then we take the choice where there were least number of minimums.
I would love to explain more if anyone is interested.

1 Like