結果

問題 No.3605 Grand Cross
コンテスト
ユーザー Kude
提出日時 2026-08-01 00:08:05
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,256 ms / 2,000 ms
+ 528µs
コード長 2,431 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,847 ms
コンパイル使用メモリ 388,820 KB
実行使用メモリ 476,092 KB
最終ジャッジ日時 2026-08-01 00:08:49
合計ジャッジ時間 42,177 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, m;
    cin >> n >> m;
    VI a(n), b(m), c(n), d(m);
    for (int& x : a) cin >> x;
    for (int& x : b) cin >> x;
    for (int& x : c) cin >> x, x--;
    for (int& x : d) cin >> x, x--;
    {
      VI used(n + m);
      for (int x : c) used[x] |= 1;
      for (int x : d) used[x] |= 2;
      for (int nxt = 0; int& s : used) {
        s = s == 3 ? nxt++ : -1;
      }
      for (int& x : c) x = used[x];
      for (int& x : d) x = used[x];
    }
    ll ans = -1;
    rep(_, 2) {
      swap(n, m);
      swap(a, b);
      swap(c, d);
      rep(_, 2) {
        rep(_, 2) {
          static VL sa, sb;
          sa.resize(n + 1), sb.resize(m + 1);
          rep(i, n) sa[i+1] = sa[i] + a[i];
          rep(j, m) sb[j+1] = sb[j] + b[j];
          using BS = bitset<100005>;
          static BS b2pos[100005];
          rep(j, (m + 1) / 2) if (d[j] != -1) b2pos[d[j]].set(j);
          static BS undone;
          undone.set();
          rrep(i, (n + 1) / 2) if (c[i] != -1) {
            BS todo = b2pos[c[i]] >> i & undone;
            for (int d = todo._Find_first(); d < ssize(todo); d = todo._Find_next(d)) {
              int j = i + d;
              chmax(ans, sa[i + 1 + i] + sb[j + 1 + i] - sb[j - i]);
              undone.reset(d);
            }
          }
          rep(j, (m + 1) / 2) if (d[j] != -1) b2pos[d[j]].reset(j);
          reverse(all(b));
          reverse(all(d));
        }
        reverse(all(a));
        reverse(all(c));
      }
    }
    cout << ans << '\n';
  }
}
0