답안 #1011436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011436 2024-06-30T13:41:53 Z Double_Slash Languages (IOI10_languages) C++17
컴파일 오류
0 ms 0 KB
#include "lang.h"
#include "grader.h"
#include <bits/stdc++.h>
 
using namespace std;
#define debug(x) [&] { auto _x = x; cerr << __LINE__ << ": " << #x << " = " << _x << endl; return _x; }()
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 / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
		}
		for (auto [k, v]: o) {
			if (not m.contains(k)) ret += magic((double) v / o.tot);
		}
		return ret;
	}
 
	void operator+=(const Data<T, Hash, MAX> &o) {
		for (auto &[k, v]: o) {
          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 hash2 {
ll operator() (const pint &x) { return x.first << 16ll | x.second; }
};
struct hash3 {
ll operator()(const array<int, 3> &x) { return (x[0] << 32ll) | (x[1] << 16ll) | x[2]; }
};
 
struct Profile {
Data<int, hash<int>, 50> sing;
  Data<pint, hash2, 150> doub;
  Data<array<int, 3>, hash3, 55> trip;
 
	Profile() {}
 
	Profile(int *arr) {
		for (int i = 0; i < 100; ++i) {
          sing[arr[i]]++;
          if (i) doub[{arr[i - 1], arr[i]}]++;
          if (i >=2) trip[{arr[i - 2], arr[i - 1], arr[i]}];
		}
      for (auto [k, v]: doub) doub.inv.emplace(v, k);
      sing.tot = 100;
      doub.tot = 99;
      trip.tot = 98;
	}
 
	double operator&(const Profile &o) const {
		return (sing & o.sing) + (doub & o.doub) + (trip & o.trip);
	}
 
	void operator+=(const Profile &o) {
      sing += o.sing;
doub += o.doub;
      trip += o.trip;
	}
} 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;
}

Compilation message

lang.cpp: In member function 'll hash3::operator()(const std::array<int, 3>&)':
lang.cpp:48:54: warning: left shift count >= width of type [-Wshift-count-overflow]
   48 | ll operator()(const array<int, 3> &x) { return (x[0] << 32ll) | (x[1] << 16ll) | x[2]; }
lang.cpp: In constructor 'Profile::Profile(int*)':
lang.cpp:60:15: error: no match for 'operator[]' (operand types are 'Data<int, std::hash<int>, 50>' and 'int')
   60 |           sing[arr[i]]++;
      |               ^
lang.cpp:61:22: error: no match for 'operator[]' (operand types are 'Data<std::pair<int, int>, hash2, 150>' and '<brace-enclosed initializer list>')
   61 |           if (i) doub[{arr[i - 1], arr[i]}]++;
      |                      ^
lang.cpp:62:26: error: no match for 'operator[]' (operand types are 'Data<std::array<int, 3>, hash3, 55>' and '<brace-enclosed initializer list>')
   62 |           if (i >=2) trip[{arr[i - 2], arr[i - 1], arr[i]}];
      |                          ^
lang.cpp:64:25: error: no matching function for call to 'begin(Data<std::pair<int, int>, hash2, 150>&)'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/initializer_list:90:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)'
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
/usr/include/c++/10/initializer_list:90:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'std::initializer_list<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/bits/range_access.h:51:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:51:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&) [with _Container = Data<std::pair<int, int>, hash2, 150>]':
lang.cpp:64:25:   required from here
/usr/include/c++/10/bits/range_access.h:51:50: error: 'struct Data<std::pair<int, int>, hash2, 150>' has no member named 'begin'
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |                                           ~~~~~~~^~~~~
/usr/include/c++/10/bits/range_access.h:61:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:61:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&) [with _Container = Data<std::pair<int, int>, hash2, 150>]':
lang.cpp:64:25:   required from here
/usr/include/c++/10/bits/range_access.h:61:56: error: 'const struct Data<std::pair<int, int>, hash2, 150>' has no member named 'begin'
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |                                                 ~~~~~~~^~~~~
/usr/include/c++/10/bits/range_access.h:90:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   90 |     begin(_Tp (&__arr)[_Nm])
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:90:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   mismatched types '_Tp [_Nm]' and 'Data<std::pair<int, int>, hash2, 150>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1214:5: note: candidate: 'template<class _Tp> _Tp* std::begin(std::valarray<_Tp>&)'
 1214 |     begin(valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1214:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'std::valarray<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1224:5: note: candidate: 'template<class _Tp> const _Tp* std::begin(const std::valarray<_Tp>&)'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1224:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'const std::valarray<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
lang.cpp:64:25: error: no matching function for call to 'end(Data<std::pair<int, int>, hash2, 150>&)'
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/initializer_list:101:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)'
  101 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
/usr/include/c++/10/initializer_list:101:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'std::initializer_list<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/bits/range_access.h:71:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   71 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/10/bits/range_access.h:71:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&) [with _Container = Data<std::pair<int, int>, hash2, 150>]':
lang.cpp:64:25:   required from here
/usr/include/c++/10/bits/range_access.h:71:48: error: 'struct Data<std::pair<int, int>, hash2, 150>' has no member named 'end'
   71 |     end(_Container& __cont) -> decltype(__cont.end())
      |                                         ~~~~~~~^~~
