QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#476508 | #9129. Quotient Sum | ucup-team3691# | RE | 0ms | 0kb | C++14 | 1.5kb | 2024-07-13 19:53:47 | 2024-07-13 19:53:48 |
Judging History
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;
}
详细
Test #1:
score: 0
Runtime Error
input:
3 2 3 6