Skip to content

Instantly share code, notes, and snippets.

@kusano
Created March 28, 2021 01:48
Show Gist options
  • Save kusano/499ab3f0629f5f2e576304ee926bd631 to your computer and use it in GitHub Desktop.
Save kusano/499ab3f0629f5f2e576304ee926bd631 to your computer and use it in GitHub Desktop.
Google Code Jam Qualification Round 2021 Cheating Detection
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
double f(double x)
{
return 1/(1+exp(-x));
}
double F(double x)
{
return -log(1-f(x));
}
double skill(double p)
{
double l = -3.;
double r = 3.;
for (int i=0; i<100; i++)
{
double m = (l+r)*.5;
// (1/6)∫[-3<=x<=3](f(m-x))
// = (1/6)(-F(m-x)[-3<=x<=3])
// = (1/6)(-F(m-3)+F(m+3))
((-F(m-3)+F(m+3))/6<p ? l : r) = m;
}
return l;
}
int main()
{
int T;
cin>>T;
int P;
cin>>P;
for (int t=1; t<=T; t++)
{
vector<vector<int>> A(100, vector<int>(10000));
for (int i=0; i<100; i++)
{
string s;
cin>>s;
for (int j=0; j<10000; j++)
A[i][j] = s[j]-'0';
}
vector<double> S(100);
for (int i=0; i<100; i++)
{
int s = 0;
for (int j=0; j<10000; j++)
s += A[i][j];
S[i] = skill(s/10000.);
}
vector<double> Q(10000);
for (int i=0; i<10000; i++)
{
int s = 0;
for (int j=0; j<100; j++)
s += A[j][i];
Q[i] = -skill(s/100.);
}
vector<double> X(100);
for (int i=0; i<100; i++)
{
for (int j=0; j<10000; j++)
if (A[i][j]==0)
X[i] += -log(1-f(S[i]-Q[j]));
else
X[i] += -log(f(S[i]-Q[j]));
int s = 0;
for (int j=0; j<10000; j++)
s += A[i][j];
double p = s/10000.;
X[i] = X[i]/10000 - (-p*log(p)-(1-p)*log(1-p));
}
int ans = 0;
for (int i=1; i<100; i++)
if (X[i]>X[ans])
ans = i;
ans++;
cout<<"Case #"<<t<<": "<<ans<<endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment