이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdlib.h>
#include <stdio.h>
#include "grader.h"
#include "lang.h"
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
template <class T1, class T2>
inline bool maximise(T1 &x, T2 y) {
if (x < y) { x = y; return true; }
return false;
}
template <int DIM>
struct Vector {
private:
ld x[DIM];
public:
Vector() {
for (int i = 0; i < DIM; i++)
x[i] = 0;
}
inline ld& operator [] (int i) {
return x[i];
}
inline ld operator [] (int i) const {
return x[i];
}
Vector operator + (const Vector &oth) const {
Vector res;
for (int i = 0; i < DIM; i++)
res.x[i] = x[i] + oth.x[i];
return res;
}
Vector operator - (const Vector &oth) const {
Vector res;
for (int i = 0; i < DIM; i++)
res.x[i] = x[i] - oth.x[i];
return res;
}
Vector operator * (ld k) const {
Vector res;
for (int i = 0; i < DIM; i++)
res.x[i] = x[i] * k;
return res;
}
inline ld abs() const {
ld res = 0;
for (int i = 0; i < DIM; i++)
res += x[i] * x[i];
return sqrtl(res);
}
inline Vector unify() {
ld len = abs();
if (len == 0)
return *this;
return (*this) * (1.0 / len);
}
};
template <int DIM>
ld dot(const Vector<DIM> &A, const Vector<DIM> &B) {
ld res = 0;
for (int i = 0; i < DIM; i++)
res += A[i] * B[i];
return res;
}
const int LEN = 100;
const int NUM_LANG = 56;
const int NUM_CHAR = 65356;
bool IS_FIRST_RUN = true;
int freq[NUM_LANG][NUM_CHAR];
void excerpt(int *txt) {
if (IS_FIRST_RUN) {
for (int x = 0; x < NUM_LANG; x++)
for (int c = 0; c < NUM_CHAR; c++)
freq[x][c] = 0;
IS_FIRST_RUN = false;
}
Vector<NUM_LANG> vec;
vector<int> chars(txt, txt + LEN);
for (int c : chars) {
Vector<NUM_LANG> delta;
for (int x = 0; x < NUM_LANG; x++)
delta[x] += freq[x][c];
vec = vec + delta.unify();
}
vec = vec.unify();
/*
cout << "vec = ";
for (int x = 0; x < NUM_LANG; x++)
cout << vec[x] << " ";
cout << endl;
*/
ld best = -1e20;
int lang = -1;
for (int x = 0; x < NUM_LANG; x++) {
Vector<NUM_LANG> u;
u[x] = 1;
if (maximise(best, dot(u, vec)))
lang = x;
}
int ans = language(lang);
for (int i = 0; i < LEN; i++) {
freq[ans][txt[i]] += 177;
freq[lang][txt[i]] -= 100;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |