Submission #666290

#TimeUsernameProblemLanguageResultExecution timeMemory
666290Chal1shkanZemljište (COCI22_zemljiste)C++14
70 / 70
505 ms6932 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define pii pair <int, int> # define pll pair <ll, ll> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 1e5 + 125; const ll maxl = 20 + 0; const ll inf = 2e9 + 0; const ll mod = 998244353; using namespace std; ll n, m, l, r; ll a[525][525]; ll p[525], pr[525][525]; void ma1n () { cin >> n >> m >> l >> r; if (l > r) swap(l, r); for (ll i = 1; i <= n; ++i) { for (ll j = 1; j <= m; ++j) { cin >> a[i][j]; pr[i][j] = pr[i][j - 1] + a[i][j]; } } ll ans = inf; for (ll i = 1; i <= m; ++i) { for (ll j = i; j <= m; ++j) { for (ll ij = 1; ij <= n; ++ij) { p[ij] = p[ij - 1] + pr[ij][j] - pr[ij][i - 1]; } p[n + 1] = p[n + 2] = p[n]; ll cur = 0; for (ll ij = 1; ij <= n; ++ij) { while (p[ij] - p[cur] > r) ++cur; ans = min(ans, abs(p[ij] - p[cur] - l) + abs(p[ij] - p[cur] - r)); if (cur > 0) ans = min(ans, abs(p[ij] - p[cur - 1] - l) + abs(p[ij] - p[cur - 1] - r)); } } } cout << ans << nl; } int main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; test++) { // cout << "Case " << test << ":" << nl; ma1n(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...