提出 #19073768


ソースコード 拡げる

#include<bits/stdc++.h>
clock_t __t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 233
	typedef __int128 ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-__t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	ll mul(ll x,ll y){ull s=1.0*x/mod*y;ll res=1ull*x*y-s*mod;return (res%mod+mod)%mod;}
}
using namespace my_std;

struct pt
{
	ll x,y;
	pt(ll X=0,ll Y=0){x=X,y=Y;}
	const pt operator + (const pt &a) const {return pt(x+a.x,y+a.y);}
	const pt operator - (const pt &a) const {return pt(x-a.x,y-a.y);} 
	const pt operator * (const int &a) const {return pt(x*a,y*a);} 
}P[sz],A,B;
ll Cross(pt a,pt b){return a.x*b.y-a.y*b.x;}
int n,N;

void Work()
{
	sort(P+1,P+n+1,[](pt a,pt b){return a.x==b.x?a.y<b.y:a.x<b.x;});
	static pt st[sz]; int tp; st[tp=1]=P[1];
	rep(i,2,n) { while (tp>1&&Cross(st[tp]-st[tp-1],P[i]-st[tp])<=0) --tp; st[++tp]=P[i]; }
	int nn=tp; 
	drep(i,n-1,1) { while (tp>nn&&Cross(st[tp]-st[tp-1],P[i]-st[tp])<=0) --tp; st[++tp]=P[i]; }
	rep(i,1,n) P[i+n]=P[i],P[i]=P[1]; N=n+n; rep(i,1,tp-1) P[i]=st[i]; n=tp-1;
}

