結果
| 問題 | No.3605 Grand Cross |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-07-31 23:51:45 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,336 bytes |
| 記録 | |
| コンパイル時間 | 2,360 ms |
| コンパイル使用メモリ | 365,124 KB |
| 実行使用メモリ | 475,960 KB |
| 最終ジャッジ日時 | 2026-07-31 23:53:04 |
| 合計ジャッジ時間 | 77,878 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 TLE * 14 |
ソースコード
#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';
}
}
Kude