Created
March 28, 2021 01:48
-
-
Save kusano/499ab3f0629f5f2e576304ee926bd631 to your computer and use it in GitHub Desktop.
Google Code Jam Qualification Round 2021 Cheating Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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