結果
| 問題 |
No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-12-09 02:12:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 162 ms / 3,000 ms |
| コード長 | 1,095 bytes |
| コンパイル時間 | 2,222 ms |
| コンパイル使用メモリ | 199,124 KB |
| 最終ジャッジ日時 | 2025-02-18 09:43:58 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
vector<ll> A[15],B[15];
ll G[28],H[28];
int main(){
int m;
cin>>m;
rep(i,28) cin>>G[i];
rep(i,28) cin>>H[i];
rep(bit,1<<14){
int a=__builtin_popcount(bit);
ll sum=0,sum1=0;
rep(i,14){
if(bit&(1<<i)){
sum=(sum+G[i])%m;
sum1=(sum1+G[i+14])%m;
}
else{
sum=(sum+H[i])%m;
sum1=(sum1+H[i+14])%m;
}
}
A[a].push_back(sum);
B[a].push_back(sum1);
}
rep(i,15) sort(ALL(A[i])),sort(ALL(B[i]));
int q;
cin>>q;
rep(_,q){
int k,x;
cin>>k>>x;
int ans=0;
for(int a=0;a<=14;a++){
if(k-a<0 || k-a>14) continue;
for(auto p:A[a]){
int q=0,r=0;;
if(x>=p) q=upper_bound(ALL(B[k-a]),m-p-1)-lower_bound(ALL(B[k-a]),x-p);
else{
q=upper_bound(ALL(B[k-a]),m-p-1)-B[k-a].begin();
r=B[k-a].end()-lower_bound(ALL(B[k-a]),m-p+x);
}
ans+=q+r;
}
}
cout<<ans<<endl;
}
}
umezo