結果

問題 No.457 (^^*)
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-18 10:03:42
言語 Go
(1.21.3)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 13,331 ms
コンパイル使用メモリ 220,992 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:44:19
合計ジャッジ時間 14,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 54 ms
4,348 KB
testcase_12 AC 60 ms
4,348 KB
testcase_13 AC 100 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 64 ms
4,348 KB
testcase_16 AC 100 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	buf := 10000

	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, buf+1), buf+1)

	sc.Scan()
	s := sc.Text()
	r := []rune(s)

	// fmt.Println(len(s))

	var left, right int
	for i := 0; i < len(r)-4; i++ {
		if r[i] != '(' {
			continue
		}

		c, b, a := 0, -1, -1 // ^の出た回数, 最初に*が出た時の^の数, 最後に*が出た時の^の数
		for j := i + 1; j < len(r); j++ {
			switch r[j] {
			case '^':
				c++
			case '*':
				if b == -1 {
					b = c
				}
				a = c
			case ')':
				// fmt.Println(c, b, a)

				// 左向きが作れるか
				if a >= 2 {
					left++
				}

				// 右向きが作れるか
				if b >= 0 && c-b >= 2 {
					right++
				}
			}
		}
	}

	fmt.Println(left, right)
}
0