QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#476508#9129. Quotient Sumucup-team3691#RE 0ms0kbC++141.5kb2024-07-13 19:53:472024-07-13 19:53:48

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 15:38:30]
  • hack成功,自动添加数据
  • (/hack/908)
  • [2024-07-13 19:53:48]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-13 19:53:47]
  • 提交

answer

#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <random>
#include <ctime>
#include <cstdlib>
#include <chrono>

using namespace std;

int n, m, k;

void propag(int p, int n, vector<vector<int>> &v) {
  if (n == 0) {
    cout << v[0][0] << " ";

    return;
  }

  vector<vector<int>> lft(1 << (n - 1), vector<int> (n, 1));
  vector<vector<int>> rgt(1 << (n - 1), vector<int> (n, 1));

  const int msb = (1 << (n - 1));

  for (int x = 0; x < msb; ++x) {
    for (int d = 0; d <= n; ++d) {
      if (d < n)
        lft[x][d] = 1LL * lft[x][d] * v[x][d] % m;

      if (d > 0)
        rgt[x][d - 1] = 1LL * rgt[x][d - 1] * v[x][d] % m;
    }
  }
  
  for (int x = msb; x < 2 * msb; ++x) {
    for (int d = 0; d <= n; ++d) {
      if (d > 0)
        lft[x ^ msb][d - 1] = 1LL * lft[x ^ msb][d - 1] * v[x][d] % m;

      if (d <= n)
        rgt[x ^ msb][d] = 1LL * rgt[x ^ msb][d] * v[x][d] % m;
    }
  }

  propag(p, n - 1, lft);
  propag(p + msb, n - 1, rgt);
}

void solve() {
  cin >> n >> m >> k;

  vector<vector<int>> v(1 << n, vector<int> (n + 1, 1));
  for (int i = 0; i < k; ++i) {
    int c, d, x;
    cin >> c >> d >> x;

    v[c][d] = 1LL * v[c][d] * x % m;
  }

  propag(0, n, v);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
  //cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
2 3 6

output:


result: