Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b571a65

Browse files
committed
ABC191-D
1 parent 53fec8e commit b571a65

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

‎abc/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,14 @@
438438
* [x] D - Hachi
439439
* [ ] E - Transformable Teacher
440440
* [ ] F - Silver Woods
441+
442+
## AtCoder Beginner Contest 191
443+
444+
<https://atcoder.jp/contests/abc191>
445+
446+
* [ ] A - Vanishing Pitch
447+
* [ ] B - Remove It
448+
* [ ] C - Digital Graffiti
449+
* [x] D - Circle Lattice Points
450+
* [ ] E - Come Back Quickly
451+
* [ ] F - GCD or MIN

‎abc/abc191-d/Main.hs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- https://github.com/minoki/my-atcoder-solutions
2+
{-# LANGUAGE TypeApplications #-}
3+
{-# LANGUAGE BangPatterns #-}
4+
import Data.Int (Int64)
5+
import qualified Data.ByteString.Char8 as BS
6+
import Data.Ratio
7+
8+
main = do
9+
[cx,cy,r] <- map (read @Double . BS.unpack) . BS.words <$> BS.getLine
10+
let cx4, cy4, r4 :: Int64
11+
cx4 = round (cx * 10^4)
12+
cy4 = round (cy * 10^4)
13+
r4 = round (r * 10^4)
14+
isInside x y = (10^4 * x - cx4)^2 + (10^4 * y - cy4)^2 <= r4^2
15+
minX = ceiling $ (cx4 - r4) % (10^4)
16+
maxX = floor $ (cx4 + r4) % (10^4)
17+
go1 !acc !x !yB !yT | x > maxX = acc
18+
| otherwise = let yB' = if isInside x yB then
19+
let go !y | isInside x (y - 1) = go (y - 1)
20+
| otherwise = y
21+
in go yB
22+
else
23+
let go !y | isInside x (y + 1) = y + 1
24+
| y > yT = y
25+
| otherwise = go (y + 1)
26+
in go yB
27+
yT' = if isInside x yT then
28+
let go !y | isInside x (y + 1) = go (y + 1)
29+
| otherwise = y
30+
in go yT
31+
else
32+
let go !y | isInside x (y - 1) = y - 1
33+
| y < yB = y
34+
| otherwise = go (y - 1)
35+
in go yT
36+
in if yT' < yB' then
37+
acc
38+
else
39+
go1 (acc + yT' - yB' + 1) (x + 1) yB' yT'
40+
y0 = round cy
41+
go0 !x | x > maxX = 0
42+
| otherwise = if isInside x y0 then
43+
go1 0 x y0 y0
44+
else
45+
go0 (x + 1)
46+
print $ go0 minX

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /