結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー RubikunRubikun
提出日時 2023-12-09 00:07:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 657 ms / 3,000 ms
コード長 2,067 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 211,148 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-09 00:07:27
合計ジャッジ時間 15,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,676 KB
testcase_01 AC 13 ms
6,676 KB
testcase_02 AC 33 ms
6,676 KB
testcase_03 AC 372 ms
6,676 KB
testcase_04 AC 231 ms
6,676 KB
testcase_05 AC 34 ms
6,676 KB
testcase_06 AC 315 ms
6,676 KB
testcase_07 AC 303 ms
6,676 KB
testcase_08 AC 100 ms
6,676 KB
testcase_09 AC 218 ms
6,676 KB
testcase_10 AC 306 ms
6,676 KB
testcase_11 AC 61 ms
6,676 KB
testcase_12 AC 464 ms
6,676 KB
testcase_13 AC 458 ms
6,676 KB
testcase_14 AC 434 ms
6,676 KB
testcase_15 AC 456 ms
6,676 KB
testcase_16 AC 433 ms
6,676 KB
testcase_17 AC 433 ms
6,676 KB
testcase_18 AC 458 ms
6,676 KB
testcase_19 AC 459 ms
6,676 KB
testcase_20 AC 459 ms
6,676 KB
testcase_21 AC 457 ms
6,676 KB
testcase_22 AC 649 ms
6,676 KB
testcase_23 AC 657 ms
6,676 KB
testcase_24 AC 641 ms
6,676 KB
testcase_25 AC 652 ms
6,676 KB
testcase_26 AC 636 ms
6,676 KB
testcase_27 AC 322 ms
6,676 KB
testcase_28 AC 321 ms
6,676 KB
testcase_29 AC 596 ms
6,676 KB
testcase_30 AC 318 ms
6,676 KB
testcase_31 AC 441 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
    }
}

0