ログイン
新規登録
AtsuoCoder Optimization Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 1a5b77ea-c96f-4f99-b535-d2241561f878
コード
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") using namespace std; using ll = long long; struct Op { int id, H, W, a, b; bool operator<(const &Op rhs) const { return H * W >= rhs.H * rhs.W; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, T; if (!(cin >> N >> T)) return 0; vector<vector<int>> A(N, vector<int>(N)), B(N, vector<int>(N)); for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> A[i][j]; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> B[i][j]; vector<Op> ops(T); for (int t = 0; t < T; ++t) { ops[t].id = t; cin >> ops[t].H >> ops[t].W >> ops[t].a >> ops[t].b; } const int LIMIT = 100000; vector<tuple<int, int, int>> out; out.reserve(10000); clock_t clk = clock(); vector<char> used(T, 0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); while ((double)(clock() - clk) / CLOCKS_PER_SEC < 2.9) { sort(ops.begin(), ops.end()); for (int t = 0; t < T; ++t) { int id = ops[t].id, H = ops[t].H, W = ops[t].W, a = ops[t].a, b = ops[t].b; int uses = 0; while (used[id] < 3 && (int)out.size() < LIMIT) { vector<vector<int>> pref(N + 1, vector<int>(N + 1, 0)); bool anyPossible = false; for (int i = 0; i < N; ++i) { int rowSum = 0; for (int j = 0; j < N; ++j) { int w = 0; if (A[i][j] == a) { int before = (int)A[i][j] - (int)B[i][j]; int after = (int)b - (int)B[i][j]; w = after * after - before * before; anyPossible = true; } rowSum += w; pref[i + 1][j + 1] = pref[i][j + 1] + rowSum; } } if (!anyPossible) break; int bestDelta = 0; int bestX = -1, bestY = -1; for (int x = 0; x + H <= N; ++x) { for (int y = 0; y + W <= N; ++y) { int x2 = x + H, y2 = y + W; int s = pref[x2][y2] - pref[x][y2] - pref[x2][y] + pref[x][y]; if (s < bestDelta) { bestDelta = s; bestX = x; bestY = y; } } } if (bestX == -1) break; for (int i = bestX; i < bestX + H; ++i) { for (int j = bestY; j < bestY + W; ++j) { if (A[i][j] == a) A[i][j] = b; } } out.emplace_back(id, bestX, bestY); ++used[id]; } if ((int)out.size() >= LIMIT) break; } } cout << out.size() << '\n'; for (auto &tp : out) { int id, x, y; tie(id, x, y) = tp; cout << id << " " << x << " " << y << "\n"; } return 0; }
結果
問題
点数
言語
結果
実行時間
メモリ
A - Replace() は Replace() されました
0
C++
WJ
0 ms
0 KiB
コンパイルエラー
Main.cpp:10:27: error: ISO C++ forbids declaration of 'Op' with no type [-fpermissive] 10 | bool operator<(const &Op rhs) const | ^~ Main.cpp:10:30: error: expected ',' or '...' before 'rhs' 10 | bool operator<(const &Op rhs) const | ^~~ Main.cpp: In member function 'bool Op::operator<(const int&) const': Main.cpp:12:25: error: 'rhs' was not declared in this scope 12 | return H * W >= rhs.H * rhs.W; | ^~~ In file included from /usr/include/c++/13/bits/stl_algobase.h:71, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from Main.cpp:1: /usr/include/c++/13/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = __gnu_cxx::__normal_iterator<Op*, std::vector<Op> >; _Iterator2 = __gnu_cxx::__normal_iterator<Op*, std::vector<Op> >]': /usr/include/c++/13/bits/stl_algo.h:1819:14: required from 'constexpr void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1859:25: required from 'constexpr void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1950:31: required from 'constexpr void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:4861:18: required from 'constexpr void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<Op*, vector<Op> >]' Main.cpp:45:13: required from here /usr/include/c++/13/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'Op' and 'Op') 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ In file included from /usr/include/c++/13/bits/stl_algobase.h:67: /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' (reversed) 1189 | operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:45:23: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _Iterator, class _Container> constexpr std::__detail::__synth3way_t<_T1> __gnu_cxx::operator<=>(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)' (rewritten) 1208 | operator<=>(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:45:23: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ Main.cpp:10:10: note: candidate: 'bool Op::operator<(const int&) const' 10 | bool operator<(const &Op rhs) const | ^~~~~~~~ Main.cpp:10:27: note: no known conversion for argument 1 from 'Op' to 'const int&' 10 | bool operator<(const &Op rhs) const | ~~~~~~~^~ /usr/include/c++/13/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = Op; _Iterator = __gnu_cxx::__normal_iterator<Op*, std::vector<Op> >]': /usr/include/c++/13/bits/stl_algo.h:1799:20: required from 'constexpr void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Val_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1827:36: required from 'constexpr void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1859:25: required from 'constexpr void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1950:31: required from 'constexpr void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:4861:18: required from 'constexpr void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<Op*, vector<Op> >]' Main.cpp:45:13: required from here /usr/include/c++/13/bits/predefined_ops.h:98:22: error: no match for 'operator<' (operand types are 'Op' and 'Op') 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' (reversed) 1189 | operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:98:22: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _Iterator, class _Container> constexpr std::__detail::__synth3way_t<_T1> __gnu_cxx::operator<=>(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)' (rewritten) 1208 | operator<=>(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:98:22: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ Main.cpp:10:10: note: candidate: 'bool Op::operator<(const int&) const' 10 | bool operator<(const &Op rhs) const | ^~~~~~~~ Main.cpp:10:27: note: no known conversion for argument 1 from 'Op' to 'const int&' 10 | bool operator<(const &Op rhs) const | ~~~~~~~^~ /usr/include/c++/13/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<Op*, std::vector<Op> >; _Value = Op]': /usr/include/c++/13/bits/stl_heap.h:140:48: required from 'constexpr void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Distance = long int; _Tp = Op; _Compare = __gnu_cxx::__ops::_Iter_less_val]' /usr/include/c++/13/bits/stl_heap.h:247:23: required from 'constexpr void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Distance = long int; _Tp = Op; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_heap.h:356:22: required from 'constexpr void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1635:23: required from 'constexpr void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1910:25: required from 'constexpr void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1926:27: required from 'constexpr void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:1947:25: required from 'constexpr void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Op*, vector<Op> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' /usr/include/c++/13/bits/stl_algo.h:4861:18: required from 'constexpr void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<Op*, vector<Op> >]' Main.cpp:45:13: required from here /usr/include/c++/13/bits/predefined_ops.h:69:22: error: no match for 'operator<' (operand types are 'Op' and 'Op') 69 | { return *__it < __val; } | ~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> __gnu_cxx::operator<=>(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' (reversed) 1189 | operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1189:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:69:22: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 69 | { return *__it < __val; } | ~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _Iterator, class _Container> constexpr std::__detail::__synth3way_t<_T1> __gnu_cxx::operator<=>(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)' (rewritten) 1208 | operator<=>(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1208:5: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/predefined_ops.h:69:22: note: 'Op' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 69 | { return *__it < __val; } | ~~~~~~^~~~~~~ Main.cpp:10:10: note: candidate: 'bool Op::operator<(const int&) const' 10 | bool operator<(const &Op rhs) const | ^~~~~~~~ Main.cpp:10:27: note: no known conversion for argument 1 from 'Op' to 'const int&' 10 | bool operator<(const &Op rhs) const | ~~~~~~~^~