提出 #39250016
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
const int N = 1 << 20 | 1;
int n, A[N], B[N], a[N], b[N], f[N], l = 1, s[N], ans;
int PLUS(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
int qpow(int x, int y) { int t = 1; for (; y; y>>=1) { if (y & 1) t = 1ll * t * x % MOD; x = 1ll * x * x % MOD; } return t; }
void NTT(int n, int *a, int o) {
for (int i=0; i<n; i++)
if (i < f[i]) swap(a[i], a[f[i]]);
for (int i=1; i<n; i<<=1) {
int g = qpow(3, (MOD - 1) / (i << 1));
for (int j=0; j<n; j+=i<<1)
for (int k=j, gi=1; k<j+i; k++, gi=1ll*gi*g%MOD) {
int _ = 1ll * a[k+i] * gi % MOD;
a[k+i] = PLUS(a[k], MOD - _), a[k] = PLUS(a[k], _);
}
}
if (o) {
reverse (a+1, a+n);
int inv = qpow(n, MOD - 2);
for (int i=0; i<n; i++) a[i] = 1ll * a[i] * inv % MOD;
}
}
int main() {
cin >> n;
for (int i=0; i<n; i++) scanf ("%d", &A[i]);
for (int i=0; i<n; i++) scanf ("%d", &B[i]);
reverse (B, B+n);
while (l <= n - 1 << 1) l <<= 1;
for (int i=1; i<l; i++) f[i] = f[i>>1] >> 1 | (i & 1 ? l >> 1 : 0);
for (int t=0; t<5; t++) {
for (int i=0; i<n; i++) a[i] = A[i] >> t & 1 ^ 1, b[i] = B[i] >> t & 1 ^ 1;
for (int i=n; i<l; i++) a[i] = b[i] = 0;
NTT(l, a, 0), NTT(l, b, 0);
for (int i=0; i<l; i++) a[i] = 1ll * a[i] * b[i] % MOD;
NTT(l, a, 1);
for (int i=n; i<l; i++) a[i%n] += a[i];
for (int i=0; i<n; i++) s[i] += n - a[i] << t;
}
for (int i=0; i<n; i++) ans = max(ans, s[i]);
cout << ans;
}
提出情報
| 提出日時 |
|
| 問題 |
G - OR Sum |
| ユーザ |
YeahPotato |
| 言語 |
C++ (GCC 9.2.1) |
| 得点 |
600 |
| コード長 |
1503 Byte |
| 結果 |
AC |
| 実行時間 |
916 ms |
| メモリ |
21896 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:30:16: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
30 | while (l <= n - 1 << 1) l <<= 1;
| ~~^~~
./Main.cpp:33:44: warning: suggest parentheses around arithmetic in operand of ‘^’ [-Wparentheses]
33 | for (int i=0; i<n; i++) a[i] = A[i] >> t & 1 ^ 1, b[i] = B[i] >> t & 1 ^ 1;
| ~~~~~~~~~~^~~
./Main.cpp:33:70: warning: suggest parentheses around arithmetic in operand of ‘^’ [-Wparentheses]
33 | for (int i=0; i<n; i++) a[i] = A[i] >> t & 1 ^ 1, b[i] = B[i] >> t & 1 ^ 1;
| ~~~~~~~~~~^~~
./Main.cpp:39:37: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
39 | for (int i=0; i<n; i++) s[i] += n - a[i] << t;
| ~~^~~~~~
./Main.cpp:27:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
27 | for (int i=0; i<n; i++) scanf ("%d", &A[i]);
| ~~~~~~^~~~~~~~~~~~~
./Main.cpp:28:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
28 | for (int i=0; i<n; i++) scanf ("%d", &B[i]);
| ~~~~~~^~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| example_00.txt |
AC |
14 ms |
3544 KiB |
| example_01.txt |
AC |
2 ms |
3612 KiB |
| hand_00.txt |
AC |
905 ms |
21616 KiB |
| hand_01.txt |
AC |
908 ms |
21740 KiB |
| hand_02.txt |
AC |
911 ms |
21612 KiB |
| hand_03.txt |
AC |
912 ms |
21612 KiB |
| hand_04.txt |
AC |
911 ms |
21684 KiB |
| hand_05.txt |
AC |
912 ms |
21596 KiB |
| hand_06.txt |
AC |
912 ms |
21756 KiB |
| hand_07.txt |
AC |
914 ms |
21616 KiB |
| hand_08.txt |
AC |
3 ms |
3600 KiB |
| hand_09.txt |
AC |
2 ms |
3644 KiB |
| random_00.txt |
AC |
912 ms |
21772 KiB |
| random_01.txt |
AC |
913 ms |
21776 KiB |
| random_02.txt |
AC |
916 ms |
21772 KiB |
| random_03.txt |
AC |
913 ms |
21608 KiB |
| random_04.txt |
AC |
914 ms |
21732 KiB |
| random_05.txt |
AC |
915 ms |
21756 KiB |
| random_06.txt |
AC |
913 ms |
21744 KiB |
| random_07.txt |
AC |
916 ms |
21612 KiB |
| random_08.txt |
AC |
908 ms |
21776 KiB |
| random_09.txt |
AC |
912 ms |
21748 KiB |
| random_10.txt |
AC |
909 ms |
21616 KiB |
| random_11.txt |
AC |
913 ms |
21680 KiB |
| random_12.txt |
AC |
908 ms |
21780 KiB |
| random_13.txt |
AC |
914 ms |
21604 KiB |
| random_14.txt |
AC |
909 ms |
21892 KiB |
| random_15.txt |
AC |
908 ms |
21780 KiB |
| random_16.txt |
AC |
906 ms |
21768 KiB |
| random_17.txt |
AC |
906 ms |
21732 KiB |
| random_18.txt |
AC |
912 ms |
21756 KiB |
| random_19.txt |
AC |
907 ms |
21596 KiB |
| random_20.txt |
AC |
909 ms |
21612 KiB |
| random_21.txt |
AC |
907 ms |
21732 KiB |
| random_22.txt |
AC |
907 ms |
21764 KiB |
| random_23.txt |
AC |
908 ms |
21740 KiB |
| random_24.txt |
AC |
907 ms |
21740 KiB |
| random_25.txt |
AC |
909 ms |
21748 KiB |
| random_26.txt |
AC |
910 ms |
21616 KiB |
| random_27.txt |
AC |
909 ms |
21744 KiB |
| random_28.txt |
AC |
910 ms |
21612 KiB |
| random_29.txt |
AC |
914 ms |
21780 KiB |
| random_30.txt |
AC |
902 ms |
21616 KiB |
| random_31.txt |
AC |
908 ms |
21736 KiB |
| random_32.txt |
AC |
908 ms |
21896 KiB |
| random_33.txt |
AC |
909 ms |
21612 KiB |
| random_34.txt |
AC |
915 ms |
21776 KiB |