Submission #1215884

#TimeUsernameProblemLanguageResultExecution timeMemory
1215884lrnnzRaisins (IOI09_raisins)C++20
25 / 100
5095 ms328 KiB
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <iomanip> using namespace std; #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define ll int #define ld long double #define ui uint64_t #define cont(set, element) ((set).find(element) != (set).end()) /********* DEBUG *********/ template <typename T> void outvec(const vector<T>& Z){ for (const T& x : Z) cout << x << ' '; cout << "\n"; } void printVariable(const any& var) { if (!var.has_value()) { cout << "null"; return; } if (var.type() == typeid(int)) { cout << any_cast<int>(var); } else if (var.type() == typeid(double)) { cout << any_cast<double>(var); } else if (var.type() == typeid(float)) { cout << any_cast<float>(var); } else if (var.type() == typeid(char)) { cout << any_cast<char>(var); } else if (var.type() == typeid(bool)) { cout << (any_cast<bool>(var) ? "true" : "false"); } else if (var.type() == typeid(string)) { cout << any_cast<string>(var); } else if (var.type() == typeid(const char*)) { cout << any_cast<const char*>(var); } else if (var.type() == typeid(long long)) { cout << any_cast<long long>(var); } else { cout << "[unknown type]"; } } template<typename... Args> void outval(Args... args) { vector<any> variables = {args...}; for (size_t i = 0; i < variables.size(); ++i) { printVariable(variables[i]); if (i != variables.size() - 1) { cout << " "; } } cout << "\n"; } #define sp << " " << /********* DEBUG *********/ const ll MOD = 1e9+7; const ll MOD2 = 998244353; const ll inf = 1e18; const ll mxN = 2000005; ll re(ll tlx, ll tly, ll brx, ll bry, vector<vector<ll>> &grid, ll sum){ ll ans = inf; if (tlx == brx && tly == bry) return 0; ll curr = 0; for (int i = tly; i < bry; i++){ for (int j = tlx; j <= brx; j++){ curr += grid[i][j]; } ans = min(ans, re(tlx, tly, brx, i, grid, curr) + re(tlx, i + 1, brx, bry, grid, sum-curr)); } curr = 0; for (int i = tlx; i < brx; i++){ for (int j = tly; j <= bry; j++) curr += grid[j][i]; ans = min(ans, re(tlx, tly, i, bry, grid, curr) + re(i + 1, tly, brx, bry, grid, sum-curr)); } return ans + sum; } void solve(){ ll n,m; cin >> n >> m; vector<vector<ll>> grid(n,vector<ll>(m)); ll sum = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cin >> grid[i][j]; sum += grid[i][j]; } } outval(re(0, 0, m-1, n-1, grid, sum)); } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t = 1; //cin >> t; while (t--) { solve(); } }

Compilation message (stderr)

raisins.cpp:70:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   70 | const ll inf = 1e18;
      |                ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...