Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1622 Accepted Submission(s): 460
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { //fropen("in","r",stdin); // fropen("out","w",stdin); int n,m,a,b; while(scanf("%d%d%d%d",&n,&m,&a,&b)!=EOF) { int d,f,h; int v1,v2,v3,v4,k,l; v1=n/2+n%2; f=m/2+m%2; h=min(v1,f); d=max(v1,f); if(n==m&&n%2==1&&m%2==1&&h==min(a,b)&&d==max(a,b)) { printf("%d\n",h-1); continue; } if(h==v1) { k=max(a-1,n-a); v2=min(k,min(m-b+1,b)); } else { k=max(b-1,m-b); v2=min(k,min(n-a+1,a)); } v2=max(v2,h); printf("%d\n",v2); } return 0; }