結果

問題 No.2716 Falcon Method
ユーザー ゆにぽけゆにぽけ
提出日時 2024-04-05 22:09:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,837 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 131,124 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 22:09:47
合計ジャッジ時間 4,633 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 111 ms
6,676 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 91 ms
6,676 KB
testcase_22 AC 116 ms
6,676 KB
testcase_23 RE -
testcase_24 AC 119 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
	int N,Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	vector<int> D(N + 1),R(N + 1);
	for(int i = 0;i < N;i++)
	{
		D[i + 1] = D[i];
		R[i + 1] = R[i];
		if(S[i] == 'D')
		{
			D[i + 1]++;
		}
		else
		{
			R[i + 1]++;
		}
	}

	auto g = [&](const vector<int> &sum,const int st,int x) -> long long
	{
		long long cnt = 0;
		cnt += (long long) (x / N) * sum[N];
		int r = x % N;
		if(st + r <= N)
		{
			cnt += sum[st + r] - sum[st];
		}
		else
		{
			cnt += sum[N] - sum[st];
			r -= (N - st);
			assert(r > 0);
			cnt += sum[r];
		}
		return cnt;
	};

	auto f = [&](const vector<int> &sum,const int goal,const int st) -> int
	{
		if(sum[N] == 0)
		{
			return (int)2e9;
		}
		int ok = (int)1e9,ng = 0;
		while(ok - ng > 1)
		{
			int mid = (ok + ng) / 2;
			long long cnt = g(sum,st,mid);
			if(cnt >= goal)
			{
				ok = mid;
			}
			else
			{
				ng = mid;
			}
		}
		return ok;
	};
	for(;Q--;)
	{
		int H,W,P;
		cin >> H >> W >> P;
		int h = f(D,H,P),w = f(R,W,P);
		bool sw = false;
		if(h < w);
		else
		{
			assert(h > w);
			sw = true;
			swap(h,w);
			swap(D,R);
			swap(H,W);
		}
		int plus = g(R,P,h);
		P = (P + plus) % N;
		P = (P + H) % N;
		cout << P << "\n";
		if(sw)
		{
			swap(h,w);
			swap(D,R);
			swap(H,W);
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0