結果
問題 | No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ |
ユーザー | Rubikun |
提出日時 | 2023-12-09 00:07:11 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 622 ms / 3,000 ms |
コード長 | 2,067 bytes |
コンパイル時間 | 2,593 ms |
コンパイル使用メモリ | 209,688 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-27 03:18:38 |
合計ジャッジ時間 | 14,127 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=1<<30; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); ll M;cin>>M; ll N=28; vector<ll> A(N),B(N); for(int i=0;i<N;i++) cin>>A[i]; for(int i=0;i<N;i++) cin>>B[i]; int Q;cin>>Q; while(Q--){ ll K,X;cin>>K>>X; vector<vector<ll>> S(N/2+1); for(int bit=0;bit<(1<<(N/2));bit++){ ll sum=0; for(int i=0;i<N/2;i++){ if(bit&(1<<i)){ sum+=A[N/2+i]; }else{ sum+=B[N/2+i]; } } sum%=M; S[__builtin_popcount(bit)].push_back(sum); } for(int i=0;i<si(S);i++) sort(all(S[i])); ll ans=0; for(int bit=0;bit<(1<<(N/2));bit++){ ll sum=0; for(int i=0;i<N/2;i++){ if(bit&(1<<i)){ sum+=A[i]; }else{ sum+=B[i]; } } sum%=M; int tar=K-__builtin_popcount(bit); if(tar<0||tar>N/2) continue; if(sum<X){ ll L=X-sum,R=M-sum; ans+=lower_bound(all(S[tar]),R)-lower_bound(all(S[tar]),L); }else{ ll L=0,R=M-sum; ans+=lower_bound(all(S[tar]),R)-lower_bound(all(S[tar]),L); L=X+M-sum; R=M; ans+=lower_bound(all(S[tar]),R)-lower_bound(all(S[tar]),L); } } cout<<ans<<"\n"; } }