結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,676 KB
testcase_01 AC 9 ms
6,676 KB
testcase_02 AC 14 ms
6,676 KB
testcase_03 AC 53 ms
6,676 KB
testcase_04 AC 34 ms
6,676 KB
testcase_05 AC 13 ms
6,676 KB
testcase_06 AC 45 ms
6,676 KB
testcase_07 AC 43 ms
6,676 KB
testcase_08 AC 16 ms
6,676 KB
testcase_09 AC 31 ms
6,676 KB
testcase_10 AC 42 ms
6,676 KB
testcase_11 AC 14 ms
6,676 KB
testcase_12 AC 54 ms
6,676 KB
testcase_13 AC 62 ms
6,676 KB
testcase_14 AC 53 ms
6,676 KB
testcase_15 AC 49 ms
6,676 KB
testcase_16 AC 52 ms
6,676 KB
testcase_17 AC 51 ms
6,676 KB
testcase_18 AC 60 ms
6,676 KB
testcase_19 AC 65 ms
6,676 KB
testcase_20 AC 63 ms
6,676 KB
testcase_21 AC 63 ms
6,676 KB
testcase_22 AC 157 ms
6,676 KB
testcase_23 AC 188 ms
6,676 KB
testcase_24 AC 157 ms
6,676 KB
testcase_25 AC 151 ms
6,676 KB
testcase_26 AC 158 ms
6,676 KB
testcase_27 AC 9 ms
6,676 KB
testcase_28 AC 9 ms
6,676 KB
testcase_29 AC 125 ms
6,676 KB
testcase_30 AC 24 ms
6,676 KB
testcase_31 AC 55 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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