답안 #1011552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011552 2024-06-30T15:16:45 Z Double_Slash Languages (IOI10_languages) C++17
60 / 100
10000 ms 9052 KB
#pragma GCC optimize("O3,unroll-all-loops,inline")
#pragma GCC target("avx2")
#include "lang.h"
#include "grader.h"
#include <bits/extc++.h>
 
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pint = pair<int, int>;
 
double magic(double x) {
	return abs(x);
}
 
template <typename T, class Hash, int MAX>
struct Data {
	int tot = 0;
    unordered_map<T, int, Hash> m;
    set<pair<int, T>> inv;
 
	double operator&(const Data<T, Hash, MAX> &o) const {
		double ret = 0;
		for (auto [k, v]: m) {
			ret += magic((double) v / tot - (o.m.find(k) != m.end() ? (double) o.m.find(k)->second / o.tot : 0));
		}
		for (auto [k, v]: o.m) {
			if (m.find(k) == m.end()) ret += magic((double) v / o.tot);
		}
		return ret;
	}
 
	void operator+=(const Data<T, Hash, MAX> &o) {
		for (auto &[k, v]: o.m) {
          inv.erase({m[k], k});
			inv.emplace(m[k] += v, k);
		}
		tot += o.tot;
      while (inv.size() > MAX) {
          tot -= inv.begin()->first;
          m.erase(inv.begin()->second);
        inv.erase(inv.begin());
}
	}};
 
struct hash1 {
    int operator()(const int x) const {
        return ((long long)x) * 327821 % 1000000007;
    }
};
struct hash2 {
ll operator() (const pint &x) const { return ((x.first) * 37) ^ ((x.second) * 73); }
};
struct hash3 {
ll operator()(const array<int, 3> &x) const { return (x[0] * 37) ^ (x[1] * 73) ^ (x[2] * 409); }
};
struct hash4 {
ll operator()(const array<int, 4> &x) const { return (x[0] * 37) ^ (x[1] * 73) ^ (x[2] * 409) ^ (x[3] * 859); }
};
struct hash5 {
ll operator()(const array<int, 5> &x) const { return (x[0] * 37) ^ (x[1] * 73) ^ (x[2] * 409) ^ (x[3] * 859) ^ (x[4] * 797); }
};
 
struct Profile {
Data<int, hash1, 50> sing;
  Data<pint, hash2, 100> doub;
  Data<array<int, 3>, hash3, 140> trip;
  Data<array<int, 4>, hash4, 100> quad;
  Data<array<int, 5>, hash5, 100> quint;
 
	Profile() {}
 
	Profile(int *arr) {
		for (int i = 0; i < 100; ++i) {
          sing.m[arr[i]]++;
          if (i) doub.m[{arr[i - 1], arr[i]}]++;
          if (i >=2) trip.m[{arr[i - 2], arr[i - 1], arr[i]}];
          if (i >= 3) quad.m[{arr[i - 3], arr[i - 2], arr[i - 1], arr[i]}];
          if (i >= 4) quint.m[{arr[i - 4], arr[i - 3], arr[i - 2], arr[i - 1], arr[i]}];
		}
      for (auto [k, v]: sing.m) sing.inv.emplace(v, k);
      for (auto [k, v]: doub.m) doub.inv.emplace(v, k);
            for (auto [k, v]: trip.m) trip.inv.emplace(v, k);
for (auto [k, v]: quad.m) quad.inv.emplace(v, k);
for (auto [k, v]: quint.m) quint.inv.emplace(v, k);
      
      sing.tot = 100;
      doub.tot = 99;
      trip.tot = 98;
      quad.tot = 97;
      quint.tot = 96;
	}
 
	double operator&(const Profile &o) const {
		return (sing & o.sing) + (doub & o.doub) + (trip & o.trip) + (quad & o.quad) + (quint & o.quint);
	}
 
	void operator+=(const Profile &o) {
      sing += o.sing;
doub += o.doub;
      trip += o.trip;
      quad += o.quad;
      quint += o.quint;
	}
} profile[56];
 
void excerpt(int *E) {
	Profile p(E);
	pair<double, int> mn{1e18, 0};
	for (int i = 0; i < 56; ++i) {
		mn = min(mn, {p & profile[i], i});
	}
	int ans = language(mn.second);
	profile[ans] += p;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10070 ms 8844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9834 ms 9052 KB Output is partially correct - 82.70%