結果

問題 No.2716 Falcon Method
ユーザー ks2mks2m
提出日時 2024-04-05 23:27:37
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,841 bytes
コンパイル時間 7,758 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 184,764 KB
最終ジャッジ日時 2024-04-05 23:29:24
合計ジャッジ時間 28,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,136 KB
testcase_01 AC 54 ms
52,124 KB
testcase_02 AC 54 ms
54,100 KB
testcase_03 AC 55 ms
54,116 KB
testcase_04 AC 56 ms
54,108 KB
testcase_05 AC 55 ms
54,132 KB
testcase_06 AC 106 ms
55,324 KB
testcase_07 AC 108 ms
55,648 KB
testcase_08 AC 106 ms
55,364 KB
testcase_09 AC 117 ms
55,400 KB
testcase_10 AC 108 ms
55,268 KB
testcase_11 RE -
testcase_12 AC 1,120 ms
176,996 KB
testcase_13 AC 966 ms
168,072 KB
testcase_14 AC 1,134 ms
140,476 KB
testcase_15 AC 963 ms
170,556 KB
testcase_16 AC 1,062 ms
140,524 KB
testcase_17 AC 1,161 ms
144,900 KB
testcase_18 AC 1,256 ms
150,932 KB
testcase_19 AC 1,101 ms
136,740 KB
testcase_20 AC 953 ms
184,764 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 1,398 ms
170,380 KB
testcase_24 RE -
testcase_25 AC 57 ms
54,112 KB
testcase_26 AC 53 ms
54,120 KB
testcase_27 AC 1,400 ms
170,396 KB
testcase_28 AC 1,392 ms
170,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		char[] s = br.readLine().toCharArray();
		int[] h = new int[q];
		int[] w = new int[q];
		int[] p = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			h[i] = Integer.parseInt(sa[0]);
			w[i] = Integer.parseInt(sa[1]);
			p[i] = Integer.parseInt(sa[2]);
		}
		br.close();

		long[][] dpd = new long[31][n];
		long[][] dpr = new long[31][n];
		long inf = 1000000000000000000L;
		long d = inf;
		long r = inf;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'D') {
				d = n + i;
				break;
			}
		}
		for (int i = 0; i < n; i++) {
			if (s[i] == 'R') {
				r = n + i;
				break;
			}
		}
		for (int i = n - 1; i >= 0; i--) {
			dpd[0][i] = d - i;
			dpr[0][i] = r - i;
			if (s[i] == 'D') {
				d = i;
			} else {
				r = i;
			}
		}

		for (int i = 0; i < 30; i++) {
			for (int j = 0; j < n; j++) {
				dpd[i + 1][j] = dpd[i][j] + dpd[i][(int) ((j + dpd[i][j]) % n)];
				dpr[i + 1][j] = dpr[i][j] + dpr[i][(int) ((j + dpr[i][j]) % n)];
				dpd[i + 1][j] = Math.min(dpd[i + 1][j], inf);
				dpr[i + 1][j] = Math.min(dpr[i + 1][j], inf);
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			if (s[p[i]] == 'D') {
				h[i]--;
			} else {
				w[i]--;
			}
			d = p[i];
			for (int j = 0; j < 31; j++) {
				if ((h[i] >> j & 1) == 1) {
					d += dpd[j][(int) (d % n)];
				}
			}
			r = p[i];
			for (int j = 0; j < 31; j++) {
				if ((w[i] >> j & 1) == 1) {
					r += dpr[j][(int) (r % n)];
				}
			}
			long ans = Math.min(d + 1, r + 1) % n;
			pw.println(ans);
		}
		pw.flush();
	}
}
0