QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#476512 | #9115. Contour Multiplication | ucup-team3691# | RE | 60ms | 3840kb | C++14 | 1.5kb | 2024-07-13 19:54:09 | 2024-07-13 19:54:09 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3616kb
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: 3616kb
input:
1 2 1 0 1 696782227
output:
1 1
result:
ok 2 tokens
Test #4:
score: 0
Accepted
time: 60ms
memory: 3840kb
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:
0 0 45928586 0 134497770 0 206758057 394352068 0 244291949 0 209807785 0 285761102 402778530 0 0 0 61435341 287059619 347978730 135518317 363576818 0 0 0 0 0 0 0 0 349412261
result:
ok 32 tokens
Test #5:
score: -100
Runtime Error
input:
13 471577301 500000 6468 6 306578522 8113 3 479854366 720 5 444779113 8132 12 228254993 6354 13 64735677 6877 9 421810792 541 9 278526040 3090 0 986913987 5352 8 16271033 3263 5 929162219 3483 8 459160836 5355 12 867871503 3035 9 877478088 4090 10 88145277 468 6 252659128 4500 6 628030207 455 5 2083...