Submission #1036105

#TimeUsernameProblemLanguageResultExecution timeMemory
1036105vjudge1Zemljište (COCI22_zemljiste)C++17
30 / 70
2035 ms4272 KiB
#warning Check FastIO
#ifdef ONLINE_JUDGE
    #pragma GCC optimize("Ofast")
    #pragma GCC target("avx,avx2,fma")
#endif
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <random>
#include <chrono>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
#define bits_on(a) (__builtin_popcountll(a))
#define mx_pw2(a) (__builtin_ctzll(a))
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
#define SHUFFLE(v) shuffle(all(v), RNG); 
const ll inf=LLONG_MAX;
void input(vll& a)
{
    for(auto& i:a)
        cin>>i;
}
void pyn(bool a)
{
    cout<<(a?"YES":"NO")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
  if(b==0){
    return 1;
  }
  ll temp=powmod(a,b/2,modulo);
  if(b%2==0){
    return (temp*temp)%modulo;
  }
  else{
    return (a*((temp*temp)%modulo))%modulo;
  }
}

bool Prime(ll n){
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
    return (n>1);
}
const int N=502;
ll a[N][N],pre[N][N];
ll ele[N],npre[N];
bool check(ll x)
{
    // sum>=x
}
void solve()
{
    ll n,m,ax,bx;
    cin>>n>>m>>ax>>bx;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            pre[i][j]=pre[i][j-1]+a[i][j];
        }
    }
    ll ans=ax+bx;
    for(int x=1;x<=m;x++)
    {
        for(int xp=x;xp<=m;xp++)
        {
            set<ll> pr;
            pr.insert(0);
            ll sm=0;
            for(ll row=1;row<=n;row++)
            {
                sm+=pre[row][xp]-pre[row][x-1];
                auto it=pr.lower_bound(sm-bx);
                if(it!=pr.end())
                {
                    ll l=*it;
                    ll val=sm-l;
                    ans=min(ans,abs(ax-val)+abs(bx-val));
                }
                if(it!=pr.begin())
                {
                    it--;
                    ll l=*it;
                    ll val=sm-l;
                    ans=min(ans,abs(ax-val)+abs(bx-val));
                }
                pr.insert(sm);
                // sm-b <= l 
                // l = sm-b-1
                // sm - l = sm -sm +b == b+1 
            }
        }
    }
    cout<<ans<<endl;
}
int supra(){
    I Hear Shots Ratatatata
    ll tqwertyuiop=1;
    for(int tp=1;tp<=tqwertyuiop;tp++)
    {
        // cout<<"Case #"<<tp<<": ";
        solve();
    }
    return 0;
}
/*
Bro use only in a emergency 
this is kind of hacking
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/

Compilation message (stderr)

Main.cpp:1:2: warning: #warning Check FastIO [-Wcpp]
    1 | #warning Check FastIO
      |  ^~~~~~~
Main.cpp: In function 'bool check(long long int)':
Main.cpp:73:1: warning: no return statement in function returning non-void [-Wreturn-type]
   73 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...