結果
問題 | No.490 yukiソート |
ユーザー |
![]() |
提出日時 | 2017-03-10 23:27:42 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,411 bytes |
コンパイル時間 | 12,387 ms |
コンパイル使用メモリ | 229,860 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 10:25:54 |
合計ジャッジ時間 | 13,747 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
package mainimport ("bufio""fmt""os""strconv")func main() {ns := NewScanner()var n intn = ns.NextInt()a := make([]int, n)for i := 0; i < n; i++ {a[i] = ns.NextInt()}for i := 0; i < 2*n-3; i++ {for p := 0; p < i; p++ {q := i - pif p < q && q <= n-1 {if a[p] > a[q] {a[p], a[q] = a[q], a[p]}}}}// sort.Ints(a)for i, b := range a {fmt.Print(b)if i < len(a)-1 {fmt.Print(" ")} else if i == len(a)-1 {fmt.Print("\n")}}}type Scanner struct {r *bufio.Readerbuf []bytep int}func NewScanner() *Scanner {rdr := bufio.NewReaderSize(os.Stdin, 10000)return &Scanner{r: rdr}}func (s *Scanner) Next() string {s.pre()start := s.pfor ; s.p < len(s.buf); s.p++ {if s.buf[s.p] == ' ' {break}}result := string(s.buf[start:s.p])s.p++return result}func (s *Scanner) NextLine() string {s.pre()start := s.ps.p = len(s.buf)return string(s.buf[start:])}func (s *Scanner) NextInt() int {v, _ := strconv.Atoi(s.Next())return v}func (s *Scanner) NextInt64() int64 {v, _ := strconv.ParseInt(s.Next(), 10, 64)return v}func (s *Scanner) pre() {if s.p >= len(s.buf) {s.readLine()s.p = 0}}func (s *Scanner) readLine() {s.buf = make([]byte, 0)for {l, p, e := s.r.ReadLine()if e != nil {panic(e)}s.buf = append(s.buf, l...)if !p {break}}}