답안 #15064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15064 2015-07-11T08:07:10 Z hongjun7 씽크스몰 (kriii3_TT) C++
20 / 30
1233 ms 43924 KB
#include <cstdio>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef complex<long double> base;
typedef long long ll;
void fft(vector <base> &a, bool invert) {
	int n = sz(a);
	for (int i = 1, j = 0; i<n; i++) {
		int bit = n >> 1;
		for (; j >= bit; bit >>= 1) j -= bit;
		j += bit;
		if (i < j) swap(a[i], a[j]);
	}
	for (int len = 2; len <= n; len <<= 1) {
		long double ang = 2 * M_PI / len*(invert ? -1 : 1);
		base wlen(cos(ang), sin(ang));
		for (int i = 0; i<n; i += len) {
			base w(1);
			for (int j = 0; j<len / 2; j++) {
				base u = a[i + j], v = a[i + j + len / 2] * w;
				a[i + j] = u + v;
				a[i + j + len / 2] = u - v;
				w *= wlen;
			}
		}
	}
	if (invert) {
		for (int i = 0; i<n; i++) a[i] /= n;
	}
}
void multiply(const vector<ll> &a, const vector<ll> &b, vector<ll> &res) {
	vector <base> fa(all(a)), fb(all(b));
	int n = 1;
	while (n < sz(a) + sz(b)) n <<= 1;
	fa.resize(n); fb.resize(n);
	fft(fa, 0); fft(fb, 0);
	for (int i = 0; i < n; i++) fa[i] *= fb[i];
	fft(fa, 1);
	res.resize(n);
	for (int i = 0; i < n; i++) res[i] = (ll)(fa[i].real() + (fa[i].real()>0 ? 0.5 : -0.5));
	ll r = res[0];
	for (int i = 1; i < n; i++) r ^= res[i];
	printf("%lld", r);
}
int n, m, x;
int main() {
	scanf("%d%d", &n, &m);
	vector <ll> a(n + 1), b(m + 1), res;
	for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 0; i <= m; i++) scanf("%lld", &b[i]);
	if (n < m) for (int i = n; i <= m; i++) a.push_back(0);
	else for (int i = m; i <= n; i++) b.push_back(0);
	multiply(a, b, res);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1596 KB Output is correct
2 Correct 0 ms 1596 KB Output is correct
3 Correct 1 ms 1596 KB Output is correct
4 Correct 3 ms 1780 KB Output is correct
5 Correct 3 ms 1752 KB Output is correct
6 Correct 3 ms 1748 KB Output is correct
7 Correct 3 ms 1756 KB Output is correct
8 Correct 0 ms 1756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 4328 KB Output is correct
2 Correct 559 ms 22224 KB Output is correct
3 Correct 570 ms 22452 KB Output is correct
4 Correct 577 ms 22680 KB Output is correct
5 Correct 571 ms 23292 KB Output is correct
6 Correct 575 ms 22948 KB Output is correct
7 Correct 571 ms 23460 KB Output is correct
8 Correct 567 ms 23460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1233 ms 43924 KB Output isn't correct
2 Halted 0 ms 0 KB -