結果

問題 No.151 セグメントフィッシング
ユーザー tassi_2012
提出日時 2015-02-15 23:45:14
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,380 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 110,300 KB
実行使用メモリ 31,616 KB
最終ジャッジ日時 2024-06-23 20:33:26
合計ジャッジ時間 52,598 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 17 TLE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {
        var str = Console.ReadLine().Split(' ');
        var N = int.Parse(str[0]);
        var Q = int.Parse(str[1]);

        Pool pool = new Pool(N);

        for (int i = 0; i < Q; i++)
        {
            str = Console.ReadLine().Split(' ');
            string x = str[0];
            int y = int.Parse(str[1]);
            long z = long.Parse(str[2]);

            if (x.Equals("C"))
            {
                Console.WriteLine(pool.outputSum(y, (int)z));
            }
            else
            {
                pool.add(x, y, z);
            }
            pool.next();
        }
    }
}

public class Pool
{
    private int length;
    private List<Fish> flist;

    public Pool(int N)
    {
        this.length = N;
        this.flist = new List<Fish>();
    }

    public void add(string direction, int position, long num)
    {
        flist.Add(new Fish(direction, position, num, this.length));
    }

    public void next()
    {
        foreach(Fish fish in flist){
            fish.next();
        }
    }

    public long outputSum(int left, int right)
    {
        long sum = 0;
        foreach (Fish fish in flist)
        {
            int posi = fish.getPosition();
            if (left <= posi && posi < right)
            {
                sum += fish.getNum();
            }
        }
        return sum;
    }
}

public class Fish
{
    private string direction;
    private int position;
    private long num;
    private int length;

    public Fish(string direction, int position, long num, int length)
    {
        this.direction = direction;
        this.position = position;
        this.num = num;
        this.length = length;
    }

    public void next()
    {
        if (direction.Equals("R"))
        {
            if (position + 1 == length)
            {
                direction = "L";
            }
            else
            {
                position++;
            }
        }
        else
        {
            if (position - 1 < 0)
            {
                direction = "R";
            }
            else
            {
                position--;
            }
        }
    }

    public long getNum()
    {
        return this.num;
    }

    public int getPosition()
    {
        return this.position;
    }
}
0