답안 #1011434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011434 2024-06-30T13:39:14 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 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());
}
	}};

auto hash2 = [] (const pint &x) { return x.first << 16ll | x.second; };
auto hash3 = [] (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 lambda function:
lang.cpp:44:57: warning: left shift count >= width of type [-Wshift-count-overflow]
   44 | auto hash3 = [] (const array<int, 3> &x) { return (x[0] << 32ll) | (x[1] << 16ll) | x[2]; };
lang.cpp: At global scope:
lang.cpp:48:24: error: type/value mismatch at argument 2 in template parameter list for 'template<class T, class Hash, int MAX> struct Data'
   48 |   Data<pint, hash2, 150> doub;
      |                        ^
lang.cpp:48:24: note:   expected a type, got 'hash2'
lang.cpp:49:32: error: type/value mismatch at argument 2 in template parameter list for 'template<class T, class Hash, int MAX> struct Data'
   49 |   Data<array<int, 3>, hash3, 55> trip;
      |                                ^
lang.cpp:49:32: note:   expected a type, got 'hash3'
lang.cpp: In constructor 'Profile::Profile(int*)':
lang.cpp:55:15: error: no match for 'operator[]' (operand types are 'Data<int, std::hash<int>, 50>' and 'int')
   55 |           sing[arr[i]]++;
      |               ^
lang.cpp:56:22: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   56 |           if (i) doub[{arr[i - 1], arr[i]}]++;
      |                      ^
lang.cpp:57:26: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   57 |           if (i >=2) trip[{arr[i - 2], arr[i - 1], arr[i]}];
      |                          ^
lang.cpp:59:25: error: 'begin' was not declared in this scope
   59 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
lang.cpp:59:25: note: suggested alternatives:
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:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from lang.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
lang.cpp:59:25: error: 'end' was not declared in this scope
   59 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                         ^~~~
lang.cpp:59:25: note: suggested alternatives:
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:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from lang.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
lang.cpp:59:36: error: request for member 'inv' in '((Profile*)this)->Profile::doub', which is of non-class type 'int'
   59 |       for (auto [k, v]: doub) doub.inv.emplace(v, k);
      |                                    ^~~
lang.cpp:61:12: error: request for member 'tot' in '((Profile*)this)->Profile::doub', which is of non-class type 'int'
   61 |       doub.tot = 99;
      |            ^~~
lang.cpp:62:12: error: request for member 'tot' in '((Profile*)this)->Profile::trip', which is of non-class type 'int'
   62 |       trip.tot = 98;
      |            ^~~
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:66:20:   required from here
lang.cpp:22:32: error: 'const class std::unordered_map<int, int>' has no member named 'tot'
   22 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                              ~~^~~
lang.cpp:22:41: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'count'
   22 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                                       ~~^~~~~
lang.cpp:22:63: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'at'
   22 |    ret += magic((double) v / m.tot - (o.count(k) ? (double) o.at(k) / o.tot : 0));
      |                                                             ~~^~
lang.cpp:24:3: error: no matching function for call to 'begin(const Data<int, std::hash<int>, 50>&)'
   24 |   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:24:3: note:   'Data<int, std::hash<int>, 50>' is not derived from 'std::initializer_list<_Tp>'
   24 |   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:24: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:66: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:66: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:24: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:66: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:66: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:24:3: note:   mismatched types '_Tp [_Nm]' and 'const Data<int, std::hash<int>, 50>'
   24 |   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:24:3: note:   types 'std::valarray<_Tp>' and 'const Data<int, std::hash<int>, 50>' have incompatible cv-qualifiers
   24 |   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:24:3: note:   'const Data<int, std::hash<int>, 50>' is not derived from 'const std::valarray<_Tp>'
   24 |   for (auto [k, v]: o) {
      |   ^~~
lang.cpp:24: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/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:24:3: note:   'Data<int, std::hash<int>, 50>' is not derived from 'std::initializer_list<_Tp>'
   24 |   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: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 = const Data<int, std::hash<int>, 50>]':
lang.cpp:24: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:66:20:   required from here
/usr/include/c++/10/bits/range_access.h:71:48: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'end'
   71 |     end(_Container& __cont) -> decltype(__cont.end())
      |                                         ~~~~~~~^~~
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:66:20:   required from here
/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<int, std::hash<int>, 50>]':
lang.cpp:24: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:66:20:   required from here
/usr/include/c++/10/bits/range_access.h:81:54: error: 'const struct Data<int, std::hash<int>, 50>' has no member named 'end'
   81 |     end(const _Container& __cont) -> decltype(__cont.end())
      |                                               ~~~~~~~^~~
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:66:20:   required from here
/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:24:3: note:   mismatched types '_Tp [_Nm]' and 'const Data<int, std::hash<int>, 50>'
   24 |   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: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:24:3: note:   types 'std::valarray<_Tp>' and 'const Data<int, std::hash<int>, 50>' have incompatible cv-qualifiers
   24 |   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: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:24:3: note:   'const Data<int, std::hash<int>, 50>' is not derived from 'const std::valarray<_Tp>'
   24 |   for (auto [k, v]: o) {
      |   ^~~
lang.cpp:25:14: error: 'const class std::unordered_map<int, int>' has no member named 'contains'
   25 |    if (not m.contains(k)) ret += magic((double) v / o.tot);
      |            ~~^~~~~~~~
lang.cpp: In instantiation of 'void Data<T, Hash, MAX>::operator+=(const Data<T, Hash, MAX>&) [with T = int; Hash = std::hash<int>; int MAX = 50]':
lang.cpp:70:17:   required from here
lang.cpp:31:3: error: no matching function for call to 'begin(const Data<int, std::hash<int>, 50>&)'
   31 |   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:31:3: note:   'Data<int, std::hash<int>, 50>' is not derived from 'std::initializer_list<_Tp>'
   31 |   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 /u