Submission #706492

#TimeUsernameProblemLanguageResultExecution timeMemory
706492SamNguyenLanguages (IOI10_languages)C++14
57 / 100
215 ms14860 KiB
#include <stdlib.h>
#include <stdio.h>

#include "grader.h"
#include "lang.h"

#include <bits/stdc++.h>
using namespace std;

template <class T1, class T2>
inline bool maximise(T1 &x, T2 y) {
	if (x < y) { x = y; return true; }
	return false;
}

const int LEN = 100;
const int NUM_LANG = 56;
const int NUM_CHAR = 65356;

bool IS_FIRST_RUN = true;
int sum[NUM_CHAR], freq[NUM_LANG][NUM_CHAR];
double rate[NUM_LANG];

void excerpt(int *txt) {
	if (IS_FIRST_RUN) {
		memset(sum, 0, sizeof sum);
		memset(freq, 0, sizeof freq);
		IS_FIRST_RUN = false;
	}

	for (int x = 0; x < NUM_LANG; x++)
		rate[x] = 1.0;

	for (int i = 0; i < LEN; i++) 
		for (int x = 0; x < NUM_LANG; x++) if (sum[txt[i]] > 0) 
			rate[x] *= 1.0L * freq[x][txt[i]] / sum[txt[i]];

	double best_rate = -1.0;
	int lang = -1;
	for (int x = 0; x < NUM_LANG; x++)
		if (maximise(best_rate, rate[x]))
			lang = x;

	int ans = language(lang);
	for (int i = 0; i < LEN; i++) {
		freq[ans][txt[i]]++;
		sum[txt[i]]++;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...