結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー daiotadaiota
提出日時 2023-12-09 12:01:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 3,000 ms
コード長 1,330 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 174,812 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-09 12:01:58
合計ジャッジ時間 6,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,676 KB
testcase_01 AC 11 ms
6,676 KB
testcase_02 AC 20 ms
6,676 KB
testcase_03 AC 98 ms
6,676 KB
testcase_04 AC 60 ms
6,676 KB
testcase_05 AC 16 ms
6,676 KB
testcase_06 AC 83 ms
6,676 KB
testcase_07 AC 81 ms
6,676 KB
testcase_08 AC 24 ms
6,676 KB
testcase_09 AC 54 ms
6,676 KB
testcase_10 AC 78 ms
6,676 KB
testcase_11 AC 21 ms
6,676 KB
testcase_12 AC 101 ms
6,676 KB
testcase_13 AC 117 ms
6,676 KB
testcase_14 AC 98 ms
6,676 KB
testcase_15 AC 93 ms
6,676 KB
testcase_16 AC 96 ms
6,676 KB
testcase_17 AC 97 ms
6,676 KB
testcase_18 AC 112 ms
6,676 KB
testcase_19 AC 122 ms
6,676 KB
testcase_20 AC 120 ms
6,676 KB
testcase_21 AC 121 ms
6,676 KB
testcase_22 AC 294 ms
6,676 KB
testcase_23 AC 293 ms
6,676 KB
testcase_24 AC 283 ms
6,676 KB
testcase_25 AC 280 ms
6,676 KB
testcase_26 AC 284 ms
6,676 KB
testcase_27 AC 11 ms
6,676 KB
testcase_28 AC 10 ms
6,676 KB
testcase_29 AC 239 ms
6,676 KB
testcase_30 AC 50 ms
6,676 KB
testcase_31 AC 103 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)


ll g[30],h[30];
vector<ll> a[20],b[20];

int main(){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j;

	ll M;
	cin >> M;
	for(i=1;i<=28;i++) cin >> g[i];
	for(i=1;i<=28;i++) cin >> h[i];
	int Q;
	cin >> Q;

	for(i=0;i<(1LL<<14);i++){
		ll c=0;
		ll s=0;
		for(j=0;j<14;j++){
			if(i & (1LL<<j)){
				c++;
				s+=g[j+1];
				s%=M;
		   }else{
			    s+=h[j+1];
			    s%=M;
		   }
		}

		a[c].push_back(s);
	}

	for(i=0;i<(1LL<<14);i++){
		ll c=0;
		ll s=0;
		for(j=0;j<14;j++){
			if(i & (1LL<<j)){
				c++;
				s+=g[j+15];
				s%=M;

		   }else{
			    s+=h[j+15];
			    s%=M;

		   }
		}

		b[c].push_back(s);
	}

	REP(i,15) sort(b[i].begin(),b[i].end());


	while(Q--){

		ll K,X;
		cin >> K >> X;


		ll d=0;
		REP(i,15){
			REP(j,15){
				if((i+j)!=K) continue;

				ll n=a[i].size();
				REP(k,n){

					ll p=a[i][k];

				    ll x=lower_bound(b[j].begin(),b[j].end(),X-p)-b[j].begin();
					ll y=upper_bound(b[j].begin(),b[j].end(),M-p-1)-b[j].begin();

					ll z=lower_bound(b[j].begin(),b[j].end(),M+X-p)-b[j].begin();
					ll u=upper_bound(b[j].begin(),b[j].end(),2*M-p-1)-b[j].begin();

					d+=y-x+u-z;

				}

			}
		}

		cout << d << endl;


	}


    return 0;
}
0