結果

問題 No.151 セグメントフィッシング
ユーザー haruki_57haruki_57
提出日時 2015-02-14 13:08:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,677 ms / 5,000 ms
コード長 2,158 bytes
コンパイル時間 3,524 ms
コンパイル使用メモリ 75,196 KB
実行使用メモリ 55,844 KB
最終ジャッジ日時 2023-09-06 01:01:35
合計ジャッジ時間 21,739 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
48,852 KB
testcase_01 AC 41 ms
48,668 KB
testcase_02 AC 42 ms
48,532 KB
testcase_03 AC 41 ms
48,612 KB
testcase_04 AC 40 ms
48,836 KB
testcase_05 AC 44 ms
49,308 KB
testcase_06 AC 45 ms
48,984 KB
testcase_07 AC 46 ms
48,804 KB
testcase_08 AC 218 ms
52,916 KB
testcase_09 AC 214 ms
54,708 KB
testcase_10 AC 246 ms
55,068 KB
testcase_11 AC 255 ms
55,276 KB
testcase_12 AC 1,462 ms
55,044 KB
testcase_13 AC 1,476 ms
55,676 KB
testcase_14 AC 1,525 ms
55,088 KB
testcase_15 AC 1,491 ms
55,244 KB
testcase_16 AC 1,506 ms
55,336 KB
testcase_17 AC 1,119 ms
52,900 KB
testcase_18 AC 1,117 ms
52,976 KB
testcase_19 AC 1,677 ms
55,032 KB
testcase_20 AC 1,674 ms
55,844 KB
testcase_21 AC 1,196 ms
55,108 KB
testcase_22 AC 1,173 ms
55,084 KB
testcase_23 AC 191 ms
53,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class SegmentFishing {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        int N = NI();
        int Q = NI();
        long[][] seg = new long[N][2];
        StringBuilder sb=new StringBuilder();
        while(Q-->0){
            char c = NC();
            int y = NI();
            int z = NI();
            if(c=='L'){
                seg[y][1]+=z;
            } else if(c=='R'){
                seg[y][0]+=z;
            } else {
                long sum =0;
                for (int i = y; i < z; i++) {
                    sum += seg[i][0]+seg[i][1];
                }
                /*
                for (int i = 0; i < 2; i++) {
                    for (int j = 0; j < seg.length; j++) {
                        System.out.print(seg[j][i]+" ");
                    }
                    System.out.println();
                }
                System.out.println(sum);
                */
                sb.append(sum);
                sb.append('\n');
            }
            
            move(seg);
        }
        System.out.print(sb);
    }
    static void move(long[][] seg){
        long right = seg[seg.length-1][0];
        long left  = seg[0][1];
        // right
        for (int i = seg.length-2; i >= 0; i--) {
            seg[i+1][0] = seg[i][0];
        }
        
        // left
        for (int i = 1;i<seg.length;i++){
            seg[i-1][1] = seg[i][1];
        }
        
        seg[seg.length-1][1] = right;
        seg[0][0] = left;
    }
    static int NI(){
        try {
            int c=System.in.read(),r=0;
            for(;c!='-'&&(c<'0'||'9'<c);)c=System.in.read();
            if(c=='-') return -NI();
            for(;'0'<=c&&c<='9';c=System.in.read())
                r = r * 10 + c - '0';
            return r;
        } catch (Exception e) {
            return -1;
        }
    }
    
    static char NC(){
        try {
            char c=(char)System.in.read();
            for(;c==' '||c=='\n';)c=(char)System.in.read();
            return c;
        } catch (Exception e) {
            return 0;
        }
    }
}
0