Submission #1303252

#TimeUsernameProblemLanguageResultExecution timeMemory
1303252ansonkhcLanguages (IOI10_languages)C++20
47 / 100
5564 ms10040 KiB
#include "grader.h" #include "lang.h" #include <vector> #include <map> #include <cmath> using namespace std; #define MAX_LANG 56 #define MAX_SYMB 65536 // We store the frequency of n-grams for each language. // To save memory, we use maps or small arrays for higher n-grams. // For this optimized version, we focus on 1-grams and 2-grams for speed/memory. double cnt[MAX_LANG][MAX_SYMB]; map<pair<int, int>, int> bigrams[MAX_LANG]; void excerpt(int *E) { double best_score = -1.0; int best_lang = 0; for (int l = 0; l < MAX_LANG; l++) { double score = 0; // 1-gram scoring for (int i = 0; i < 100; i++) { score += cnt[l][E[i]]; } // 2-gram scoring (Higher weight usually yields better accuracy) for (int i = 0; i < 99; i++) { if (bigrams[l].count({E[i], E[i+1]})) { score += bigrams[l][{E[i], E[i+1]}] * 5.0; } } if (score > best_score) { best_score = score; best_lang = l; } } // Guess the language and get the actual answer int actual = language(best_lang); // Update our statistical model with the correct answer for (int i = 0; i < 100; i++) { cnt[actual][E[i]]++; } for (int i = 0; i < 99; i++) { bigrams[actual][{E[i], E[i+1]}]++; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...