Submission #872348

#TimeUsernameProblemLanguageResultExecution timeMemory
872348Ahmed_SolymanZemljište (COCI22_zemljiste)C++14
70 / 70
1656 ms6996 KiB
/* In the name of Allah made by: Ahmed_Solyman */ #include <bits/stdc++.h> #include <ext/rope> using namespace std; using namespace __gnu_cxx; #pragma GCC optimize("-Ofast") #pragma GCC optimize("-O1") //-------------------------------------------------------------// typedef long long ll; typedef unsigned long long ull; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define PI acos(-1) #define lb lower_bound #define ub upper_bound #define endl '\n' #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define sum_to(n) (n*(n+1))/2 #define pb push_back #define pf push_front #define fil(arr,x) memset(arr,x,sizeof(arr)) const ll mod=1e9+7; int dx[8]={0,1,0,-1,1,1,-1,-1}; int dy[8]={1,0,-1,0,1,-1,-1,1}; //-------------------------------------------------------------// ll lcm(ll a,ll b) { return (max(a,b)/__gcd(a,b))*min(a,b); } void person_bool(bool x) { cout<<(x?"YES":"NO")<<endl; } ll dp[505][505]; ll sum(int i,int j,int a,int b){ return dp[a][b]-dp[a][j-1]-dp[i-1][b]+dp[i-1][j-1]; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); #ifndef ONLINE_JUDGE //freopen("input.in", "r", stdin); //freopen("output.out", "w", stdout); #endif fast int n,m; ll a,b; cin>>n>>m>>a>>b; if(a>b)swap(a,b); vector<vector<ll>>arr(n+1,vector<ll>(m+1)); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>arr[i][j]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+arr[i][j]; } } ll ans=4e18; for(int x=1;x<=m;x++){ for(int y=x;y<=m;y++){ for(int i=1;i<=n;i++){ int l=i,r=n; ll s1=0,s2=0; while(l<=r){ int mid=l+r>>1; if(sum(i,x,mid,y)>=a){ s1=sum(i,x,mid,y); r=mid-1; } else{ l=mid+1; } } if(r>=i)s2=sum(i,x,r,y); ans=min(ans,abs(s1-a)+abs(s1-b)); ans=min(ans,abs(s2-a)+abs(s2-b)); } } } cout<<ans<<endl; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:73:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |                     int mid=l+r>>1;
      |                             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...