提出 #55831310
ソースコード 拡げる
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package main
import (
"bufio"
"errors"
"fmt"
"math"
"os"
"sort"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
func main() {
//bufサイズ以上の文字列入力が必要な場合は拡張すること
buf := make([]byte, 9*1024*1024)
sc.Buffer(buf, bufio.MaxScanTokenSize)
sc.Split(bufio.ScanWords)
n := nextInt()
ans := solve(n)
Print(ans)
}
func solve(n int) string {
if n == 1 {
return "0"
}
w := 9 * 2
cur := 1
digit1 := 0
digit2 := 1
for {
if n < cur+w {
break
}
cur += w
w *= 10
digit1++
digit2 += 2
}
idx := n - cur
//fmt.Println(idx, digit1, digit2)
if idx > w/2 {
idx -= w / 2
digit2++
}
w2 := 1
for i := 0; i < Floor(digit2-1, 2); i++ {
w2 *= 10
}
//idxでdigit2桁の回文を作る
t := strconv.Itoa(w2 + idx - 1)
ans := "" + t
for i := 0; i < len(t); i++ {
if i == 0 && digit2%2 == 1 {
continue
}
//fmt.Println(i, string(t[i]))
ans += string(t[len(t)-1-i])
}
return ans
}
func nextInt() int {
sc.Scan()
i, _ := strconv.Atoi(sc.Text())
return int(i)
}
func nextIntSlice(n int) []int {
s := make([]int, n)
for i := range s {
s[i] = nextInt()
}
return s
}
func nextFloat64() float64 {
sc.Scan()
f, _ := strconv.ParseFloat(sc.Text(), 64)
return f
}
func nextString() string {
sc.Scan()
return sc.Text()
}
func Print(x any) {
defer out.Flush()
fmt.Fprintln(out, x)
}
func PrintInt(x int) {
defer out.Flush()
fmt.Fprintln(out, x)
}
func PrintFloat64(x float64) {
defer out.Flush()
fmt.Fprintln(out, x)
}
func PrintString(x string) {
defer out.Flush()
fmt.Fprintln(out, x)
}
func PrintHorizonaly(x []int) {
defer out.Flush()
fmt.Fprintf(out, "%d", x[0])
for i := 1; i < len(x); i++ {
fmt.Fprintf(out, " %d", x[i])
}
fmt.Fprintln(out)
}
func PrintVertically(x []int) {
defer out.Flush()
for _, v := range x {
fmt.Fprintln(out, v)
}
}
func Abs(x int) int {
if x < 0 {
return -x
}
return x
}
func Min(x, y int) int {
if x < y {
return x
}
return y
}
func Max(x, y int) int {
if x < y {
return y
}
return x
}
func Floor(x, y int) int {
/*
return x / y
*/
r := (x%y + y) % y
return (x - r) / y
}
func Ceil(x, y int) int {
return (x + y - 1) / y
}
func Sqrt(x int) int {
x2 := int(math.Sqrt(float64(x))) - 1
for (x2+1)*(x2+1) <= x {
x2++
}
return x2
}
// xの平方根の整数部分を計算する
func FloorSqrt(x int) int {
l, r := 0, int(2e9)
for l <= r {
mid := (l + r) / 2
if mid*mid > x {
r = mid - 1
} else {
l = mid + 1
}
}
return r
}
func Gcd(x, y int) int {
if x == 0 {
return y
}
if y == 0 {
return x
}
/*
if x < y {
x, y = y, x
}
*/
return Gcd(y, x%y)
}
func Lcm(x, y int) int {
// x*yのオーバーフロー対策のため先にGcdで割る
// Gcd(x, y)はxの約数のため割り切れる
ret := x / Gcd(x, y)
ret *= y
return ret
}
func Pow(x, y, p int) int {
ret := 1
for y > 0 {
if y%2 == 1 {
ret = ret * x % p
}
y >>= 1
x = x * x % p
}
return ret
}
func Inv(x, p int) int {
return Pow(x, p-2, p)
}
func Permutation(N, K int) int {
v := 1
if 0 < K && K <= N {
for i := 0; i < K; i++ {
v *= (N - i)
}
} else if K > N {
v = 0
}
return v
}
func Factional(N int) int {
return Permutation(N, N-1)
}
func Combination(N, K int) int {
if K == 0 {
return 1
}
if K == 1 {
return N
}
return Combination(N, K-1) * (N + 1 - K) / K
}
type Comb struct {
n, p int
fac []int // Factional(i) mod p
finv []int // 1/Factional(i) mod p
inv []int // 1/i mod p
}
func NewCombination(n, p int) *Comb {
c := new(Comb)
c.n = n
c.p = p
c.fac = make([]int, n+1)
c.finv = make([]int, n+1)
c.inv = make([]int, n+1)
c.fac[0] = 1
c.fac[1] = 1
c.finv[0] = 1
c.finv[1] = 1
c.inv[1] = 1
for i := 2; i <= n; i++ {
c.fac[i] = c.fac[i-1] * i % p
c.inv[i] = p - c.inv[p%i]*(p/i)%p
c.finv[i] = c.finv[i-1] * c.inv[i] % p
}
return c
}
func (c *Comb) Factional(x int) int {
return c.fac[x]
}
func (c *Comb) Combination(n, k int) int {
if n < k {
return 0
}
if n < 0 || k < 0 {
return 0
}
ret := c.fac[n] * c.finv[k]
ret %= c.p
ret *= c.finv[n-k]
ret %= c.p
return ret
}
// 重複組み合わせ H
func (c *Comb) DuplicateCombination(n, k int) int {
return c.Combination(n+k-1, k)
}
func (c *Comb) Inv(x int) int {
return c.inv[x]
}
func NextPermutation(x sort.Interface) bool {
n := x.Len() - 1
if n < 1 {
return false
}
j := n - 1
for ; !x.Less(j, j+1); j-- {
if j == 0 {
return false
}
}
l := n
for !x.Less(j, l) {
l--
}
x.Swap(j, l)
for k, l := j+1, n; k < l; {
x.Swap(k, l)
k++
l--
}
return true
}
func DivideSlice(A []int, K int) ([]int, []int, error) {
if len(A) < K {
return nil, nil, errors.New("")
}
return A[:K+1], A[K:], nil
}
提出情報
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
350 / 350 |
結果 |
|
|
セット名 |
テストケース |
Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 02_random_2_05.txt, 02_random_2_06.txt, 02_random_2_07.txt, 02_random_2_08.txt, 02_random_2_09.txt, 03_max_00.txt, 04_min_00.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
00_sample_00.txt |
AC |
1 ms |
1752 KB |
00_sample_01.txt |
AC |
1 ms |
1752 KB |
00_sample_02.txt |
AC |
1 ms |
1768 KB |
01_random_1_00.txt |
AC |
1 ms |
1768 KB |
01_random_1_01.txt |
AC |
1 ms |
1768 KB |
01_random_1_02.txt |
AC |
1 ms |
1768 KB |
01_random_1_03.txt |
AC |
1 ms |
1768 KB |
01_random_1_04.txt |
AC |
1 ms |
1768 KB |
02_random_2_00.txt |
AC |
1 ms |
1756 KB |
02_random_2_01.txt |
AC |
1 ms |
1756 KB |
02_random_2_02.txt |
AC |
1 ms |
1756 KB |
02_random_2_03.txt |
AC |
1 ms |
1752 KB |
02_random_2_04.txt |
AC |
1 ms |
1752 KB |
02_random_2_05.txt |
AC |
1 ms |
1768 KB |
02_random_2_06.txt |
AC |
1 ms |
1756 KB |
02_random_2_07.txt |
AC |
1 ms |
1752 KB |
02_random_2_08.txt |
AC |
1 ms |
1756 KB |
02_random_2_09.txt |
AC |
1 ms |
1768 KB |
03_max_00.txt |
AC |
1 ms |
1768 KB |
04_min_00.txt |
AC |
1 ms |
1752 KB |