Submission #572688

# Submission time Handle Problem Language Result Execution time Memory
572688 2022-06-05T04:07:09 Z tamthegod Zemljište (COCI22_zemljiste) C++17
30 / 70
2000 ms 4192 KB
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 500 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int r, s, a, b;
int c[maxN][maxN];
int sum[maxN][maxN];
void ReadInput()
{
    cin >> r >> s >> a >> b;
    for(int i=1; i<=r; i++)
        for(int j=1; j<=s; j++)
        {
            cin >> c[i][j];
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + c[i][j];
        }
}
int get(int x, int y, int u, int v)
{
    return sum[u][v] - sum[x - 1][v] - sum[u][y - 1] + sum[x - 1][y - 1];
}
void Solve()
{
    int res = oo;
    if(a > b) swap(a, b);
    for(int i=1; i<=r; i++)
        for(int j=i; j<=r; j++)
        {
            set<int> S;
            S.insert(0);
            for(int k=1; k<=s; k++)
            {
                int val = get(i, 1, j, k);
                auto it = S.upper_bound(val - a);
                auto it1 = it;
                if(it1 != S.begin()) it1--;
                if(it != S.end()) res = min(res, abs(val - *it - a) + abs(val - *it - b));
                if(it1 != S.end()) res = min(res, abs(val - *it1 - a) + abs(val - *it1 - b));
                S.insert(val);
            }
        }
    cout << res;
}
int32_t main()
{
 //   freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 45 ms 1124 KB Output is correct
12 Correct 44 ms 1108 KB Output is correct
13 Correct 47 ms 1108 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 48 ms 1116 KB Output is correct
16 Correct 51 ms 1108 KB Output is correct
17 Correct 40 ms 1116 KB Output is correct
18 Correct 38 ms 1116 KB Output is correct
19 Correct 37 ms 1108 KB Output is correct
20 Correct 39 ms 1108 KB Output is correct
21 Correct 37 ms 1108 KB Output is correct
22 Correct 38 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 45 ms 1124 KB Output is correct
12 Correct 44 ms 1108 KB Output is correct
13 Correct 47 ms 1108 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 48 ms 1116 KB Output is correct
16 Correct 51 ms 1108 KB Output is correct
17 Correct 40 ms 1116 KB Output is correct
18 Correct 38 ms 1116 KB Output is correct
19 Correct 37 ms 1108 KB Output is correct
20 Correct 39 ms 1108 KB Output is correct
21 Correct 37 ms 1108 KB Output is correct
22 Correct 38 ms 1108 KB Output is correct
23 Execution timed out 2076 ms 4192 KB Time limit exceeded
24 Halted 0 ms 0 KB -