/usr/include/c++/10/bits/range_access.h:81:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   81 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/10/bits/range_access.h:81:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&) [with _Container = Data<std::pair<int, int>, hash2, 150>]':
lang.cpp:64:25:   required from here
/usr/include/c++/10/bits/range_access.h:81:54: error: 'const struct Data<std::pair<int, int>, hash2, 150>' has no member named 'end'
   81 |     end(const _Container& __cont) -> decltype(__cont.end())
      |                                               ~~~~~~~^~~
/usr/include/c++/10/bits/range_access.h:100:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  100 |     end(_Tp (&__arr)[_Nm])
      |     ^~~
/usr/include/c++/10/bits/range_access.h:100:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   mismatched types '_Tp [_Nm]' and 'Data<std::pair<int, int>, hash2, 150>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1234:5: note: candidate: 'template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)'
 1234 |     end(valarray<_Tp>& __va)
      |     ^~~
/usr/include/c++/10/valarray:1234:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'std::valarray<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1244:5: note: candidate: 'template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
/usr/include/c++/10/valarray:1244:5: note:   template argument deduction/substitution failed:
lang.cpp:64:25: note:   'Data<std::pair<int, int>, hash2, 150>' is not derived from 'const std::valarray<_Tp>'
   64 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
lang.cpp: In instantiation of 'double Data<T, Hash, MAX>::operator&(const Data<T, Hash, MAX>&) const [with T = int; Hash = std::hash<int>; int MAX = 50]':
lang.cpp:71:20:   required from here
lang.cpp:23:32: error: 'const class std::unordered_map<int, int>' has no member named 'tot'
   23 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                              ~~^~~
lang.cpp:23:41: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'count'
   23 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                                       ~~^~~~~
lang.cpp:23:63: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'at'
   23 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                                                             ~~^~
lang.cpp:25:3: error: no matching function for call to 'begin(const Data<int, std::hash<int>, 50>&)'
   25 |   for (auto [k, v]: o) {
      |   ^~~
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/initializer_list:90:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)'
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
/usr/include/c++/10/initializer_list:90:5: note:   template argument deduction/substitution failed:
lang.cpp:25:3: note:   'Data<int, std::hash<int>, 50>' is not derived from 'std::initializer_list<_Tp>'
   25 |   for (auto [k, v]: o) {
      |   ^~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from lang.cpp:3:
/usr/include/c++/10/bits/range_access.h:51:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:51:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&) [with _Container = const Data<int, std::hash<int>, 50>]':
lang.cpp:25:3:   required from 'double Data<T, Hash, MAX>::operator&(const Data<T, Hash, MAX>&) const [with T = int; Hash = std::hash<int>; int MAX = 50]'
lang.cpp:71:20:   required from here
/usr/include/c++/10/bits/range_access.h:51:50: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'begin'
   51 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |                                           ~~~~~~~^~~~~
lang.cpp: In instantiation of 'double Data<T, Hash, MAX>::operator&(const Data<T, Hash, MAX>&) const [with T = int; Hash = std::hash<int>; int MAX = 50]':
lang.cpp:71:20:   required from here
/usr/include/c++/10/bits/range_access.h:61:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:61:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&) [with _Container = Data<int, std::hash<int>, 50>]':
lang.cpp:25:3:   required from 'double Data<T, Hash, MAX>::operator&(const Data<T, Hash, MAX>&) const [with T = int; Hash = std::hash<int>; int MAX = 50]'
lang.cpp:71:20:   required from here
/usr/include/c++/10/bits/range_access.h:61:56: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'begin'
   61 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |                                                 ~~~~~~~^~~~~
lang.cpp: In instantiation of 'double Data<T, Hash, MAX>::operator&(const Data<T, Hash, MAX>&) const [with T = int; Hash = std::hash<int>; int MAX = 50]':
lang.cpp:71:20:   required from here
/usr/include/c++/10/bits/range_access.h:90:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   90 |     begin(_Tp (&__arr)[_Nm])
      |     ^~~~~
/usr/include/c++/10/bits/range_access.h:90:5: note:   template argument deduction/substitution failed:
lang.cpp:25:3: note:   mismatched types '_Tp [_Nm]' and 'const Data<int, std::hash<int>, 50>'
   25 |   for (auto [k, v]: o) {
      |   ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1214:5: note: candidate: 'template<class _Tp> _Tp* std::begin(std::valarray<_Tp>&)'
 1214 |     begin(valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1214:5: note:   template argument deduction/substitution failed:
lang.cpp:25:3: note:   types 'std::valarray<_Tp>' and 'const Data<int, std::hash<int>, 50>' have incompatible cv-qualifiers
   25 |   for (auto [k, v]: o) {
      |   ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from lang.cpp:3:
/usr/include/c++/10/valarray:1224:5: note: candidate: 'template<class _Tp> const _Tp* std::begin(const std::valarray<_Tp>&)'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
/usr/include/c++/10/valarray:1224:5: note:   template argument deduction/substitution failed:
lang.cpp:25:3: note:   'const Data<int, std::hash<int>, 50>' is not derived from 'const std::valarray<_Tp>'
   25 |   for (auto [k, v]: o) {
      |   ^~~
lang.cpp:25:3: error: no matching function for call to 'end(const Data<int, std::hash<int>, 50>&)'
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/local