惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
The Register - Security
The Register - Security
A
About on SuperTechFans
L
LINUX DO - 热门话题
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
L
LangChain Blog
博客园_首页
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
Recent Announcements
Recent Announcements
NISL@THU
NISL@THU
P
Privacy & Cybersecurity Law Blog
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
C
Cybersecurity and Infrastructure Security Agency CISA
G
GRAHAM CLULEY
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
博客园 - Franky
The Hacker News
The Hacker News
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Security Latest
Security Latest
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
V
V2EX
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
SegmentFault 最新的问题
Latest news
Latest news
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
L
Lohrmann on Cybersecurity
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tor Project blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔 Luogu P3227. [HNOI2013] 切糕 Luogu P8500. [NOI2022] 冒泡排序 Luogu P3629. [APIO2010] 巡逻 USACO 2018 February Contest, Gold Problem 2. Directory Traversal Luogu P3647. [APIO2014] 连珠线 IZhO 2017. Problem F. Hard route SPOJ TWOPATHS. Two Paths 换根 dp 洪恩电脑 —— 开天辟地 Facebook Hacker Cup 2022 Round 2 Codeforces Round #875 Luogu P5828 边双连通图计数 EC Final 拉格朗日反演定理 Luogu P5827. 点双连通图计数 无标号连通图 AtCoder Beginner Contest 284 Luogu P4708. 画画 Luogu P6295. 有标号 DAG 计数 BZOJ #2863. 愤怒的元首 HDU 3303. Harmony Forever 聊聊《明日方舟 Side Story 孤星》与《崩坏:星穹铁道》 SGU 208. Toral Tickets 后日谈,SHLUG 月度分享(上) 钢琴练习 EasyRPG x ChatGPT ControlNet 相关 The 1st Universal Cup, Stage 4, Ukraine EasyRPG —— Sliding Puzzle The 1st Universal Cup, Stage 3, Poland DP 优化练习 NOI 2009 TypeDB Forces 2023 Nas 买来做什么… Global Game Jam 2023 参赛纪录 The 1st Universal Cup, Stage 2, Hongkong Codeforces Round #850 舟游同人游戏 RM2k3 机能增强 —— EasyRPG Player 魔改版 《海之歌》设定与剧本 dfs 序求 lca Codeforces Round #844 P3768 简单的数学题 AtCoder Beginner Contest 281 ChatGPT 相关 AtCoder Grand Contest 059 AtCoder Beginner Contest 280 Codeforces Global Round 24 事实核查,以乌鲁木齐火灾为例 SPOJ MUSKET. Musketeers Pinely Round 1 Note about FTX Permutation ICPC World Final 2021 CodeTON Round 3 Codeforces Round #831 Educational Codeforces Round 138 NovelAI 法术指南 卡农 Educational Codeforces Round 135 Codeforces Round #819 瓦喵之夏 NOI 2022 Luogu P3765 总统选举 Luogu P3369 【模板】普通平衡树 网络国家 旋转卡壳 OFAC Sanctions && Tornado Cash BZOJ 1185. [HNOI2007]最小矩形覆盖 Codeforces Round #814
The 1st Universal Cup, Stage 0, Nanjing
2023-02-07 · via 某岛

February 7, 2023

Problem G. Inscryption

其实就是括号序列。。首先考虑是否有解,那么肯定待定位置都填 '('
那么接下来就是保证合法的情况下,尽可能多的将待定位置填成 ')'。。那么这个肯定尽可能选一段后缀去填更优。
上面的观察已经足够写一个基于二分答案的解了,不过我们可以做的更好。。。

对于每个待定序列,我们都贪心的首先将其设置成 ‘)’,再之后遇到不合法的情况时,再进行调整,
而这只需要记录我们前面有多少待定的位置被填成 ')' 即可。

const int N = int(1e6) + 9;
int a[N];
int n;

bool ok() {
    int p = 1, q = 1, o = 0; REP(i, n) {
        if (a[i] == 1) {
            ++p; ++q;
        } else if (a[i] == -1) {
            if (q > 1) {
                --q;
            } else if (o) {
                --o; ++p; ++q;
            } else {
                return 0;
            }
        } else {
            if (q > 1) {
                --q; ++o;
            } else {
                ++p; ++q;
            }
        }
    }

    int d = __gcd(p, q); p /= d; q /= d;
    printf("%d %d\n", p, q);
    return 1;
}


int main(){

#ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin);
#endif

    Rush {
        RD(n); REP(i, n) RD(a[i]);
        if (!ok()) puts("-1");
    }
}

Posted by xiaodao
Category: 日常