メモ帳

楽しいアウトプットの場所

ABC197 A, B, C, D問題をNim言語で解く

atcoder.jp

let s = stdin.readLine
echo s[1..2] & s[0]

atcoder.jp

import sequtils, strutils, strformat, algorithm, math, sugar

var
  h, w, x, y, ans: int

(h, w, x, y) = stdin.readLine.split.map(parseInt)
let s = (0..<h).mapIt(stdin.readLine)

x-=1
y-=1
ans = 0

if s[x][y]=='.': ans+=1

for j in y+1..<w:
  if s[x][j]=='#': break
  else: ans+=1

for j in 1..y:
  if s[x][y-j]=='#': break
  else: ans+=1

for i in x+1..<h:
  if s[i][y]=='#': break
  else: ans+=1

for i in 1..x:
  if s[x-i][y]=='#': break
  else: ans+=1

echo ans

atcoder.jp

import sequtils, strutils, strformat, algorithm, math, sugar, complex

let 
    n = stdin.readLine.parseInt()
    A = stdin.readLine.split.map(parseInt)
var ans:int64 = 10000000000000000

for bit in 0..<(1 shl (n-1)):
    var xorSum:int64 = 0
    var orSum:int64 = A[0]
    for i in 0..<(n-1):
        if(bit and (1 shl i)) != 0:
            xorSum = (xorSum xor orSum)
            orSum = A[i+1]
            if i == n-2: xorSum=(xorSum xor A[n-1])
        else:
            orSum=(orSum or A[i+1])
            if i == n-2: xorSum=(xorsum xor orSum)
    if xorSum<ans: ans = xorSum

if n == 1: echo A[0]
else: echo ans

atcoder.jp

import complex, math, strutils, sequtils

var
    x0, y0, x2, y2: float64
var n: float64 = stdin.readLine.parseFloat()
(x0, y0) = stdin.readLine.split.map(parseFloat)
(x2, y2) = stdin.readLine.split.map(parseFloat)

let
    p0 = complex[float64](x0, y0)
    o = complex[float64]((x0+x2)/2, (y0+y2)/2)
    r = rect[float64](1.0, 2*PI/n)

var ans = (p0-o)*r+o
echo ans.re, " ", ans.im