Submission #704867

# Submission time Handle Problem Language Result Execution time Memory
704867 2023-03-03T06:04:21 Z Paul_Liao_1457 Zemljište (COCI22_zemljiste) C++17
70 / 70
279 ms 4856 KB
//記得跳題
//#pragma GCC optimize("O4,unroll_loops")
//#pragma GCC target("avx2")
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>
#include<random>

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define INF (ll)(2e18)
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0);

using namespace std;

ll pre[505][505], x[505][505], p[505];
set<ll> st;

signed main(){
  AC;
  int r, s, a, b; cin >> r >> s >> a >> b;
  if (a > b) swap(a, b);
  
  FOR (i, 1, r + 1) FOR (j, 1, s + 1) cin >> x[i][j];
  FOR (j, 1, s + 1) {
    FOR (i, 1, r + 1) {
      pre[i][j] = pre[i-1][j] + x[i][j];
    }
  }
  
  ll ans = INF;
  
  FOR (u, 1, r + 1) FOR (d, u, r + 1) {
    st.clear();
    ll sum = 0;
    int l=0;
    FOR (j, 1, s + 1) {
      sum += pre[d][j] - pre[u-1][j];
      p[j] = sum;
      while (sum - p[l] >= b) {
        ans = min(ans, sum - p[l] - b + sum - p[l] - a);
        l++;
      }
      ans = min(ans, abs((sum - p[l]) - a) + abs((sum - p[l]) - b) );
      //cerr << "sum = " << sum << endl;
      /*auto it = st.lower_bound(sum - b);
      if (it != st.end() && sum - *it >= a) {
        cout << b - a << endl; return 0;
      }
      if (sum - *it < a) {
        ans = min(ans, a - (sum - *it) + b - (sum - *it));
      }
      if (it != st.begin()) {
        it = prev(it);
        ans = min(ans, (sum - *it) - b + (sum - *it) - a);
      }
      st.insert(sum);*/
    }
  }
  cout << ans << endl;
}

# 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 0 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 328 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 0 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 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 4 ms 1108 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 3 ms 1108 KB Output is correct
19 Correct 3 ms 1108 KB Output is correct
20 Correct 3 ms 1092 KB Output is correct
21 Correct 3 ms 1108 KB Output is correct
22 Correct 3 ms 1176 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 0 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 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 4 ms 1108 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 3 ms 1108 KB Output is correct
19 Correct 3 ms 1108 KB Output is correct
20 Correct 3 ms 1092 KB Output is correct
21 Correct 3 ms 1108 KB Output is correct
22 Correct 3 ms 1176 KB Output is correct
23 Correct 269 ms 4744 KB Output is correct
24 Correct 274 ms 4744 KB Output is correct
25 Correct 268 ms 4816 KB Output is correct
26 Correct 265 ms 4812 KB Output is correct
27 Correct 176 ms 4592 KB Output is correct
28 Correct 279 ms 4736 KB Output is correct
29 Correct 266 ms 4748 KB Output is correct
30 Correct 265 ms 4808 KB Output is correct
31 Correct 38 ms 4180 KB Output is correct
32 Correct 271 ms 4736 KB Output is correct
33 Correct 269 ms 4736 KB Output is correct
34 Correct 271 ms 4740 KB Output is correct
35 Correct 272 ms 4856 KB Output is correct
36 Correct 267 ms 4740 KB Output is correct
37 Correct 270 ms 4744 KB Output is correct
38 Correct 271 ms 4632 KB Output is correct
39 Correct 267 ms 4812 KB Output is correct
40 Correct 270 ms 4808 KB Output is correct
41 Correct 161 ms 4840 KB Output is correct
42 Correct 163 ms 4788 KB Output is correct
43 Correct 165 ms 4648 KB Output is correct
44 Correct 167 ms 4740 KB Output is correct