-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1060.cc
47 lines (41 loc) · 1.13 KB
/
1060.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Name: Modular multiplication of polynomials
//Level: 2
//Category: シミュレーション
//Note:
/*
* 係数がmod 2なので、XORを使ってパタパタとひっくり返していけば良い。
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
while(N--) {
vector<int> f, g, h;
int fd, gd, hd;
cin >> fd;
f.resize(fd);
for(int i = 0; i < fd; ++i) cin >> f[fd-i-1];
cin >> gd;
g.resize(gd);
for(int i = 0; i < gd; ++i) cin >> g[gd-i-1];
cin >> hd;
h.resize(hd);
for(int i = 0; i < hd; ++i) cin >> h[hd-i-1];
vector<int> coef(fd+gd, 0);
for(int i = 0; i < fd; ++i)
for(int j = 0; j < gd; ++j)
coef[i+j] ^= f[i]&g[j];
for(int i = (int)fd+gd-1; i >= hd-1; --i)
if(coef[i])
for(int j = 0; j < hd; ++j) coef[i-j] ^= h[hd-j-1];
int k = min(hd, fd+gd-1);
while(!coef[k]) --k;
cout << k+1;
while(k>=0) cout << " " << coef[k--];
cout << endl;
}
return 0;
}