結果
| 問題 |
No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-12-09 01:58:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 3,000 ms |
| コード長 | 1,338 bytes |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 201,568 KB |
| 最終ジャッジ日時 | 2025-02-18 09:43:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
vector<ll> B[15];
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int m;
cin>>m;
vector<ll> G(28),H(28);
rep(i,28) cin>>G[i];
rep(i,28) cin>>H[i];
for(int bit=0;bit<(1<<14);bit++){
int a=__builtin_popcount(bit);
ll sum=0;
rep(i,14){
if(bit&(1<<i)) sum=(sum+G[i])%m;
else sum=(sum+H[i])%m;
}
A[a].push_back(sum);
}
for(int bit=0;bit<(1<<14);bit++){
int a=__builtin_popcount(bit);
ll sum=0;
rep(i,14){
if(bit&(1<<i)) sum=(sum+G[i+14])%m;
else sum=(sum+H[i+14])%m;
}
B[a].push_back(sum);
}
rep(i,15) sort(ALL(A[i]));
rep(i,15) sort(ALL(B[i]));
int q;
cin>>q;
while(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]){
if(x>=p){
auto q=upper_bound(ALL(B[k-a]),m-p-1)-lower_bound(ALL(B[k-a]),x-p);
ans+=q;
}
else{
auto q=upper_bound(ALL(B[k-a]),m-p-1)-B[k-a].begin();
auto r=B[k-a].end()-lower_bound(ALL(B[k-a]),m-p+x);
ans+=q+r;
}
}
}
cout<<ans<<endl;
}
return 0;
}
umezo