ちょっとだけ改良した

package acm.jp2011p

new File(args[1]).withPrintWriter { out -> 
    def xs = []
    def ys = []
    new File(args[0]).splitEachLine(/\s+/){ items ->
        items = items.collect { it.toInteger() }
        if( items.size() == 1 ){
            if( xs.size() > 0 && ys.size() > 0 ) out.println "${xs.max()-xs.min()+1} ${ys.max()-ys.min()+1}"
            xs = [0]; ys = [0]
        } else {
            switch( items[1] ){
            case 0: xs << xs[items[0]]-1; ys << ys[items[0]];   break
            case 1: xs << xs[items[0]];   ys << ys[items[0]]+1; break
            case 2: xs << xs[items[0]]+1; ys << ys[items[0]];   break
            case 3: xs << xs[items[0]];   ys << ys[items[0]]-1; break
            }
        }
    }
}
  • splitするのに、groovyっぽい正規表現記述に変更
  • 文字列の生成にGStringの利用に変更
  • leftShiftの利用に変更
  • closeメソッドを呼ぶ代わりに、withXXXの利用に変更