結果

問題 No.2716 Falcon Method
ユーザー tentententen
提出日時 2024-04-08 10:23:12
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,464 bytes
コンパイル時間 6,755 ms
コンパイル使用メモリ 78,732 KB
実行使用メモリ 258,936 KB
最終ジャッジ日時 2024-04-08 10:25:06
合計ジャッジ時間 14,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,968 KB
testcase_01 AC 52 ms
53,972 KB
testcase_02 AC 53 ms
53,980 KB
testcase_03 AC 59 ms
53,980 KB
testcase_04 AC 53 ms
53,976 KB
testcase_05 AC 54 ms
53,964 KB
testcase_06 AC 88 ms
55,016 KB
testcase_07 AC 101 ms
55,260 KB
testcase_08 AC 104 ms
54,996 KB
testcase_09 AC 100 ms
55,112 KB
testcase_10 AC 90 ms
55,156 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[][][] values = new int[30][n][2];
        char[] inputs = sc.next().toCharArray();
        for (int i = 0; i < n; i++) {
            if (inputs[i] == 'D') {
                values[0][i][0]++;
            } else {
                values[0][i][1]++;
            }
        }
        for (int i = 1; i < 30; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < 2; k++) {
                    values[i][j][k] = values[i - 1][j][k] + values[i - 1][(j + (1 << (i - 1))) % n][k];
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            int p = sc.nextInt();
            for (int i = 29; i >= 0; i--) {
                if (values[i][p][0] < h && values[i][p][1] < w) {
                    h -= values[i][p][0];
                    w -= values[i][p][1];
                    p += (1 << i);
                    p %= n;
                }
            }
            while (h > 0 && w > 0) {
                if (inputs[p] == 'D') {
                    h--;
                } else {
                    w--;
                }
                p++;
                p %= n;
            }
            sb.append(p).append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0