結果

問題 No.1469 programing
ユーザー scrappyscrappy
提出日時 2022-10-21 20:44:08
言語 Go
(1.22.1)
結果
AC  
実行時間 9 ms / 3,000 ms
コード長 1,789 bytes
コンパイル時間 10,248 ms
コンパイル使用メモリ 210,020 KB
実行使用メモリ 7,540 KB
最終ジャッジ日時 2023-09-13 21:15:31
合計ジャッジ時間 12,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,264 KB
testcase_01 AC 2 ms
5,264 KB
testcase_02 AC 2 ms
5,264 KB
testcase_03 AC 2 ms
5,268 KB
testcase_04 AC 2 ms
5,268 KB
testcase_05 AC 2 ms
5,264 KB
testcase_06 AC 2 ms
5,264 KB
testcase_07 AC 2 ms
5,264 KB
testcase_08 AC 2 ms
5,264 KB
testcase_09 AC 2 ms
5,268 KB
testcase_10 AC 2 ms
5,264 KB
testcase_11 AC 2 ms
5,264 KB
testcase_12 AC 3 ms
5,268 KB
testcase_13 AC 2 ms
5,264 KB
testcase_14 AC 2 ms
5,268 KB
testcase_15 AC 2 ms
5,264 KB
testcase_16 AC 3 ms
5,268 KB
testcase_17 AC 9 ms
7,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.1469 programing
package main

import (
	"bufio"
	"io"
	"os"
)

func main() {
	Solve()
}

func Solve() {
	cpr := NewComProReader(os.Stdin)
	last := byte(' ')

	wbuf := make([]byte, 5_000_000+2)
	wlen := 0
	for !cpr.EOF {
		for _, b := range cpr.Slice() {
			if last != b {
				wbuf[wlen] = b
				wlen++
			}
			last = b
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	wr.Write(wbuf[:wlen])
	wr.Flush()
}

// ComProReader
const BUFFER_SIZE = 64 * 1024

type ComProReader struct {
	reader *bufio.Reader
	buffer []byte
	length int
	index  int
	EOF    bool
}

func NewComProReader(r io.Reader) *ComProReader {
	cpr := new(ComProReader)
	cpr.reader = bufio.NewReader(r)
	cpr.buffer = make([]byte, BUFFER_SIZE)
	cpr.index = 0
	cpr.length = 0
	cpr.read_next_block()
	return cpr
}

func (cpr *ComProReader) read_next_block() {
	if cpr.index >= cpr.length {
		len, err := cpr.reader.Read(cpr.buffer)
		if err == io.EOF {
			cpr.EOF = true
		} else if err != nil {
			panic(err)
		}
		cpr.index = 0
		cpr.length = len
	}
}

func (cpr *ComProReader) Byte() (result byte) {
	cpr.read_next_block()

	result = cpr.buffer[cpr.index]
	cpr.index++
	return
}

func (cpr *ComProReader) Slice() (result []byte) {
	cpr.read_next_block()

	result = cpr.buffer[cpr.index:cpr.length]
	cpr.index = cpr.length
	return
}

func (cpr *ComProReader) Int() int {
	c := cpr.Byte()
	for c == ' ' || c == '\n' || c == '\t' {
		c = cpr.Byte()
	}

	sign := 1
	if c == '-' {
		sign = -1
		c = cpr.Byte()
	}

	v := 0
	for '0' <= c && c <= '9' {
		v = 10*v + int(c-'0')
		c = cpr.Byte()
	}
	return v * sign
}

func (cpr *ComProReader) Uint() uint {
	c := cpr.Byte()
	for c == ' ' || c == '\n' || c == '\t' {
		c = cpr.Byte()
	}

	v := uint(0)
	for '0' <= c && c <= '9' {
		v = 10*v + uint(c-'0')
		c = cpr.Byte()
	}
	return v
}
0