Submission #718260

#TimeUsernameProblemLanguageResultExecution timeMemory
718260AugustynZemljište (COCI22_zemljiste)C++17
0 / 70
1 ms212 KiB
#include<iostream> using namespace std; int r,s,a,b; long long **sum_pr,odp; long long sumzkwr(int xpd,int ypd,int xlg,int ylg) { return sum_pr[xpd][ypd]-sum_pr[xlg-1][ypd]-sum_pr[xpd][ylg-1]+sum_pr[xlg-1][ylg-1]; } void bs(int j,int i,int k) { int pocz=1,kon=i+1,sr=(pocz+kon)>>1; while(pocz!=sr) { if(sumzkwr(j,i,k,sr)>=b) pocz=sr; else kon=sr; sr=(pocz+kon)>>1; } long long pom=sumzkwr(j,i,k,sr); odp=min(odp,abs(a-pom)+abs(b-pom)); if(pom>b&&sr<i) { ++sr; odp=min(odp,abs(a-pom)+abs(b-pom)); } } int main() { scanf("%d%d%d%d",&r,&s,&a,&b); if(a>b) swap(a,b); odp=a+b; sum_pr=new long long *[s+1]; for(int i=0;i<=s;++i) sum_pr[i]=new long long [r+1]; for(int i=1;i<=r;++i) { for(int j=1;j<=s;++j) { scanf("%lld",&sum_pr[j][i]); sum_pr[j][i]+=sum_pr[j-1][i]+sum_pr[j][i-1]-sum_pr[j-1][i-1]; for(int k=j;k>=1;--k) bs(j,i,k); } } printf("%lld",odp); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d%d%d%d",&r,&s,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |             scanf("%lld",&sum_pr[j][i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...