結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー shobonvipshobonvip
提出日時 2024-02-23 21:35:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 208,428 KB
実行使用メモリ 11,932 KB
最終ジャッジ日時 2024-02-23 21:35:33
合計ジャッジ時間 6,400 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 202 ms
6,676 KB
testcase_02 AC 202 ms
6,676 KB
testcase_03 AC 205 ms
6,676 KB
testcase_04 AC 202 ms
6,676 KB
testcase_05 AC 316 ms
6,676 KB
testcase_06 AC 340 ms
6,676 KB
testcase_07 AC 18 ms
6,676 KB
testcase_08 AC 18 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 6 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 25 ms
7,264 KB
testcase_14 AC 25 ms
7,108 KB
testcase_15 AC 25 ms
6,800 KB
testcase_16 AC 24 ms
6,676 KB
testcase_17 AC 27 ms
10,356 KB
testcase_18 AC 25 ms
7,472 KB
testcase_19 AC 26 ms
8,308 KB
testcase_20 AC 28 ms
9,696 KB
testcase_21 AC 27 ms
8,592 KB
testcase_22 AC 25 ms
8,136 KB
testcase_23 AC 28 ms
11,932 KB
testcase_24 AC 27 ms
9,860 KB
testcase_25 AC 27 ms
9,860 KB
testcase_26 AC 27 ms
9,860 KB
testcase_27 AC 28 ms
11,932 KB
testcase_28 AC 28 ms
11,932 KB
testcase_29 AC 27 ms
9,860 KB
testcase_30 AC 27 ms
9,860 KB
testcase_31 AC 28 ms
9,860 KB
testcase_32 AC 28 ms
11,932 KB
testcase_33 AC 27 ms
9,860 KB
testcase_34 AC 187 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

void solve(){
	string s; cin >> s;
	vector<int> x;
	rep(i,0,(int)s.size()){
		x.push_back(s[i] - '0');
	}
	
	auto increment = [&](vector<int> x) -> vector<int> {
		vector<int> y;
		int up = 1;
		rrep(i,0,(int)x.size()){
			if (up == 0){
				y.push_back(x[i]);
			}else{
				if (x[i] + up >= 10){
					y.push_back(0);
				}else{
					y.push_back(x[i] + up);
					up = 0;
				}
			}
		}
		if (up == 1){
			y.push_back(1);
		}
		reverse(y.begin(), y.end());
		return y;
	};

	auto half = [&](vector<int> x) -> vector<int> {
		assert(x.back() % 2 == 0);
		vector<int> y = x;
		vector<int> z((int)y.size());
		rep(i,0,(int)x.size()){
			z[i] = y[i] / 2;
			if (i < (int)x.size() - 1){
				y[i] %= 2;
				y[i+1] += y[i] * 10;
			}
		}
		return z;
	};

	
	
	int m; cin >> m;
	ll tar1 = 0;
	ll tar2 = 0;
	if (x.back() % 2 == 1){
		rep(i,0,(int)x.size()){
			tar1 = (tar1 * 10 + x[i]) % m;
		}
		x = increment(x);
		x = half(x);
		rep(i,0,(int)x.size()){
			tar2 = (tar2 * 10 + x[i]) % m;
		}
	}else{
		vector<int> y = half(x);
		rep(i,0,(int)y.size()){
			tar1 = (tar1 * 10 + y[i]) % m;

		}
		x = increment(x);
		rep(i,0,(int)x.size()){
			tar2 = (tar2 * 10 + x[i]) % m;

		}
	}
	cout << tar1 * tar2 % m << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t; cin >> t;
	while(t--) solve();
}

0