結果

問題 No.2716 Falcon Method
ユーザー pengin_2000pengin_2000
提出日時 2024-04-05 22:38:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 8,272 KB
最終ジャッジ日時 2024-04-05 22:38:31
合計ジャッジ時間 3,464 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 105 ms
8,132 KB
testcase_12 AC 81 ms
8,132 KB
testcase_13 AC 63 ms
8,136 KB
testcase_14 AC 90 ms
7,592 KB
testcase_15 AC 65 ms
8,000 KB
testcase_16 AC 73 ms
7,592 KB
testcase_17 AC 88 ms
7,728 KB
testcase_18 AC 103 ms
7,864 KB
testcase_19 AC 72 ms
7,588 KB
testcase_20 AC 62 ms
7,996 KB
testcase_21 AC 79 ms
7,724 KB
testcase_22 AC 104 ms
8,272 KB
testcase_23 AC 106 ms
8,272 KB
testcase_24 AC 104 ms
8,272 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 109 ms
8,272 KB
testcase_28 AC 107 ms
8,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
char s[200005];
long long int x[400005], y[400005];
int main()
{
	long long int n, q;
	scanf("%lld %lld", &n, &q);
	scanf("%s", s);
	long long int i;
	x[0] = y[0] = 0;
	for (i = 0; i < n; i++)
	{
		x[i + 1] = x[i];
		y[i + 1] = y[i];
		if (s[i] == 'D')
			x[i + 1]++;
		else
			y[i + 1]++;
	}
	for (i = 0; i < n; i++)
	{
		x[i + 1 + n] = x[i + n];
		y[i + 1 + n] = y[i + n];
		if (s[i] == 'D')
			x[i + 1 + n]++;
		else
			y[i + 1 + n]++;
	}
	long long int min, mid, max;
	long long int h, w, p;
	long long int f1, f2, f;
	for (i = 0; i < q; i++)
	{
		scanf("%lld %lld %lld", &h, &w, &p);
		if (x[n] > 0)
			f1 = (h - 1) / x[n];
		else
			f1 = 1e18;
		if (y[n] > 0)
			f2 = (w - 1) / y[n];
		else
			f2 = 1e18;
		if (f1 < f2)
			f = f1;
		else
			f = f2;
		h -= x[n] * f;
		w -= y[n] * f;
		if (h > x[n] && w > y[n])
		{
			h -= x[n];
			w -= y[n];
		}
		min = p;
		max = 2 * n;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (x[mid] - x[p] < h && y[mid] - y[p] < w)
				min = mid;
			else
				max = mid;
		}
		printf("%lld\n", max % n);
	}
	return 0;
}
0