結果

問題 No.2716 Falcon Method
ユーザー 沙耶花沙耶花
提出日時 2024-04-05 21:41:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 5,298 ms
コンパイル使用メモリ 261,640 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-05 21:42:03
合計ジャッジ時間 10,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 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 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 257 ms
6,676 KB
testcase_12 AC 221 ms
6,676 KB
testcase_13 AC 148 ms
6,676 KB
testcase_14 AC 233 ms
6,676 KB
testcase_15 AC 170 ms
6,676 KB
testcase_16 AC 202 ms
6,676 KB
testcase_17 AC 261 ms
6,676 KB
testcase_18 AC 277 ms
6,676 KB
testcase_19 AC 207 ms
6,676 KB
testcase_20 AC 158 ms
6,676 KB
testcase_21 AC 211 ms
6,676 KB
testcase_22 AC 302 ms
6,784 KB
testcase_23 AC 296 ms
6,784 KB
testcase_24 AC 292 ms
6,784 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 294 ms
6,784 KB
testcase_28 AC 326 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int N,Q;
	cin>>N>>Q;
	
	string S;
	cin>>S;
	
	vector<long long> s0(N+1),s1(N+1);
	for(int i=1;i<=N;i++){
		if(S[i-1]=='D')s0[i]++;
		else s1[i]++;
		s0[i] += s0[i-1];
		s1[i] += s1[i-1];
	}
	
	rep(_,Q){
		int H,W;
		cin>>H>>W;
		int P;
		cin>>P;
		
		long long ok = 0,ng = H+W;
		while(ng-ok>1LL){
			long long mid = (ok+ng)/2;
			long long x = 0,y = 0;
			long long rem = mid;
			if(rem >= N-P){
				x += s0.back() - s0[P];
				y += s1.back() - s1[P];
				rem -= N-P;
			}
			else{
				x += s0[P+rem] - s0[P];
				y += s1[P+rem] - s1[P];
				rem = 0;
			}
			x += s0.back() * (rem/N);
			y += s1.back() * (rem/N);
			rem %= N;
			x += s0[rem];
			y += s1[rem];
			//cout<<mid<<' '<<x<<' '<<y<<endl;
			if(x<H && y<W)ok = mid;
			else ng = mid;
		}
	//	cout<<ok<<endl;
		cout<<(ok+P+1)%N<<endl;
		
		
	}
	
	
	return 0;
}
0