結果

問題 No.151 セグメントフィッシング
ユーザー haruki_57haruki_57
提出日時 2015-02-14 13:06:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,157 bytes
コンパイル時間 3,263 ms
コンパイル使用メモリ 74,008 KB
実行使用メモリ 56,544 KB
最終ジャッジ日時 2023-09-06 00:59:13
合計ジャッジ時間 21,574 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
48,996 KB
testcase_01 AC 40 ms
49,100 KB
testcase_02 AC 41 ms
48,988 KB
testcase_03 AC 40 ms
49,104 KB
testcase_04 AC 41 ms
48,792 KB
testcase_05 AC 44 ms
49,436 KB
testcase_06 AC 46 ms
49,164 KB
testcase_07 AC 45 ms
48,960 KB
testcase_08 AC 212 ms
54,628 KB
testcase_09 AC 215 ms
54,492 KB
testcase_10 AC 234 ms
54,780 KB
testcase_11 AC 238 ms
54,648 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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 {
                int 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