結果

問題 No.2716 Falcon Method
ユーザー ks2mks2m
提出日時 2024-04-05 23:23:23
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,740 bytes
コンパイル時間 2,779 ms
コンパイル使用メモリ 77,232 KB
実行使用メモリ 182,940 KB
最終ジャッジ日時 2024-04-05 23:23:46
合計ジャッジ時間 21,139 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
54,108 KB
testcase_01 RE -
testcase_02 AC 55 ms
54,120 KB
testcase_03 AC 54 ms
54,108 KB
testcase_04 AC 54 ms
54,112 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 108 ms
55,408 KB
testcase_08 AC 94 ms
55,272 KB
testcase_09 AC 93 ms
55,264 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 1,030 ms
177,412 KB
testcase_13 AC 930 ms
167,888 KB
testcase_14 AC 1,042 ms
139,716 KB
testcase_15 AC 957 ms
170,072 KB
testcase_16 AC 1,088 ms
140,696 KB
testcase_17 AC 1,027 ms
144,400 KB
testcase_18 AC 1,196 ms
148,116 KB
testcase_19 AC 1,073 ms
136,400 KB
testcase_20 AC 991 ms
182,940 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 1,343 ms
170,356 KB
testcase_24 RE -
testcase_25 AC 54 ms
54,120 KB
testcase_26 AC 55 ms
54,112 KB
testcase_27 AC 1,347 ms
170,324 KB
testcase_28 AC 1,340 ms
170,684 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 d = 1000000000000000000L;
		long r = 1000000000000000000L;
		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)];
			}
		}

		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