Submission #1678206
Source Code Expand
#include <iostream> #include <algorithm> #include <utility> using namespace std; int H, W; long long res = 1000000000; int solve() { for (int i = 1; i <= H - 1; ++i) { long long min_val, max_val; min_val = (long long) i * W; max_val = (long long) i * W; int separated_width; if (W % 2) { separated_width = W / 2 + 1; min_val = min(min_val, (long long) (H - i) * separated_width); max_val = max(max_val, (long long) (H - i) * separated_width); min_val = min(min_val, (long long) (H - i) * (W - separated_width)); max_val = max(max_val, (long long) (H - i) * (W - separated_width)); res = min(res, max_val - min_val); min_val = i * W; max_val = i * W; } separated_width = W / 2; min_val = min(min_val, (long long) (H - i) * separated_width); max_val = max(max_val, (long long) (H - i) * separated_width); min_val = min(min_val, (long long) (H - i) * (W - separated_width)); max_val = max(max_val, (long long) (H - i) * (W - separated_width)); res = min(res, max_val - min_val); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; solve(); swap(&H, &W); solve(); cout << res << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Chocolate Bar |
User | colaholic |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1397 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:49:16: error: no matching function for call to ‘swap(int*, int*)’ swap(&H, &W); ^ In file included from /usr/include/c++/5/bits/stl_pair.h:59:0, from /usr/include/c++/5/bits/stl_algobase.h:64, from /usr/include/c++/5/bits/char_traits.h:39, from /usr/include/c++/5/ios:40, from /usr/include/c++/5/ostream:38, from /usr/include/c++/5/iostream:39, from ./Main.cpp:1: /usr/include/c++/5/bits/move.h:176:5: note: candidate: void std::swap(_Tp&, _Tp&) [with _Tp = int*] <near match> swap(_Tp& __a, _Tp& __b) ^ /usr/include/c++/5/bits/move.h:176:5: note: conversion of argument 2 would be ill-formed: ./Main.cpp:49:16: error: invalid initialization of non-const reference of type ‘int*&’ from an rvalue of type ‘int*’ swap(&H, &W); ^ In file included from /usr/include/c++/5/bits/stl_pair.h:59:0, from /usr/...