답안 #572689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572689 2022-06-05T04:13:22 Z tamthegod Zemljište (COCI22_zemljiste) C++14
70 / 70
257 ms 4300 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++)
        {
            int p = 0;
            for(int k=1; k<=s; k++)
            {
                int val = get(i, 1, j, k);
                while(p < k && val - get(i, 1, j, p) >= a) p++;
                int p1 = p - 1;
                if(p < k) res = min(res, abs(val - get(i, 1, j, p) - a) + abs(val - get(i, 1, j, p) - b));
                if(p1 >= 0) res = min(res, abs(val - get(i, 1, j, p1) - a) + abs(val - get(i, 1, j, p1) - b));
            }
        }
    cout << res;
}
int32_t main()
{
   // freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 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 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 4 ms 1108 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 4 ms 1132 KB Output is correct
18 Correct 3 ms 1084 KB Output is correct
19 Correct 2 ms 1108 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 4 ms 1132 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 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 1 ms 340 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 4 ms 1108 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 4 ms 1132 KB Output is correct
18 Correct 3 ms 1084 KB Output is correct
19 Correct 2 ms 1108 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 4 ms 1132 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 209 ms 4272 KB Output is correct
24 Correct 216 ms 4272 KB Output is correct
25 Correct 237 ms 4180 KB Output is correct
26 Correct 208 ms 4172 KB Output is correct
27 Correct 146 ms 4228 KB Output is correct
28 Correct 257 ms 4184 KB Output is correct
29 Correct 216 ms 4236 KB Output is correct
30 Correct 242 ms 4276 KB Output is correct
31 Correct 31 ms 3796 KB Output is correct
32 Correct 207 ms 4260 KB Output is correct
33 Correct 206 ms 4268 KB Output is correct
34 Correct 257 ms 4276 KB Output is correct
35 Correct 205 ms 4272 KB Output is correct
36 Correct 211 ms 4172 KB Output is correct
37 Correct 213 ms 4272 KB Output is correct
38 Correct 219 ms 4180 KB Output is correct
39 Correct 214 ms 4300 KB Output is correct
40 Correct 217 ms 4272 KB Output is correct
41 Correct 152 ms 4276 KB Output is correct
42 Correct 148 ms 4272 KB Output is correct
43 Correct 200 ms 4272 KB Output is correct
44 Correct 169 ms 4276 KB Output is correct