ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1989. Subpalindromes

WA1
Posted by maxormo 22 Mar 2017 08:18
hell why WA1?
i wanna get my TLE

package main

import (
    "bufio"
    "os"
    "strings"
    "strconv"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)

    buffer, _ := in.ReadString('\n')
    str := []rune(strings.Trim(buffer, "\n"))

    buffer, _ = in.ReadString('\n')
    count, _ := strconv.ParseUint(strings.Trim(buffer, "\n"), 10, 0)
    for k := uint64(0); k < count; k++ {

        buffer, _ = in.ReadString('\n')
        flds := strings.Fields(buffer)

        if []rune(flds[0])[0] == 'c' {
            i, _ := strconv.Atoi(flds[1])
            str[i-1] = []rune(flds[2])[0]
        } else {
            i, _ := strconv.ParseUint(flds[1], 10, 0)
            j, _ := strconv.ParseUint(flds[2], 10, 0)
            if isPali(i-1, j-1, str) {
                out.WriteString("Yes\n")
            } else {
                out.WriteString("No\n")
            }
        }
    }
    out.Flush()
}

func isPali(i, j uint64, str []rune) bool {
    for i < j {

        if str[i] != str[j] {
            return false
        }

        i++
        j--
    }
    return true
}

Edited by author 22.03.2017 08:19

Edited by author 22.03.2017 08:19