結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー 👑 kmjpkmjp
提出日時 2024-02-23 21:44:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 3,225 ms
コンパイル使用メモリ 205,872 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 21:44:28
合計ジャッジ時間 8,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 373 ms
6,676 KB
testcase_02 AC 371 ms
6,676 KB
testcase_03 AC 401 ms
6,676 KB
testcase_04 AC 372 ms
6,676 KB
testcase_05 AC 485 ms
6,676 KB
testcase_06 AC 490 ms
6,676 KB
testcase_07 AC 26 ms
6,676 KB
testcase_08 AC 26 ms
6,676 KB
testcase_09 AC 7 ms
6,676 KB
testcase_10 AC 7 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 19 ms
6,676 KB
testcase_14 AC 19 ms
6,676 KB
testcase_15 AC 19 ms
6,676 KB
testcase_16 AC 19 ms
6,676 KB
testcase_17 AC 19 ms
6,676 KB
testcase_18 AC 18 ms
6,676 KB
testcase_19 AC 19 ms
6,676 KB
testcase_20 AC 20 ms
6,676 KB
testcase_21 AC 20 ms
6,676 KB
testcase_22 AC 20 ms
6,676 KB
testcase_23 AC 20 ms
6,676 KB
testcase_24 AC 20 ms
6,676 KB
testcase_25 AC 20 ms
6,676 KB
testcase_26 AC 20 ms
6,676 KB
testcase_27 AC 19 ms
6,676 KB
testcase_28 AC 19 ms
6,676 KB
testcase_29 AC 20 ms
6,676 KB
testcase_30 AC 19 ms
6,676 KB
testcase_31 AC 19 ms
6,676 KB
testcase_32 AC 19 ms
6,676 KB
testcase_33 AC 20 ms
6,676 KB
testcase_34 AC 339 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
int N;
string A;
ll mo;

string incinc(string A) {
	reverse(A.begin(),A.end());
	FORR(r,A) {
		if(r=='9') r='0';
		else {
			r++;
			break;
		}
	}
	if(A.back()=='0') A += '1';
	reverse(A.begin(),A.end());
	return A;
}

string div2(string S) {
	string V;
	int i;
	reverse(ALL(S));
	FOR(i,S.size()) {
		int x=(S[i]-'0')/2;
		if(i+1<S.size()&&S[i+1]%2) x+=5;
		V.push_back('0'+x);
	}
	while(V.size()>1&&V.back()=='0') V.pop_back();
	reverse(ALL(V));
	return V;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		cin>>A>>mo;
		string B=incinc(A);
		if(A.back()%2==0) A=div2(A);
		if(B.back()%2==0) B=div2(B);
		ll x=0,y=0;
		FORR(a,A) x=(x*10+a-'0')%mo;
		FORR(a,B) y=(y*10+a-'0')%mo;
		cout<<(x*y)%mo<<endl;
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0