結果
| 問題 | No.3407 Birds-of-Paradise' Christmas Live |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-19 01:31:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 3,569 bytes |
| 記録 | |
| コンパイル時間 | 1,419 ms |
| コンパイル使用メモリ | 119,700 KB |
| 実行使用メモリ | 23,032 KB |
| 最終ジャッジ日時 | 2025-12-19 01:31:23 |
| 合計ジャッジ時間 | 4,432 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%lld", &A[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
/*
problem
given two 01 seqs (RLE)
choose intervals
- only 1
- disjoint
*/
constexpr Int INF = 1001001001001001001LL;
int N[2];
vector<Int> A[2];
int main() {
for (; ; ) {
for (int i = 0; i < 2; ++i) {
if (!~scanf("%d", &N[i])) return 0;
A[i].resize(N[i]);
for (int j = 0; j < N[i]; ++j) {
scanf("%lld", &A[i][j]);
}
}
using Pair = pair<Int, Int>;
vector<Pair> P[2];
for (int i = 0; i < 2; ++i) {
Int x = 0;
for (int j = 0; j < N[i]; ++j) {
if (!(j & 1) && A[i][j]) P[i].emplace_back(x, x + A[i][j]);
x += A[i][j];
}
// cerr<<"P["<<i<<"] = "<<P[i]<<endl;
}
for (int i = 0; i < 2; ++i) {
vector<Pair> ps;
for (const Pair &p : P[i]) {
auto it = partition_point(P[i ^ 1].begin(), P[i ^ 1].end(), [&](const Pair &q) -> bool {
return !(p.second <= q.second);
});
if (it != P[i ^ 1].end() && it->first <= p.first) {
// contained
} else {
ps.push_back(p);
}
}
P[i].swap(ps);
// cerr<<"P["<<i<<"] = "<<P[i]<<endl;
}
/*
--- ---- --
---- -- --
*/
vector<Pair> ps;
for (int i = 0; i < 2; ++i) for (const Pair &p : P[i]) ps.push_back(p);
sort(ps.begin(), ps.end());
const int psLen = ps.size();
Int ans = 0;
for (int i = 0, j; i < psLen; i = j) {
for (j = i + 1; j < psLen && ps[j - 1].second > ps[j].first; ++j) {}
// pv(ps.begin()+i,ps.begin()+j);
auto at = [&](int u) -> Int {
if (u == 0) return ps[i].first;
if (u == 2*(j-i) - 1) return ps[j - 1].second;
return (u & 1) ? ps[i + u/2 + 1].first : ps[i + u/2 - 1].second;
};
for (int u = 1; u < 2*(j-i); ++u) assert(at(u - 1) <= at(u));
vector<Int> dp(2*(j-i), 0);
for (int k = i; k < j; ++k) {
const int l = max(2*(k-i) - 1, 0);
const int r = min(2*(k-i) + 2, 2*(j-i) - 1);
for (int u = l; u <= r; ++u) for (int v = u + 1; v <= r; ++v) {
const Int d = at(v) - at(u);
chmax(dp[v], dp[u] + d*d);
}
}
// cerr<<" at = ";for(int u=0;u<2*(j-i);++u)cerr<<at(u)<<" ";cerr<<endl;
// cerr<<" dp = "<<dp<<endl;
ans += dp.back();
}
printf("%lld\n", ans);
}
return 0;
}