結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー tnakao0123tnakao0123
提出日時 2023-12-11 18:53:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,322 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 53,704 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2023-12-11 18:54:39
合計ジャッジ時間 48,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
13,480 KB
testcase_01 AC 10 ms
6,676 KB
testcase_02 AC 353 ms
6,676 KB
testcase_03 AC 2,807 ms
6,676 KB
testcase_04 AC 1,614 ms
6,676 KB
testcase_05 AC 89 ms
6,676 KB
testcase_06 AC 2,158 ms
6,676 KB
testcase_07 AC 2,143 ms
6,676 KB
testcase_08 AC 332 ms
6,676 KB
testcase_09 AC 1,303 ms
6,676 KB
testcase_10 AC 2,006 ms
6,676 KB
testcase_11 AC 271 ms
6,676 KB
testcase_12 AC 2,887 ms
6,676 KB
testcase_13 TLE -
testcase_14 AC 2,822 ms
6,676 KB
testcase_15 AC 2,082 ms
6,676 KB
testcase_16 AC 2,466 ms
6,676 KB
testcase_17 AC 2,695 ms
6,676 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2581.cc:  No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int N = 28;
const int K = N / 2;
const int KBITS = 1 << K;

/* typedef */

typedef vector<int> vi;

/* global variables */

int gs[N], hs[N];
vi bv0[K + 1], bv1[K + 1];

/* subroutines */

void addmod(int &a, int b, int m) { a = (a + b) % m; }

/* main */

int main() {
  int m;
  scanf("%d", &m);
  for (int i = 0; i < N; i++) scanf("%d", gs + i);
  for (int i = 0; i < N; i++) scanf("%d", hs + i);

  for (int bits = 0; bits < KBITS; bits++) {
    int bn = 0, s0 = 0, s1 = 0;
    for (int i = 0, bi = 1; i < K; i++, bi <<= 1) {
      bn += ((bits >> i) & 1);
      addmod(s0, (bits & bi) ? gs[i] : hs[i], m);
      addmod(s1, (bits & bi) ? gs[K + i] : hs[K + i], m);
    }

    bv0[bn].push_back(s0);
    bv1[bn].push_back(s1);
  }

  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int ki, xi;
    scanf("%d%d", &ki, &xi);

    int cnt = 0;
    for (int i = 0, j = ki; j >= 0; i++, j--)
      if (i <= K && j <= K && ! bv0[i].empty() && ! bv1[j].empty())
	for (auto u: bv0[i])
	  for (auto v: bv1[j]) {
	    int s = (u + v) % m;
	    if (s >= xi) cnt++;
	  }

    printf("%d\n", cnt);
  }

  return 0;
}
0