Submission #1692377
Source Code Expand
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=2e5+10;
struct Node
{
int x,y;
Node (int x=0,int y=0):x(x),y(y){}
bool operator < ( const Node &A ) const { return x<A.x || (x==A.x && y<A.y); }
}P[N],Q[N<<1];
int n,Mx,Mn;
void Init()
{
scanf("%d",&n);
Mx=-1e9-10,Mn=1e9+10;
for (int i=1;i<=n;++i)
{
scanf("%d%d",&P[i].x,&P[i].y);
if (P[i].x>P[i].y) swap(P[i].x,P[i].y);
Mx=max(P[i].y,Mx); Mn=min(P[i].x,Mn);
}
}
int app[N],cnt;
void Add(int pos,int v)
{
if (app[pos]) cnt--;
app[pos]+=v;
if (app[pos]) cnt++;
}
bool Can(int pos)
{
if (cnt!=n) return 0;
if (app[pos]>1) return 1;
else return 0;
}
void Solve()
{
int XMx=Mx,XMn=Mx,YMx=Mn,YMn=Mn;
for (int i=1;i<=n;++i)
XMn=min(XMn,P[i].y),YMx=max(YMx,P[i].x);
LL ans=1ll*(XMx-XMn)*(YMx-YMn);
int top=0;
for (int i=1;i<=n;++i) Q[++top]=Node(P[i].x,i),Q[++top]=Node(P[i].y,i);
sort(Q+1,Q+top+1);
int h=1;cnt=0;
for (int i=1;i<=top;++i)
{
Add(Q[i].y,1);
while (Can(Q[h].y)) Add(Q[h].y,-1),++h;
if (cnt==n) ans=min(ans,1ll*(Mx-Mn)*(Q[i].x-Q[h].x));
}
printf("%lld\n",ans);
}
int main()
{
Init();
Solve();
return 0;
}
Submission Info
Submission Time
2017-10-18 20:12:26+0900
Task
E - Ball Coloring
User
Mcallor
Language
C++14 (GCC 5.4.1)
Score
700
Code Size
1226 Byte
Status
AC
Exec Time
84 ms
Memory
5760 KB
Compile Error
./Main.cpp: In function ‘void Init()’:
./Main.cpp:20:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:24:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&P[i].x,&P[i].y);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
700 / 700
Status
Set Name
Test Cases
Sample
example0, example1, example2
All
div20, div21, div22, div23, div24, example0, example1, example2, maxrand0, maxrand1, maxrand2, maxrand20, maxrand21, maxrand210, maxrand211, maxrand22, maxrand23, maxrand24, maxrand25, maxrand26, maxrand27, maxrand28, maxrand29, maxrand3, maxrand4, smallrand0, smallrand1, smallrand2, smallrand3, smallrand4, sparse0, sparse1, sparse2, sparse3, sparse4
Case Name
Status
Exec Time
Memory
div20
AC
76 ms
5632 KB
div21
AC
76 ms
5632 KB
div22
AC
76 ms
5632 KB
div23
AC
76 ms
5632 KB
div24
AC
76 ms
5632 KB
example0
AC
2 ms
4864 KB
example1
AC
2 ms
4864 KB
example2
AC
2 ms
4864 KB
maxrand0
AC
76 ms
5632 KB
maxrand1
AC
76 ms
5632 KB
maxrand2
AC
76 ms
5632 KB
maxrand20
AC
78 ms
5632 KB
maxrand21
AC
79 ms
5632 KB
maxrand210
AC
74 ms
5632 KB
maxrand211
AC
79 ms
5632 KB
maxrand22
AC
79 ms
5632 KB
maxrand23
AC
79 ms
5632 KB
maxrand24
AC
78 ms
5632 KB
maxrand25
AC
79 ms
5632 KB
maxrand26
AC
79 ms
5632 KB
maxrand27
AC
79 ms
5632 KB
maxrand28
AC
79 ms
5632 KB
maxrand29
AC
77 ms
5632 KB
maxrand3
AC
76 ms
5632 KB
maxrand4
AC
76 ms
5632 KB
smallrand0
AC
2 ms
4864 KB
smallrand1
AC
2 ms
4864 KB
smallrand2
AC
2 ms
4864 KB
smallrand3
AC
2 ms
4864 KB
smallrand4
AC
2 ms
4864 KB
sparse0
AC
84 ms
5632 KB
sparse1
AC
84 ms
5632 KB
sparse2
AC
84 ms
5760 KB
sparse3
AC
84 ms
5632 KB
sparse4
AC
84 ms
5632 KB