Submission #235432

#TimeUsernameProblemLanguageResultExecution timeMemory
235432dolphingarlicLanguages (IOI10_languages)C++14
0 / 100
10088 ms178128 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; #include "grader.h" // #include "lang.h" const int SZ = 100, LANGS = 56; const float LETTER_WEIGHT = 1, BIGRAM_WEIGHT = 2, TRIGRAM_WEIGHT = 3; unordered_map<ll, float> prev_letters[LANGS], prev_bigrams[LANGS], prev_trigrams[LANGS]; int prev_cnt[LANGS]; void excerpt(int *E) { unordered_map<ll, float> curr_letters, curr_bigrams, curr_trigrams; FOR(i, 0, SZ) { curr_letters[E[i]]++; if (i) curr_bigrams[(E[i - 1] << 15) + E[i]]++; if (i > 1) curr_trigrams[(E[i - 2] << 31) + (E[i - 1] << 15) + E[i]]++; } int best_lang = 0; float best_diff = 1e18; FOR(i, 0, LANGS) if (prev_cnt[i]) { float curr_diff = 0; for (pair<ll, float> j : curr_letters) { curr_diff += LETTER_WEIGHT * abs(j.second - (prev_letters[i][j.first] / prev_cnt[i])); } for (pair<ll, float> j : curr_bigrams) { curr_diff += BIGRAM_WEIGHT * abs(j.second - (prev_bigrams[i][j.first] / prev_cnt[i])); } for (pair<ll, float> j : curr_trigrams) { curr_diff += TRIGRAM_WEIGHT * abs(j.second - (prev_trigrams[i][j.first] / prev_cnt[i])); } if (curr_diff < best_diff) { best_diff = curr_diff; best_lang = i; } } int correct = language(best_lang); prev_cnt[correct]++; for (pair<ll, float> i : curr_letters) { prev_letters[correct][i.first] += i.second; } for (pair<ll, float> i : curr_bigrams) { prev_bigrams[correct][i.first] += i.second; } for (pair<ll, float> i : curr_trigrams) { prev_trigrams[correct][i.first] += i.second; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...