ll ans;
ll Abs(ll x){return x<0?-x:x;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll work(pt a,pt b) { b=b-a; ll x=Abs(b.x),y=Abs(b.y); return gcd(x,y); }

ll lb(ll x){return x=Abs(x),(x?(x&-x):(1ll<<60));} 

int main()
{
	file();
	read(n);
	rep(i,1,n) read(P[i].x,P[i].y);
	rep(i,1,n) rep(j,i+1,n) rep(k,j+1,n) assert(Cross(P[j]-P[i],P[k]-P[i]));
	Work();
	drep(i,N,1) P[i]=P[i]-P[1];
	rep(i,2,N)
	{
		pt p=P[i];
		if (!p.y) { B.x=gcd(B.x,p.x); continue; } if (!A.y) { A=p; continue; }
		while (p.y) { ll w=A.y/p.y; A=A-p*w; swap(A,p); if (B.x) A.x%=B.x,p.x%=B.x; }
		B.x=gcd(B.x,p.x);
	}
	auto calc=[&](pt a,pt b){ll x=b.x-a.x,y=b.y-a.y;x=Abs(x),y=Abs(y),x=gcd(x,y);return x&-x;};
	ans+=calc(P[1],P[n]); rep(i,1,n-1) ans+=calc(P[i],P[i+1]);
	if (lb(A.x)<lb(A.y)&&lb(A.x)<lb(B.x))
	{
		while (B.x) { ll w=A.x/B.x; A=A-B*w; swap(A,B); }
		assert(!(lb(A.y)<lb(A.x)&&lb(A.y)<lb(B.y)));
		swap(A.x,A.y),swap(B.x,B.y); rep(i,1,n) swap(P[i].x,P[i].y);
	}
	while (lb(A.x)<lb(A.y)) { ll w=lb(A.x)/lb(B.x); A=A+B*w; }
	ll t1=lb(A.y),t2=lb(B.x);
	rep(i,1,n) { pt p=P[i]; p.y/=A.y,p.x=(p.x-(__int128)p.y*A.x)/B.x; assert(p.y*A.y==P[i].y&&p.y*A.x+p.x*B.x==P[i].x); p.y*=t1,p.x*=t2; P[i]=p; }
	ll w=-work(P[1],P[n]); rep(i,1,n-1) w-=work(P[i],P[i+1]);
	rep(i,2,n-1) w+=Abs(Cross(P[i],P[i+1])); w/=2,++w;
	ans+=w;
	cout<<(long long)ans;
	return 0;
}

提出情報

提出日時
問題 E - Middle Point
ユーザ p_b_p_b
言語 C++ (GCC 9.2.1)
得点 2000
コード長 4007 Byte
結果 AC
実行時間 5 ms
メモリ 3692 KiB

コンパイルエラー

./Main.cpp: In function ‘void my_std::print(int)’:
./Main.cpp:33:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   33 |   if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
      |   ^~
./Main.cpp:33:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
   33 |   if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
      |                     ^~
./Main.cpp:35:3: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
   35 |   while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
      |   ^~~~~
./Main.cpp:35:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
   35 |   while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
      |                                       ^~~~
./Main.cpp: In function ‘void Work()’:
./Main.cpp:9:21: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    9 |  #define rep(i,x,y) for (int i=(x);i<=(y);i++)
      |                     ^~~
./Main.cpp:77:2: note: in expansion of macro ‘rep’
   77 |  rep(i,1,n) P[i+n]=P[i],P[i]=P[1]; N=n+n; rep(i,1,tp-1) P[i]=st[i]; n=tp-1;
      |  ^~~
./Main.cpp:77:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   77 |  rep(i,1,n) P[i+n]=P[i],P[i]=P[1]; N=n+n; rep(i,1,tp-1) P[i]=st[i]; n=tp-1;
      |                                    ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:9:21: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    9 |  #define rep(i,x,y) for (int i=(x);i<=(y);i++)
      |                     ^~~
./Main.cpp:114:2: note: in expansion of macro ‘rep’
  114 |  rep(i,2,n-1) w+=Abs(Cross(P[i],P[i+1])); w/=2,++w;
      |  ^~~
./Main.cpp:114:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
  114 |  rep(i,2,n-1) w+=Abs(Cross(P[i],P[i+1])); w/=2,++w;
      |                                         ...

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 2000 / 2000
結果
AC × 2
AC × 94
セット名 テストケース
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, 091.txt, example0.txt, example1.txt
ケース名 結果 実行時間 メモリ
000.txt AC 5 ms 3580 KiB
001.txt AC 2 ms 3576 KiB
002.txt AC 2 ms 3688 KiB
003.txt AC 2 ms 3448 KiB
004.txt AC 1 ms 3624 KiB
005.txt AC 2 ms 3604 KiB
006.txt AC 2 ms 3460 KiB
007.txt AC 2 ms 3444 KiB
008.txt AC 2 ms 3500 KiB
009.txt AC 3 ms 3660 KiB
010.txt AC 2 ms 3600 KiB
011.txt AC 2 ms 3660 KiB
012.txt AC 5 ms 3656 KiB
013.txt AC 2 ms 3552 KiB
014.txt AC 2 ms 3516 KiB
015.txt AC 2 ms 3464 KiB
016.txt AC 3 ms 3476 KiB
017.txt AC 3 ms 3552 KiB
018.txt AC 2 ms 3464 KiB
019.txt AC 2 ms 3520 KiB
020.txt AC 2 ms 3576 KiB
021.txt AC 4 ms 3656 KiB
022.txt AC 2 ms 3448 KiB
023.txt AC 1 ms 3576 KiB
024.txt AC 3 ms 3600 KiB
025.txt AC 2 ms 3584 KiB
026.txt AC 2 ms 3444 KiB
027.txt AC 2 ms 3652 KiB
028.txt AC 2 ms 3552 KiB
029.txt AC 2 ms 3444 KiB
030.txt AC 3 ms 3692 KiB
031.txt AC 2 ms 3628 KiB
032.txt AC 3 ms 3624 KiB
033.txt AC 2 ms 3556 KiB
034.txt AC 2 ms 3688 KiB
035.txt AC 3 ms 3620 KiB
036.txt AC 3 ms 3656 KiB
037.txt AC 2 ms 3656 KiB
038.txt AC 2 ms 3576 KiB
039.txt AC 2 ms 3624 KiB
040.txt AC 5 ms 3628 KiB
041.txt AC 2 ms 3576 KiB
042.txt AC 2 ms 3500 KiB
043.txt AC 4 ms 3624 KiB
044.txt AC 2 ms 3656 KiB
045.txt AC 2 ms 3456 KiB
046.txt AC 2 ms 3624 KiB
047.txt AC 3 ms 3580 KiB
048.txt AC 4 ms 3580 KiB
049.txt AC 2 ms 3688 KiB
050.txt AC 2 ms 3552 KiB
051.txt AC 2 ms 3656 KiB
052.txt AC 2 ms 3660 KiB
053.txt AC 2 ms 3444 KiB
054.txt AC 2 ms 3672 KiB
055.txt AC 3 ms 3516 KiB
056.txt AC 3 ms 3516 KiB
057.txt AC 2 ms 3656 KiB
058.txt AC 2 ms 3692 KiB
059.txt AC 2 ms 3604 KiB
060.txt AC 2 ms 3620 KiB
061.txt AC 2 ms 3628 KiB
062.txt AC 2 ms 3692 KiB
063.txt AC 2 ms 3520 KiB
064.txt AC 2 ms 3692 KiB
065.txt AC 1 ms 3520 KiB
066.txt AC 2 ms 3656 KiB
067.txt AC 2 ms 3452 KiB
068.txt AC 2 ms 3460 KiB
069.txt AC 2 ms 3552 KiB
070.txt AC 3 ms 3496 KiB
071.txt AC 2 ms 3584 KiB
072.txt AC 2 ms 3580 KiB
073.txt AC 2 ms 3600 KiB
074.txt AC 2 ms 3624 KiB
075.txt AC 2 ms 3440 KiB
076.txt AC 2 ms 3624 KiB
077.txt AC 2 ms 3660 KiB
078.txt AC 5 ms 3576 KiB
079.txt AC 2 ms 3688 KiB
080.txt AC 3 ms 3452 KiB
081.txt AC 3 ms 3688 KiB
082.txt AC 4 ms 3624 KiB
083.txt AC 2 ms 3656 KiB
084.txt AC 2 ms 3580 KiB
085.txt AC 3 ms 3620 KiB
086.txt AC 4 ms 3580 KiB
087.txt AC 2 ms 3600 KiB
088.txt AC 4 ms 3688 KiB
089.txt AC 3 ms 3464 KiB
090.txt AC 3 ms 3552 KiB
091.txt AC 3 ms 3460 KiB
example0.txt AC 2 ms 3516 KiB
example1.txt AC 2 ms 3516 KiB