結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,548 KB
testcase_01 AC 11 ms
6,548 KB
testcase_02 AC 17 ms
6,548 KB
testcase_03 AC 54 ms
6,548 KB
testcase_04 AC 36 ms
6,548 KB
testcase_05 AC 14 ms
6,548 KB
testcase_06 AC 46 ms
6,548 KB
testcase_07 AC 45 ms
6,548 KB
testcase_08 AC 18 ms
6,548 KB
testcase_09 AC 33 ms
6,548 KB
testcase_10 AC 44 ms
6,548 KB
testcase_11 AC 16 ms
6,548 KB
testcase_12 AC 55 ms
6,548 KB
testcase_13 AC 63 ms
6,548 KB
testcase_14 AC 54 ms
6,548 KB
testcase_15 AC 50 ms
6,548 KB
testcase_16 AC 53 ms
6,548 KB
testcase_17 AC 52 ms
6,548 KB
testcase_18 AC 60 ms
6,548 KB
testcase_19 AC 66 ms
6,548 KB
testcase_20 AC 64 ms
6,548 KB
testcase_21 AC 64 ms
6,548 KB
testcase_22 AC 155 ms
6,548 KB
testcase_23 AC 160 ms
6,548 KB
testcase_24 AC 154 ms
6,548 KB
testcase_25 AC 149 ms
6,548 KB
testcase_26 AC 156 ms
6,548 KB
testcase_27 AC 11 ms
6,548 KB
testcase_28 AC 11 ms
6,548 KB
testcase_29 AC 125 ms
6,548 KB
testcase_30 AC 27 ms
6,548 KB
testcase_31 AC 57 ms
6,548 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];
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;
}
0