結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー t98slidert98slider
提出日時 2023-12-15 01:50:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 3,000 ms
コード長 1,673 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 210,212 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-15 01:51:04
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,676 KB
testcase_01 AC 7 ms
6,676 KB
testcase_02 AC 10 ms
6,676 KB
testcase_03 AC 47 ms
6,676 KB
testcase_04 AC 29 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 40 ms
6,676 KB
testcase_07 AC 37 ms
6,676 KB
testcase_08 AC 13 ms
6,676 KB
testcase_09 AC 26 ms
6,676 KB
testcase_10 AC 37 ms
6,676 KB
testcase_11 AC 11 ms
6,676 KB
testcase_12 AC 49 ms
6,676 KB
testcase_13 AC 56 ms
6,676 KB
testcase_14 AC 48 ms
6,676 KB
testcase_15 AC 43 ms
6,676 KB
testcase_16 AC 45 ms
6,676 KB
testcase_17 AC 46 ms
6,676 KB
testcase_18 AC 52 ms
6,676 KB
testcase_19 AC 58 ms
6,676 KB
testcase_20 AC 57 ms
6,676 KB
testcase_21 AC 56 ms
6,676 KB
testcase_22 AC 141 ms
6,676 KB
testcase_23 AC 176 ms
6,676 KB
testcase_24 AC 142 ms
6,676 KB
testcase_25 AC 138 ms
6,676 KB
testcase_26 AC 142 ms
6,676 KB
testcase_27 AC 6 ms
6,676 KB
testcase_28 AC 6 ms
6,676 KB
testcase_29 AC 115 ms
6,676 KB
testcase_30 AC 15 ms
6,676 KB
testcase_31 AC 49 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, Q, k, x;
    cin >> m;
    vector<int> a(28), b(28);
    vector<vector<int>> tb1(15), tb2(15);
    cin >> a >> b;
    for(int S = 0; S < (1 << 14); S++){
        int s1 = 0, s2 = 0, c = __builtin_popcount(S);
        for(int i = 0; i < 14; i++){
            if(S >> i & 1){
                s1 = (s1 + a[i]) % m;
                s2 = (s2 + a[i + 14]) % m;
            }else{
                s1 = (s1 + b[i]) % m;
                s2 = (s2 + b[i + 14]) % m;
            }
        }
        tb1[c].emplace_back(s1);
        tb2[c].emplace_back(s2);
    }
    for(int i = 0; i < 15; i++){
        sort(tb1[i].begin(), tb1[i].end());
        sort(tb2[i].begin(), tb2[i].end());
    }
    cin >> Q;
    while(Q--){
        cin >> k >> x;
        int ans = 0;
        for(int i1 = max(0, k - 14); i1 <= k && i1 <= 14; i1++){
            int i2 = k - i1;
            auto f = [&](int l, int r){
                r = r == m ? tb2[i2].size() : lower_bound(tb2[i2].begin(), tb2[i2].end(), r) - tb2[i2].begin();
                l = l == 0 ? 0 : lower_bound(tb2[i2].begin(), tb2[i2].end(), l) - tb2[i2].begin();
                return r - l;
            };
            for(auto &&v : tb1[i1]){
                if(x >= v){
                    ans += f(x - v, m - v);
                }else{
                    ans += f(m + x - v, m);
                    ans += f(0, m - v);
                }
            }
        }
        cout << ans << '\n';
    }
}
0