Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
52453 AK2022071311 木板游戏 C++ 运行超时 20 2000 MS 33436 KB 1122 2022-07-19 12:14:01

Tests(4/20):


#include<iostream> #include<cstdio> #include<algorithm> using namespace std; inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ x = x * 10 + ch - 48; ch = getchar(); } return x * f; } const int N = 5 * 1e5 + 10; struct wood{ int l, r; }s[N]; int n, lm[N], rm[N], f[N]; bool cmp(wood x, wood y){ if(x.l != y.l) return x.l < y.l; return x.r > y.r; } int dfs(int pos, int ll , int rr, int cnt){ if(pos > n) return cnt; if(ll >= lm[pos] && rr <= rm[pos] && cnt <= f[pos]) return 1e9 + 10; if(ll <= lm[pos] && rr >= rm[pos] && cnt >= f[pos]) lm[pos] = ll, rm[pos] = rr, f[pos] = cnt; int ans = 0; if(s[pos].l >= ll && s[pos].r <= rr) ans = dfs(pos + 1, s[pos].l, s[pos].r, cnt + 1); return max(ans, dfs(pos + 1, ll, rr, cnt)); } int main(){ n = read(); for(int i = 1; i <= n; i++) lm[i] = 1e9 + 10, f[i] = 1e9 + 10, s[i].l = read(), s[i].r = read(); sort(s + 1, s + n + 1, cmp); printf("%d", dfs(1, 0, 1e9 + 10, 0)); return 0; }


测评信息: