题解 P6891 【[JOISC2020]ビルの飾り付け 4】
1.[博客迁移20190713]题解 P4169 【[Violet]天使玩偶/SJY摆棋子】2.模拟题3.SP666 VOCV - Con-Junctions 题解4.Codeforces Round #900 (Div. 3)5.Codeforces Round 962 (Div. 3)6.题解 CF993E 【Nikita and Order Statistics】
7.题解 P6891 【[JOISC2020]ビルの飾り付け 4】
8.P2163 [SHOI2007] 园丁的烦恼9.[POI2011] LIZ-Lollipop10.Codeforces Round 973 (Div. 2)11.Codeforces Round 974 (Div. 3)12.NEERC2013题解13.CF1446C Xor Tree14.Codeforces Round 709 (Div. 1)15.Codeforces Round 975 (Div. 2)16.NEERC2014题解17.题解 P2726 【[SHOI2005]树的双中心】18.CF2019 F. Max Plus Min Plus Size19.Codeforces Round 757 (Div. 2)20.大工之星第一周题解如果要看能统计方案数的加强版,可以转至划分。
这题如果每次暴力从上一个状态枚举转移可以得到一个时间复杂度为
观察朴素动态规划方程,并经过打表可以发现,对于每一个阶段,在一个序列中选取点的个数是连续的一段区间。
那么我们可以考虑少枚举一层状态(选取个数),把控制区间记录在数组里,这样就可以
输出答案方案,只需要逆序判断就可。
至于我上文提到的加强版,需要读者掌握一定的多项式技术,笔者也在自己研究中,可以参考牛客网出题人的题解。
code:
// Program written by Liu Zhaozhou ~~~
#include <bits/stdc++.h>
using namespace std;
inline char gc(void) {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline void read(T &x) {
T f = 1; x = 0; static char c = gc();
for (; !isdigit(c); c = gc()) if (c == '-') f = -f;
for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c & 15);
x *= f;
}
inline void readstr(string&x) {
x = ""; static char ch;
while (isspace(ch = gc()));
while (x += ch, !isspace(ch = gc()));
}
inline void readstr(char *s) {
do *s = gc(); while ((*s == ' ') || (*s == '\n') || (*s == '\r'));
do *(++s) = gc(); while ((~*s) && (*s != ' ') && (*s != '\n') && (*s != '\r'));
*s = 0; return;
}
inline void readch(char&x) { while (isspace(x = gc())); }
char pf[100000], *o1 = pf, *o2 = pf + 100000;
#define ot(x) (o1 == o2 ? fwrite(pf, 1, 100000, stdout), *(o1 = pf) ++= x : *o1 ++= x)
template <class T>
inline void println(T x, char c = '\n') {
if (x < 0) ot(45), x = -x;
static char s[15], *b; b = s;
if (!x) *b ++= 48;
for (; x; * b ++= x % 10 + 48, x /= 10);
for (; b-- != s; ot(*b)); ot(c);
}
template <class T> inline void write(T x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + 48);
}
template <class T> inline void writeln(T x, char c = '\n') { write(x); putchar(c); }
template <class T> inline void chkmax(T &x, const T y) { x > y ? x = x : x = y; }
template <class T> inline void chkmin(T &x, const T y) { x < y ? x = x : x = y; }
inline void file(string str) {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
#define Ms(arr, opt) memset(arr, opt, sizeof(arr))
#define Mp(x, y) make_pair(x, y)
typedef long long ll;
typedef pair <int, int> pii;
const int INF = 0x3f3f3f3f;
const int Maxn = 5e5 + 5;
int n, a[Maxn * 2], b[Maxn * 2];
pii f[Maxn * 2][2]; char ans[Maxn * 2];
inline void update(pii &x, pii y) {
chkmin(x.first, y.first);
chkmax(x.second, y.second);
}
signed main(void) {
read(n); int m = n * 2;
for (int i = 1; i <= m; i++) read(a[i]);
for (int i = 1; i <= m; i++) read(b[i]);
f[0][0] = f[0][1] = Mp(0, 0);
for (int i = 1; i <= m; i++) {
f[i][0] = f[i][1] = Mp(INF, -INF);
if (a[i - 1] <= a[i]) update(f[i][0], f[i - 1][0]);
if (a[i - 1] <= b[i]) update(f[i][1], f[i - 1][0]);
if (b[i - 1] <= a[i]) update(f[i][0], f[i - 1][1]);
if (b[i - 1] <= b[i]) update(f[i][1], f[i - 1][1]);
++f[i][1].first; ++f[i][1].second;
}
int cur = -1, rem = n;
for (int i = 0; i < 2; i++)
if (f[m][i].first <= n && f[m][i].second >= n) cur = i;
if (cur == -1) { puts("-1"); return 0; }
for (int i = m; i >= 1; i--) {
ans[i] = (cur ? 'B' : 'A'); rem -= cur;
int opt = (cur ? b[i] : a[i]);
if (a[i - 1] <= opt && f[i - 1][0].first <= rem && f[i - 1][0].second >= rem) cur = 0;
else cur = 1;
} puts(ans + 1);
// fwrite(pf, 1, o1 - pf, stdout);
return 0;
}
/**/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现