結果

問題 No.2716 Falcon Method
ユーザー ks2mks2m
提出日時 2024-04-05 23:30:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,380 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 5,538 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 189,540 KB
最終ジャッジ日時 2024-04-05 23:31:18
合計ジャッジ時間 26,376 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,088 KB
testcase_01 AC 54 ms
54,108 KB
testcase_02 AC 55 ms
54,132 KB
testcase_03 AC 54 ms
54,096 KB
testcase_04 AC 55 ms
54,084 KB
testcase_05 AC 66 ms
54,124 KB
testcase_06 AC 113 ms
55,392 KB
testcase_07 AC 106 ms
53,300 KB
testcase_08 AC 113 ms
55,540 KB
testcase_09 AC 111 ms
55,260 KB
testcase_10 AC 101 ms
55,244 KB
testcase_11 AC 1,099 ms
189,540 KB
testcase_12 AC 1,064 ms
176,932 KB
testcase_13 AC 945 ms
168,048 KB
testcase_14 AC 1,088 ms
140,128 KB
testcase_15 AC 957 ms
168,512 KB
testcase_16 AC 1,074 ms
140,468 KB
testcase_17 AC 1,161 ms
144,496 KB
testcase_18 AC 1,216 ms
181,572 KB
testcase_19 AC 1,030 ms
136,324 KB
testcase_20 AC 982 ms
184,660 KB
testcase_21 AC 1,060 ms
141,744 KB
testcase_22 AC 1,228 ms
170,584 KB
testcase_23 AC 1,338 ms
170,808 KB
testcase_24 AC 1,155 ms
170,264 KB
testcase_25 AC 54 ms
54,092 KB
testcase_26 AC 55 ms
54,092 KB
testcase_27 AC 1,312 ms
170,656 KB
testcase_28 AC 1,380 ms
170,736 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)];
					d = Math.min(d, inf);
				}
			}
			r = p[i];
			for (int j = 0; j < 31; j++) {
				if ((w[i] >> j & 1) == 1) {
					r += dpr[j][(int) (r % n)];
					r = Math.min(r, inf);
				}
			}
			long ans = Math.min(d + 1, r + 1) % n;
			pw.println(ans);
		}
		pw.flush();
	}
}
0