답안 #704851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704851 2023-03-03T05:35:01 Z Paul_Liao_1457 Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 468 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];
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;
    st.insert(sum);
    FOR (j, 1, s + 1) {
      sum += pre[d][j] - pre[u-1][j];
      auto it = st.lower_bound(sum - b);
      if (it != st.end() && sum - *it >= a && sum - *it <= b) {
        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);
      }
    }
  }
  cout << ans << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -