提出 #20011408


ソースコード 拡げる

#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
#include<stdio.h>
#include<string.h>
const double pi=acos(-1.0);
using namespace std;
//using namespace __gnu_pbds;
#define   endl    '\n'
#define   sl(n)     scanf("%lld",&n)
#define   mp      make_pair
#define   pb      push_back
#define   ppb     pop_back
#define   fi      first
#define   se      second
#define   ll      long long
#define   ull     unsigned long long
#define   ld      long double
#define   pii     pair<int, int>
#define   f(i,a,b)  for(ll i = (ll)(a); i < (ll)(b); i++)
#define   rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define   ms(a,b)   memset((a),(b),sizeof(a))
#define   abs(x)    ((x<0)?(-(x)):(x))
#define   MAX     1000005
#define   inf     LLONG_MAX
#define   ninf    LLONG_MIN
#define   MIN     INT_MIN
#define   yeet    return 0;
#define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);

#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long  b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}

//typedef
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
 
int mod = 1e9 +7 ;
int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {if (!a) {x = 0;y = 1;return b;}int64_t x1, y1;int64_t d = extGcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
inline ll addmod(ll a,ll b){a=a%mod+b%mod;if(a>mod)a%=mod;return a;}
inline ll submod(ll a,ll b){a=a%mod-b%mod;if(a<0)a+=mod;return a;}
inline ll mulmod(ll a,ll b){return (a%mod * b%mod)%mod;}

int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};
inline ll exp(ll a,ll b){if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=r*(a%mod);r=(r+mod)%mod;}b/=2;a=(a%mod)*(a%mod);a=(a+mod)%mod;}return (r+mod)%mod;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
uint32 setbits(ll n){uint32 count=0;while (n){n&=(n-1);count++;}return count; }

////**********************************************************************////
long double EPS = 1e-14;

bool isInsideCircle(ld cx, ld cy, ld r, ld x, ld y) {
   ld dist = (x - cx) * (x - cx)  +  (y - cy) * (y - cy);
   if ( dist <= r * r)
      return true;
   else
      return false;
}

int main(){
    ld cx,cy,r;
    cin>>cx>>cy>>r;
    	r+=EPS;

    ll max_up=  r+ cy;
    ll max_down= cy-r;
    ll max_right=cx+r;
    ll max_left= cx-r;
    ll ans=0;
    ll p1=max_left;
    ll p2= max_right;
    
    for(ll i=ceil(cy);i<=max_up;i++){

         while(isInsideCircle(cx,cy,r,p1,i)==false and p1<=p2){
               p1++;
         }
        while(isInsideCircle(cx,cy,r,p2,i)==false and p2>=p1){
               p2--;
         }
        //  cout<<p1<<"  up "<<p2<<endl;
        if(p2>=p1 and isInsideCircle(cx,cy,r,p1,i) and isInsideCircle(cx,cy,r,p2,i))ans+= (p2-p1+1); 
         }
    p1=max_left;
    p2=max_right;
    ll ss= floor(cy);
    if(floor(cy)==ceil(cy))ss-=1;
    for(ll i=ss;i>=max_down;i--){
         while(isInsideCircle(cx,cy,r,p1,i)==false and p1<=p2){
               p1++;
         }
        while(isInsideCircle(cx,cy,r,p2,i)==false  and p2>=p1){
               p2--;
         }
        //  cout<<p1<<"  down "<<p2<<endl;
      if(p2>=p1 and isInsideCircle(cx,cy,r,p1,i) and isInsideCircle(cx,cy,r,p2,i))  ans+= (p2-p1+1); 
    }
    
    cout<<ans<<endl;
    
    
    

	return 0;
}

提出情報

提出日時
問題 D - Circle Lattice Points
ユーザ pro_30
言語 C++ (GCC 9.2.1)
得点 400
コード長 4096 Byte
結果 AC
実行時間 12 ms
メモリ 3744 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 46
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_marginal_00.txt, handmade_marginal_01.txt, handmade_marginal_02.txt, handmade_marginal_03.txt, handmade_marginal_04.txt, handmade_marginal_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_integer_00.txt, random_integer_01.txt, random_integer_02.txt, random_integer_03.txt, random_integer_04.txt, random_integer_05.txt, random_integer_06.txt, random_integer_07.txt, random_integer_08.txt, random_integer_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
extreme_00.txt AC 12 ms 3604 KiB
extreme_01.txt AC 8 ms 3720 KiB
extreme_02.txt AC 8 ms 3732 KiB
extreme_03.txt AC 6 ms 3616 KiB
handmade_00.txt AC 3 ms 3592 KiB
handmade_01.txt AC 2 ms 3708 KiB
handmade_02.txt AC 2 ms 3704 KiB
handmade_marginal_00.txt AC 6 ms 3740 KiB
handmade_marginal_01.txt AC 7 ms 3672 KiB
handmade_marginal_02.txt AC 8 ms 3724 KiB
handmade_marginal_03.txt AC 7 ms 3592 KiB
handmade_marginal_04.txt AC 5 ms 3696 KiB
handmade_marginal_05.txt AC 8 ms 3720 KiB
random_00.txt AC 5 ms 3724 KiB
random_01.txt AC 3 ms 3744 KiB
random_02.txt AC 7 ms 3740 KiB
random_03.txt AC 4 ms 3604 KiB
random_04.txt AC 6 ms 3584 KiB
random_05.txt AC 2 ms 3680 KiB
random_06.txt AC 5 ms 3740 KiB
random_07.txt AC 4 ms 3668 KiB
random_08.txt AC 4 ms 3656 KiB
random_09.txt AC 6 ms 3728 KiB
random_10.txt AC 7 ms 3672 KiB
random_11.txt AC 5 ms 3724 KiB
random_12.txt AC 5 ms 3652 KiB
random_13.txt AC 8 ms 3672 KiB
random_14.txt AC 7 ms 3584 KiB
random_15.txt AC 7 ms 3724 KiB
random_16.txt AC 4 ms 3696 KiB
random_17.txt AC 6 ms 3652 KiB
random_18.txt AC 6 ms 3704 KiB
random_19.txt AC 2 ms 3740 KiB
random_integer_00.txt AC 5 ms 3700 KiB
random_integer_01.txt AC 3 ms 3584 KiB
random_integer_02.txt AC 8 ms 3736 KiB
random_integer_03.txt AC 4 ms 3600 KiB
random_integer_04.txt AC 3 ms 3672 KiB
random_integer_05.txt AC 2 ms 3584 KiB
random_integer_06.txt AC 5 ms 3652 KiB
random_integer_07.txt AC 4 ms 3596 KiB
random_integer_08.txt AC 4 ms 3604 KiB
random_integer_09.txt AC 6 ms 3672 KiB
sample_01.txt AC 2 ms 3744 KiB
sample_02.txt AC 2 ms 3724 KiB
sample_03.txt AC 9 ms 3604 KiB