#include <bits/stdc++.h>
#include "grader.h"
#include "lang.h"
#define SZ 100
#define PI 3.141592653
using namespace std;
int currLang = 0;
struct library {
unordered_map<unsigned long long int, int> trigramCount, prefBigramCount;
bool learnt;
inline library() {
learnt = 0;
}
inline int compareLang(int *excerpt) {
if(learnt) {
double ret = 0.000000;
for(int i = 0; i < 100; i++) {
pair<int, int> ex = make_pair(i < 2 ? 0 : excerpt[i - 2], i < 1 ? 0 : excerpt[i - 1]);
unsigned long long int index = ex.first * 10000000000 + ex.second * 100000 + excerpt[i];
unsigned long long int prefIndex = ex.first * 100000 + ex.second;
if(trigramCount.find(index) != trigramCount.end()) {
double prob = (double)trigramCount[index] / (double)prefBigramCount[prefIndex];
ret += abs(79.000000 * log10(sin(PI*prob/2.000000)));
} else
ret += 100.000000;
}
return ret;
} else
return 999999.000000;
}
inline void learnLang(int *excerpt) {
learnt = 1;
for(int i = 0; i < 100; i++) {
pair<int, int> ex = make_pair(i < 2 ? 0 : excerpt[i - 2], i < 1 ? 0 : excerpt[i - 1]);
unsigned long long int index = ex.first * 10000000000 + ex.second * 100000 + excerpt[i];
unsigned long long int prefIndex = ex.first * 100000 + ex.second;
if(!trigramCount.count(index)) {
if(!prefBigramCount.count(prefIndex)) {
prefBigramCount[prefIndex] = 1;
} else
prefBigramCount[prefIndex]++;
trigramCount[index] = 1;
} else {
prefBigramCount[prefIndex]++;
trigramCount[index]++;
}
}
}
} database[56];
void excerpt(int *E) {
int response, answer;
double minCheckScore = 999999.000000;
double checkScore[56];
for(int j = 0; j < 56; j++) {
checkScore[j] = database[j].compareLang(E);
if(checkScore[j] < minCheckScore) {
minCheckScore = checkScore[j];
response = j;
}
}
if(minCheckScore >= 9250.000000 && currLang < 56)
response = currLang;
answer = language(response);
if(answer == currLang)
currLang += (currLang < 56) ? 1 : 0;
database[answer].learnLang(E);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |