QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#546743 | #9115. Contour Multiplication | ucup-team1766 | WA | 58ms | 3852kb | C++17 | 1.3kb | 2024-09-04 12:49:26 | 2024-09-04 12:49:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, K;
cin >> N >> M >> K;
// dp[i][j][k] = common multiplier to all bitmasks that match j in the first i bits,
// and differ in k locations in the last N - i bits.
// The dp essentially builds the bitmasks that differ with the queries in the specified
// number of bits, taking advantage of common intermediaries.
vector<vector<vector<long long>>> dp(N + 1, vector<vector<long long>>(1 << N, vector<long long>(N + 1, 1)));
for (int i = 0; i < K; i++) {
int C, D, X;
cin >> C >> D >> X;
dp[0][C][D] = X % M;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
for (int k = 0; k <= N; k++) {
if (dp[i][j][k] != 1) {
dp[i + 1][j][k] *= dp[i][j][k];
dp[i + 1][j][k] %= M;
if (k > 0) {
dp[i + 1][j ^ (1 << i)][k - 1] *= dp[i][j][k];
dp[i + 1][j ^ (1 << i)][k - 1] %= M;
}
}
}
}
}
for (int i = 0; i < (1 << N); i++) {
cout << dp[N][i][0] << " ";
}
cout << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
3 100 2 0 2 4 3 0 25
output:
1 1 1 0 1 4 4 1
result:
ok 8 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 998244353 7 0 2 4 3 0 25 9 4 37 4 1 16 6 3 8 1 4 68 13 3 97
output:
1552 8 1 9700 1 64 229696 1 8 4 388 8 64 8 68 1
result:
ok 16 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
1 2 1 0 1 696782227
output:
1 1
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 58ms
memory: 3580kb
input:
5 461799503 500000 26 2 741819583 24 4 16805970 5 2 192769861 5 4 365614234 31 0 680795402 23 5 256636931 24 4 150277578 3 1 912506287 27 5 785022824 1 4 645930009 8 2 715559837 3 4 166807726 22 2 584850050 23 1 481241174 7 0 947410124 0 4 588117991 13 5 882053755 16 5 430265734 29 5 324612363 9 4 8...
output:
178182741 394600272 156879789 346489605 277498648 135963069 2444431 415942395 121102740 305861677 56876633 318470229 349813332 402031982 335394631 332106643 411853994 75464884 258334593 448930746 204276600 40842571 95173738 232473835 105481673 220761178 301664957 312700366 343257211 30473454 1592386...
result:
wrong answer 1st words differ - expected: '0', found: '178182741'