Help us understand the problem. What is going on with this article?

paiza POH enkoi #_poh

https://github.com/cielavenir/paiza_solutions/tree/master/poh4

今まではAC==Sランクだったが、今回はBランクらしい。
問題としてもあまり楽しめなかった。
この記事も、あくまで言語ごとの性能評価という扱い。

ミッション1・2は省略して、ミッション3のタイム。

現在26言語でAC済。 タイム(case4/5) URL
C/C++/ObjC 0.01s/0.01s
0.01s/0.01s
0.02s/0.01s
https://paiza.jp/poh/enkoi-ending/4058404b
https://paiza.jp/poh/enkoi-ending/ee5390ad
https://paiza.jp/poh/enkoi-ending/034f0d12
D 0.01s/0.01s https://paiza.jp/poh/enkoi-ending/984f3db8
C# 0.03s/0.03s https://paiza.jp/poh/enkoi-ending/9d333310
Rust 0.04s/0.04s https://paiza.jp/poh/enkoi-ending/af74f725
VB 0.04s/0.07s https://paiza.jp/poh/enkoi-ending/8993e328
Swift 0.08s/0.08s https://paiza.jp/poh/enkoi-ending/bf59ca8b
Go 0.09s/0.04s https://paiza.jp/poh/enkoi-ending/8b5e0132
Java 0.09s/0.09s https://paiza.jp/poh/enkoi-ending/eed8da2f
F# 0.12s/0.12s https://paiza.jp/poh/enkoi-ending/fe2c17f8
JavaScript 0.12s/0.12s https://paiza.jp/poh/enkoi-ending/1fe48ee2
Kotlin 0.13s/0.12s https://paiza.jp/poh/enkoi-ending/e4c00084
Scheme 0.17s/0.17s https://paiza.jp/poh/enkoi-ending/1fceff14
Perl 0.18s/0.20s https://paiza.jp/poh/enkoi-ending/e7516df5
Bash 0.19s/0.38s https://paiza.jp/poh/enkoi-ending/05db0f91
Ruby 0.19s/0.19s https://paiza.jp/poh/enkoi-ending/7db8a4ad
CoffeeScript 0.20s/0.20s https://paiza.jp/poh/enkoi-ending/a13c0c79
PHP 0.23s/0.23s https://paiza.jp/poh/enkoi-ending/1bee54a4
Python2/Python3 0.51s/0.51s
0.84s/0.82s
https://paiza.jp/poh/enkoi-ending/764a0097
https://paiza.jp/poh/enkoi-ending/76852f1c
Scala 0.52s/0.52s https://paiza.jp/poh/enkoi-ending/193d1632
R 0.86s/0.90s https://paiza.jp/poh/enkoi-ending/55aad911
Haskell 1.77s/1.77s https://paiza.jp/poh/enkoi-ending/95581aa8
Elixir 1.79s/1.81s https://paiza.jp/poh/enkoi-ending/e0591fb4
Clojure 1.95s/1.90s https://paiza.jp/poh/enkoi-ending/1ce7cde8

Erlang/COBOLは省略。

で、C/C++/ObjC/D/C#/VB/JavaでIOゲー実施。今回IOゲーの有無で如実に時間に差が出た。静的型付け言語が大きく有利になってしまうため、性能評価としては宜しくない。

とりあえずQiitaにはIOゲーしたものを掲載。あとはgithub参照。

C

paizapoh4.c
#include <stdio.h>
char z[9999999];
int get(){
    static int input_count=0;
    int r=0;
    for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
    input_count++;
    return r;
}

int a[300000];
int main(){
    fread(z,1,sizeof(z),stdin);
    int T,N,i,cur=0;
    //scanf("%d%d",&T,&N);
    T=get();N=get();
    for(i=0;i<T;i++)a[i]=get(),cur+=a[i];
    int r=cur;
    for(;i<N;i++){
        a[i]=get();
        cur+=a[i];
        cur-=a[i-T];
        if(r<cur)r=cur;
    }
    printf("%d\n",r);
    return 0;
}

D

paizapoh4.d
#!/usr/bin/rdmd
import std.stdio;
char z[9999999];
int get(){
    static int input_count=0;
    int r=0;
    for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
    input_count++;
    return r;
}

int main(){
    stdin.rawRead(z);
    int T,N,i,cur=0;
    T=get();N=get();
    int[] a=new int[N];
    for(i=0;i<T;i++)a[i]=get(),cur+=a[i];
    int r=cur;
    for(;i<N;i++){
        a[i]=get();
        cur+=a[i];
        cur-=a[i-T];
        if(r<cur)r=cur;
    }
    printf("%d\n",r);
    return 0;
}

C#

paizapoh4.cs
using System;
using System.Linq;
class PaizaPOH4{
    const int SIZE=9999999;
    static byte[] z=new byte[SIZE];
    static int input_count=0;

    static int get(){
        int r=0;
        for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
        input_count++;
        return r;
    }
    static void Main(){
        Console.OpenStandardInput().Read(z,0,SIZE);
        int T,N,i,cur=0;
        T=get();N=get();
        int[] a=new int[N];
        for(i=0;i<T;i++){a[i]=get();cur+=a[i];}
        int r=cur;
        for(;i<N;i++){
            a[i]=get();
            cur+=a[i];
            cur-=a[i-T];
            if(r<cur)r=cur;
        }
        Console.WriteLine(r);
    }
}

VB

paizapoh4.vb
module PaizaPOH4
    dim SIZE as integer=9999999
    dim z(SIZE-1) as byte
    dim input_count as integer=0

    function myget() as integer
        dim r as integer
        while 48<=z(input_count) andalso z(input_count)<=57
            r=r*10+z(input_count)-48
            input_count+=1
        end while
        input_count+=1
        return r
    end function

    sub Main()
        Console.OpenStandardInput().Read(z,0,SIZE)

        dim T as integer=myget()
        dim N as integer=myget()
        dim cur as integer=0
        dim a(N-1) as integer
        for i as integer=0 to T-1
            a(i)=myget()
            cur+=a(i)
        next
        dim r as integer=cur
        for i as integer=T to N-1
            a(i)=myget()
            cur+=a(i)
            cur-=a(i-T)
            if r<cur
                r=cur
            end if
        next
        Console.WriteLine(r)
    end sub
end module

Java

paizapoh4.java
//import java.util.*;
class Main{
    static final int SIZE=9999999;
    static byte[] z=new byte[SIZE];
    static int input_count=0;

    static int get(){
        int r=0;
        for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
        input_count++;
        return r;
    }
    public static void main(String[]args){try{
        System.in.read(z,0,SIZE);
        int T,N,i,cur=0;
        T=get();N=get();
        int[] a=new int[N];
        for(i=0;i<T;i++){a[i]=get();cur+=a[i];}
        int r=cur;
        for(;i<N;i++){
            a[i]=get();
            cur+=a[i];
            cur-=a[i-T];
            if(r<cur)r=cur;
        }
        System.out.println(r);
    }catch(java.io.IOException e){}}
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away