USACO竞赛通过率分析!从青铜级晋升到铂金级究竟要多久?

USACO是全球范围内极具影响力的计算机科学竞赛之一,旨在培养和选拔优秀的编程人才。了解各个级别的通过率和获奖率,可以帮助参赛选手及其家长更好地评估竞争的激烈程度,并制定合理的备考策略。

2022-2023赛季详细数据

月赛晋级率:

初始注册USACO账号即可达到铜级。

铜奖升白银奖比率:约为15%。

白银奖升黄金奖比率:约为12%。

黄金奖升铂金奖比率:约为8%。

参赛者分布:

每场比赛中,中国参赛者占比在27%-36%之间,仅次于美国,位居第二。

参考2022-2023赛季,中国参赛总人数为10399人。

题目难度变化

近年来,USACO各组别的题目难度逐渐增加,尤其是在2022年,个别题目原来应该出现在Gold级别,但现在开始出现在Silver级别的最难那道题。这表明:

Bronze到Silver:题目更加注重灵活思维,直接套用算法模板的情况较少,重点考察建模能力。

Silver到Gold:思维难度略有下降,但代码实现要求变高。

Gold到Platinum:题目难度显著增加,需要深厚的算法知识和灵活的思维能力。

获奖率与挑战

获奖率:综合来看,USACO各级别的获奖率相对较低,尤其是从Silver到Gold再到Platinum,难度逐级递增,通过率也相应减少。

挑战:USACO竞赛全程使用英语,同时需要很强的编程能力和逻辑思维。因此,获得好成绩通常需要专业的指导和系统的训练。

USACO 竞赛中,从青铜级晋升到铂金级究竟要多久呢?

要知道,能晋级到铂金级别的同学,大体已经能够掌握多数编程技巧与算法结构,这对不少学生而言是颇具挑战性的。

晋级所需时间并没有一个确切的标准,主要是取决于学生的学习状况以及编程基础。倘若孩子从小就开始学习编程语言,那么在 USACO 计算机竞赛里晋升到铂金级别,相对来说会容易些;但要是孩子首次接触 USACO 竞赛,就期望晋级铂金级别,难度可想而知。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图

全国中小学生皆可参与!USACO不同等级需要具备什么水平?

USACO不仅仅是一个展示技术能力的平台,更是许多顶尖大学招生官在评估申请者时的一项重要参考标准。对于未来打算申请哈佛、耶鲁、麻省理工、普林斯顿、康奈尔、卡内基梅隆等顶尖大学的学生来说,参加USACO竞赛是不可不做的准备。

USACO不同等级所需具备的水平详解

USACO(USA Computing Olympiad)竞赛分为四个级别:铜级(Bronze)、银级(Silver)、金级(Gold)和铂金级(Platinum)。

铜级(Bronze)

适合对象:

首次参赛选手:没有或仅有少量编程经验的学生。

数学背景:

建议水平:代数I或者AMC 8水平。

具体要求:能够理解和处理基本的数学问题,如简单代数运算、基本几何知识等。

编程能力:

基础语法:熟练使用至少一种编程语言(如C++、Java、Python)的基础语法。

基础算法:能够应用简单的算法,如模拟、贪心算法、基础搜索(DFS/BFS)、简单数学运算(如质数判断、最大公约数)等。

备考建议:

熟悉输入输出格式:确保能够正确处理USACO题目的输入输出要求。

多练习模拟题:通过大量练习模拟题,提升快速实现题目要求的能力。

掌握基础搜索算法:深入理解DFS和BFS的应用场景,确保能在实际问题中灵活运用。

银级(Silver)

适合对象:

通过铜级的选手:已经掌握了基础算法和数据结构的学生。

数学背景:

建议水平:AMC 10/12水平。

具体要求:能够处理较为复杂的数学问题,如组合数学、概率论、中级代数等。

编程能力:

中级算法与数据结构:掌握二分查找、前缀和与差分数组、简单动态规划、图的遍历与最短路径(Dijkstra、Floyd-Warshall)等。

问题解决能力:具备通过编程解决基本问题的能力,能够将问题抽象化并设计合适的算法进行求解。

备考建议:

熟练掌握二分查找:理解其应用场景,并能迅速写出正确的代码实现。

练习动态规划:通过大量练习背包问题等基础动态规划题目,提升对动态规划的理解和应用能力。

熟悉图的表示方法:掌握图的存储方式(如邻接矩阵、邻接表),并能灵活应用DFS/BFS解决图论问题。

金级(Gold)

适合对象:

通过银级的选手:已经掌握了中级算法和数据结构的学生。

数学背景:

建议水平:AIME水平。

具体要求:能够处理高难度的数学问题,如高级组合数学、数论、复杂几何等。

编程能力:

高级算法与数据结构:掌握状态压缩DP、区间DP、线段树与树状数组、贪心算法的进阶应用、网络流与二分图匹配等。

问题抽象与优化:具有良好的算法基础,能够将复杂问题抽象化,并设计高效的解决方案。对高级数据结构有深入了解,能够优化算法性能。

备考建议:

深入理解动态规划:掌握动态规划的状态设计和转移方程,尤其是状态压缩和区间DP等高级技巧。

掌握线段树和树状数组:通过练习经典题目,提升对这些数据结构的理解和应用能力。

练习网络流和二分图匹配:通过大量练习经典题目,掌握网络流和二分图匹配的核心思想和实现方法。

铂金级(Platinum)

适合对象:

通过金级的选手:已经掌握了高级算法和数据结构的学生。

数学背景:

建议水平:美国(J)MO水平。

具体要求:能够处理极为复杂的数学问题,如高等代数、高级数论、复杂几何等。

编程能力:

高级数据结构与算法:掌握平衡树、可持久化数据结构、复杂动态规划(树形DP、数位DP)、计算几何、高级图论(强连通分量、最小生成树进阶)等。

算法优化与最优解:编程功底深厚,对算法有深入了解,具有算法优化能力,能从多种方案中寻找最优解。

备考建议:

熟悉高级数据结构:通过大量练习,掌握平衡树、可持久化数据结构等高级数据结构的实现与应用。

练习计算几何:通过经典题目,提升对计算几何算法的理解和应用能力。

深入理解高级图论算法:如Tarjan算法、Kruskal算法的优化等,通过大量练习提升对这些算法的理解和应用能力。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图

爬藤高含金量信息学竞赛!高效备赛USACO五大得分技巧!

USACO(美国计算机奥林匹克竞赛)是一项极具挑战性的编程竞赛,要求参赛者在有限时间内解决复杂的算法问题。为了帮助你在2月份的竞赛中高效备战,以下是五个关键策略:

1.主攻刷题策略

重点刷题:

历年真题: 重点刷USACO的历年真题,尤其是近几年的题目。这些题目最能反映当前竞赛的难度和出题趋势。

题目选择: 从简单到难,逐步提升难度,确保每个难度级别的题目都能熟练掌握。

专项练习:

薄弱环节: 针对自己在算法和数据结构方面的薄弱知识点进行专项练习。

常见算法: 重点练习常用的算法,例如:

搜索算法(DFS、BFS)

动态规划

图论算法(最短路径、最小生成树)

数据结构(堆、栈、队列、哈希表)

目标: 确保每个算法都能熟练应用,能够快速准确地实现代码。

建议: 制定详细的刷题计划,每天安排固定的时间进行练习,并定期回顾和总结。

2.提升实战技能

全真模拟:

比赛环境: 在4小时内完成一套完整的比赛题目,模拟真实的比赛环境。

时间限制: 严格按照比赛时间进行训练,培养时间管理能力。

提升能力:

解题速度: 通过模拟训练,提高解题速度,确保在规定时间内完成更多题目。

代码实现: 练习快速编写和调试代码,减少不必要的调试时间。

心理素质: 适应比赛压力,提高心理素质,保持冷静和专注。

建议: 每周至少进行1-2次模拟训练,并根据模拟结果调整训练策略。

3.从错题出发总结技巧

错题整理:

分类整理: 将错题按照错误类型进行分类,例如:

思路错误: 对问题理解有误,算法设计不合理。

实现错误: 代码实现过程中出现bug,例如边界条件处理不当。

优化不足: 代码效率低下,无法通过时间限制。

原因分析:

深入分析: 针对每道错题,深入分析错误原因,找出知识漏洞和不足之处。

记录总结: 将错误原因和解决方法记录下来,形成错题集。

改进策略:

针对性练习: 针对常见错误,进行专项练习,巩固薄弱环节。

举一反三: 总结错误类型,避免在后续练习和比赛中犯同样的错误。

建议: 定期回顾错题集,确保每个错误都得到纠正,并不断优化解题思路和代码实现。

4.优化代码,提升效率

代码简洁:

避免冗余: 确保代码简洁明了,避免不必要的冗余操作。

模块化编程: 将代码分解成多个模块,提高代码的可读性和可维护性。

熟悉模板:

常用算法: 熟悉常用算法的模板代码,例如排序算法、搜索算法、动态规划等。

减少调试: 使用模板代码可以减少调试时间,提高解题效率。

代码优化:

效率提升: 优化代码的运行效率,确保能够通过时间限制。

算法选择: 选择合适的算法和数据结构,避免使用效率低下的算法。

建议: 在刷题过程中,不断总结和优化代码实现,提高代码质量和效率。

5.合理调节备赛时间

心态管理:

积极心态: 保持积极乐观的心态,相信自己的能力。

压力管理: 学会缓解比赛压力,例如深呼吸、短暂休息等。

时间管理:

先易后难: 比赛时先做容易的题目,再做难度较大的题目,确保拿到基础分数。

合理分配: 遇到难题不要慌张,合理分配时间,争取部分分数。

标记难题: 对于没有思路的题目,可以先标记下来,等完成其他题目后再回头思考。

策略调整:

灵活应对: 根据比赛情况,灵活调整策略,例如:

如果时间充裕,可以尝试优化代码,提高效率。

如果时间紧张,可以先实现基础版本,再进行优化。

建议: 比赛前进行心理调适,保持良好的心态和状态。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图

USACO计算机竞赛晋级路径&晋级方式详解!附USACO历年分数线统计!

USACO(美国计算机奥林匹克竞赛)作为全球范围内极具影响力的编程竞赛之一,为理工科学生,尤其是那些希望申请海外名校计算机专业的学生提供了极大的助力。参赛选手需要从最低级别开始参赛,并逐步提升自己的水平。

USACO晋级路径

铜级(Bronze)

适合对象:新注册的参赛选手通常从这一级别开始。

难度:基础算法与数据结构,如模拟、简单贪心算法、基础搜索(DFS/BFS)、基础数学等。

银级(Silver)

适合对象:通过铜级晋级的选手。

难度:中级算法与数据结构,如二分查找、前缀和与差分数组、简单动态规划、图的遍历与最短路径等。

金级(Gold)

适合对象:通过银级晋级的选手。

难度:高级算法与数据结构,如高级动态规划(状态压缩、区间DP)、线段树与树状数组、贪心算法的进阶应用、网络流与二分图匹配等。

铂金级(Platinum)

适合对象:通过金级晋级的选手。

难度:非常复杂的算法与数据结构,如高级数据结构(平衡树、可持久化数据结构)、复杂动态规划(树形DP、数位DP)、计算几何、高级图论等。

USACO历年分数线统计

铜升银(Bronze to Silver):

晋级分数线:基本稳定在750分左右。

银升金(Silver to Gold):

晋级分数线:基本在700-750分之间浮动。

金升铂金(Gold to Platinum):

晋级分数线:基本稳定在750-800分之间。

每次考试的难度不同,因此分数线也会有所浮动。一般来说,题目难度增加时,分数线会相应降低;反之亦然。

USACO晋级方式详解

1.满分晋级

条件:在比赛中获得满分(1000分)。

优势:可以直接晋级到下一个级别,并且可以在当月的时间段内再次参加一个更高级别的比赛。

举例:如果选手在一场比赛中获得了青铜级别的满分,他们可以立即晋级到银级别,并在同一时间段内再次参加银级别的比赛,以此类推,理论上可以在一场比赛的四天内从青铜级别晋升到白金级别。

2.常规晋级

条件:未获得满分的选手需要等待晋级分数线公布。

流程:

比赛结束:组织者根据所有参赛选手的成绩设定晋级分数线。

分数线公布:通常在比赛结束后的一段时间内公布。

确认晋级:选手可以通过官网查看自己的成绩和是否晋级。

注意事项:

晋级分数线并不是固定的,而是根据这场比赛的参赛选手成绩的比例来确定的。

每次考试的难度不同,分数线也会有所浮动。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图

USACO新赛季赛程过半!不得不看的USACO 各级别重点算法与备考建议~

USACO(USA Computing Olympiad)是全球范围内极具影响力的计算机科学竞赛之一,旨在培养和选拔优秀的编程人才。随着2024-25赛季的赛程过半,了解每个级别的重点算法与知识点,并制定合理的备考策略,对于在接下来的比赛(特别是2月份的比赛)中脱颖而出至关重要。

整体赛程与分数线变化

当前情况:每个级别的分数线目前都是700分,相比于之前的赛季有所下降。

原因分析:这可能与题目难度的变化以及赛制的调整有关。

机会提示:2月份的比赛是一个较好的晋级机会,因为3月份的Open赛通常难度较大。

各级别重点算法与备考建议

铜级(Bronze)

重点算法与知识点:

基础模拟题:理解并实现简单的模拟问题。

简单贪心算法:掌握基本的贪心策略及其应用场景。

基础搜索(DFS/BFS):熟悉深度优先搜索(DFS)和广度优先搜索(BFS)的应用。

基础数学:如质数判断、最大公约数等。

备考建议:

熟悉输入输出格式:确保能够正确处理USACO题目的输入输出要求。

多练习模拟题:通过大量练习模拟题,提升快速实现题目要求的能力。

掌握基础搜索算法:深入理解DFS和BFS的应用场景,确保能在实际问题中灵活运用。

银级(Silver)

重点算法与知识点:

二分查找:熟练掌握二分查找的模板及应用场景。

前缀和与差分数组:理解和应用前缀和与差分数组优化问题求解。

简单动态规划(DP):如背包问题等经典动态规划问题。

图的遍历与最短路径:掌握Dijkstra、Floyd-Warshall等图论算法。

备考建议:

熟练掌握二分查找:理解其应用场景,并能迅速写出正确的代码实现。

练习动态规划:通过大量练习背包问题等基础动态规划题目,提升对动态规划的理解和应用能力。

熟悉图的表示方法:掌握图的存储方式(如邻接矩阵、邻接表),并能灵活应用DFS/BFS解决图论问题。

金级(Gold)

重点算法与知识点:

高级动态规划:如状态压缩、区间DP等复杂动态规划问题。

线段树与树状数组:掌握线段树和树状数组的实现与应用。

贪心算法的进阶应用:理解并实现更复杂的贪心策略。

网络流与二分图匹配:掌握网络流和二分图匹配的经典算法及其应用。

备考建议:

深入理解动态规划:掌握动态规划的状态设计和转移方程,尤其是状态压缩和区间DP等高级技巧。

掌握线段树和树状数组:通过练习经典题目,提升对这些数据结构的理解和应用能力。

练习网络流和二分图匹配:通过大量练习经典题目,掌握网络流和二分图匹配的核心思想和实现方法。

铂金级(Platinum)

重点算法与知识点:

高级数据结构:如平衡树、可持久化数据结构等。

复杂动态规划:如树形DP、数位DP等复杂动态规划问题。

计算几何:掌握计算几何的经典算法及其核心思想。

高级图论:如强连通分量、最小生成树进阶等高级图论算法。

备考建议:

熟悉高级数据结构:通过大量练习,掌握平衡树、可持久化数据结构等高级数据结构的实现与应用。

练习计算几何:通过经典题目,提升对计算几何算法的理解和应用能力。

深入理解高级图论算法:如Tarjan算法、Kruskal算法的优化等,通过大量练习提升对这些算法的理解和应用能力。

【扫码免费领取】USACO真题+备赛书单+一对一备考规划!

预约最新真题讲座、课程详情可扫码咨询⇓

思维导图

2025 年 1 月比赛——最终结果

2025年1月的比赛以算法编程问题为特色,涵盖了广泛的技术和难度水平。

在为期4天的比赛中,共有11565名不同的用户登录。来自100多个不同国家的9450名参与者提交了至少一个解决方案。4276名参与者来自美国,其中中国、加拿大、韩国、罗马尼亚、马来西亚、印度和新加坡的参与程度也很高。

总计有23508份已评级的提交材料,按语言细分如下:

14190 C++17
3324 Python-3.6.9
3069 C++11
2763 Java
127 C
35 Python-2.7.17

以下是白金、金牌、银牌和铜牌比赛的详细结果。您还可以找到每个问题的解决方案和测试数据。

USACO 2025年 1 月竞赛,白金奖

白金组共有 352 名参与者,其中 254 名是大学预科生。得分最高的成员的成绩在这里。祝贺所有最优秀的参赛者取得优异的成绩!

1 DFS Order
查看问题 | 测试数据 | 解决方案
2 Shock Wave
查看问题 | 测试数据 | 解决方案
3 Watering the Plants
查看问题 | 测试数据 | 解决方案

USACO 2025 年 1 月比赛,金奖

黄金组共有 1032 名参与者,其中 738 名是大学预科生。所有在本次比赛中获得 700 分或更高认证分数的参赛者将自动晋升到白金组。所有晋级者的详细结果将在我们完成学术诚信检查后很快公布。

1 Median Heap
查看问题 | 测试数据 | 解决方案
2 Reachable Pairs
查看问题 | 测试数据 | 解决方案
3 Photo Op
查看问题 | 测试数据 | 解决方案

USACO 2025 年 1 月比赛,银奖

白银组共有 4070 名参与者,其中 3072 名是大学预科生。所有在本次比赛中获得 700 分或更高分的参赛者将自动晋级金牌组。

1 Cow Checkups
查看问题 | 测试数据 | 解决方案
2 Farmer John's Favorite Operation
查看问题 | 测试数据 | 解决方案
3 Table Recovery
查看问题 | 测试数据 | 解决方案

USACO 2025 年 1 月比赛,铜奖

铜牌组共有 6735 名参与者,其中 5060 名是大学预科生。所有在本次比赛中获得 700 分或更高分的参赛者将自动晋升到银牌组。

1 Astral Superposition
查看问题 | 测试数据 | 解决方案
2 It's Mooin' Time II
查看问题 | 测试数据 | 解决方案
3 Cow Checkups
查看问题 | 测试数据 | 解决方案

结语

又是一场具有挑战性的比赛!从技术角度来看,1 月份的比赛进行得很顺利。我们看到了很高的参与度,有相当数量的参与者得到了晋升。

对于那些尚未晋升的人, 请记住,练习得越多,你的算法编码技能就会越强——请坚持下去!USACO比赛旨在挑战最优秀的学生,要想脱颖而出,需要付出大量努力。为了帮助你修复代码中的任何错误,你现在可以使用“分析模式”重新提交你的解决方案,并从评判服务器获取反馈。

众多人士为USACO竞赛的质量和成功做出了贡献。本次竞赛的协助人员包括 Alex Liang, Tina Wang, Chongtian Ma, Haokai Ma, Richard Qi, Thomas Liu, Claire Zhang, Larry Xing, Benjamin Chen, Weiming Zhou, Daniel Zhang, Eric Yang, Spencer Compton, William Lin, Danny Mittal, David Hu, Suhas Nagar, Nathan Wang, Brandon Wang, Michelle Wei, Nick Wu, Ho Tin Fan, Andi Qu, and Benjamin Qi,也感谢我们的翻译帮助我们扩大比赛的范围。最后,我们非常 感谢 USACO 赞助商的慷慨支持:Citadel, Ansatz、X-Camp、TwoSigma、VPlanet Coding、EasyFunCoding、Orijtech 和 Jump Trading。

我们期待在二月再次见到大家 比赛。

祝您编码愉快!

2025 年 1 月USACO竞赛铜奖组问题三—Cow Checkups

**Note: We suggest using a language other than Python to earn full credit on this problem.**

Farmer John's N (1≤N≤7500) cows are standing in a line, with cow 1 at the front of the line and cow N at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from 1 to N. The i'th cow from the front of the line is of species ai (1≤ ai N).

FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the i'th cow in the line, only if it is of species bi (1≤biN).

FJ is lazy and does not want to completely reorder his cows. He will perform the following operation exactly once.

Select two integers l and r such that 1≤lrN. Reverse the order of the cows that are between the l-th cow and the r-th cow in the line, inclusive.

FJ wants to measure how effective this approach is. For each c=0…N, help FJ find the number of distinct operations (l,r) that result in exactly c cows being checked. Two operations (l1,r1) and (l2,r2) are different if l1l2 or r1r2.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains an integer N.

The second line contains a1,a2,...,aN.

The third line contains b1,b2,…,bN.

OUTPUT FORMAT (print output to the terminal / stdout):

Output N+1 lines with the i-th line containing the number of distinct operations (l,r) that result in i−1 cows being checked.

SAMPLE INPUT:

3
1 3 2
3 2 1

SAMPLE OUTPUT:

3
3
0
0

If FJ chooses (l=1,r=1), (l=2,r=2), or (l=3,r=3) then no cows will be checked. Note that those operations do not modify any of the cows' locations.

The following operations result in one cow being checked.

l=1,r=2: FJ reverses the order of the first and second cows so the species of each cow in the new lineup will be [3,1,2]. The first cow will be checked.
l=2,r=3: FJ reverses the order of the second and third cows so the species of each cow in the new lineup will be [1,2,3]. The second cow will be checked.
l=1,r=3: FJ reverses the order of the first, second, and third cows so the species of each cow in the new lineup will be [2,3,1]. The third cow will be checked.

SAMPLE INPUT:

3
1 2 3
1 2 3

SAMPLE OUTPUT:

0
3
0
3

The three possible operations that cause 3 cows to be checked are (l=1,r=1),(l=2,r=2), and (l=3,r=3).

SAMPLE INPUT:

7
1 3 2 2 1 3 2
3 2 2 1 2 3 1

SAMPLE OUTPUT:

0
6
14
6
2
0
0
0

The two possible operations that cause 4 cows to be checked are (l=4,r=5) and (l=5,r=7).

SCORING:

Inputs 4-6: N≤100
Inputs 7-13: No additional constraints

Problem credits: Chongtian Ma and Haokai Ma

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

2025 年 1 月USACO竞赛铜奖组问题二—It's Mooin' Time II

Farmer John is trying to describe his favorite USACO contest to Elsie, but she is having trouble understanding why he likes it so much. He says "My favorite part of the contest was when Bessie said 'It's Mooin' Time' and mooed all over the contest."

Elsie still doesn't understand, so Farmer John downloads the contest as a text file and tries to explain what he means. The contest is defined as an array of N
(1≤N≤106) integers a1,a2,...,aN (1≤ ai N). Farmer John defines a moo as an array of three integers where the second integer equals the third but not the first. A moo is said to occur in the contest if it is possible to remove integers from the array until only the moo remains.

As Bessie allegedly "mooed all over the contest", help Elsie count the number of distinct moos that occur in the contest! Two moos are distinct if they do not consist of the same integers in the same order.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N.

The second line contains N space-separated integers a1,a2,...,aN .

OUTPUT FORMAT (print output to the terminal / stdout):

Output the number of distinct moos that occur in the contest.

**Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long" in Java, a "long long" in C/C++).**

SAMPLE INPUT:

6
1 2 3 4 4 4

SAMPLE OUTPUT:

3
This contest has three distinct moos: "1 4 4", "2 4 4", and "3 4 4".

SCORING:

  • Inputs 2-4: N≤102
  • Inputs 5-7: N≤104
  • Inputs 8-11: No additional constraints.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

2025 年 1 月USACO竞赛铜奖组问题一—Astral Superposition

**Note: The time limit for this problem is 4s, twice the default.**

Bessie is using her nifty telescope to take photos of all the stars in the night sky. Her telescope can capture an N×N(1≤N≤1000) photo of the stars where each pixel is either a star or empty sky. Each star will be represented by exactly one pixel, and no two distinct stars share the same pixel.

Overnight, something strange happens to the stars in the sky. Every star either disappears or moves A pixels to the right, and B pixels downwards (0≤A,BN
). If a star disappears or moves beyond the photo boundary, it no longer appears in the second photo.

Bessie took photos before and after the shifting positions, but after experimenting in Mootoshop, she accidentally superimposed one photo onto the other. Now, she can see white pixels where both photos were empty, gray pixels where stars existed in exactly one photo, and black pixels where there was a star in both photos. Bessie also remembers that no new stars moved into the frame of the second photo, so her first photo contains all of the stars in the night sky.

Given the final photo, determine the minimum possible number of stars in the sky before the shifting incident for T (1≤T≤1000) independent test cases. If no arrangement of stars can produce the given final photo, output −1.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line of input contains T and T test cases will follow.

The first line of each test case will contain N A B .

Then follow N lines each representing one row of the superimposed photo. The ith row from the top is represented by a string ci,1ci,2ci,N, where each ci,j∈{W,G,B}, representing the colors white, gray, and black respectively.

It is guaranteed that the sum of N2 over all test cases will not exceed 107.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output the minimum number of stars that existed before the shifting, or −1 if impossible.

SAMPLE INPUT:

1
3 0 0
WWB
BBB
GGG

SAMPLE OUTPUT:

7

In this example, there is no shifting. The first photo is as follows: (. for sky, * for star)

..*
***
***

The second photo, where the stars on the bottom row disappeared, is as follows:

..*
***
...

This is the only way to produce the superimposed photo, so the minimum possible number of initial stars is 7.

SAMPLE INPUT:

3
5 1 2
GWGWW
WGWWW
WBWGW
WWWWW
WWGWW
3 1 1
WWW
WBW
WWW
3 1 0
GGB
GGW
WWW

SAMPLE OUTPUT:

4
-1
4

In the first case, there were at least 4 stars at the start. If we let (r,c) denote the intersection of the rth row from the top and cth column from the left, one possibility is that they were initially at (1,1),(3,2),(2,2), and (1,3). All the stars shifted, except for the one at (2,2)which disappeared.

In the second case, there is no arrangement of stars in the initial photo that can produce the middle black pixel given the shift.

In the third case, there were at least 4 stars at the start. One possibility is that they were initially at (1,1),(1,2),(1,3),and (2,1). In the second photo, the star originally at (1,1) disappeared and the star originally at (1,3) moved off frame. The other two stars shifted to the right by 1.

SCORING:

Input 3: A=B=0
Inputs 4-7: A=1,B=0,N≤10
Inputs 8-9: A=1,B=0
Inputs 10-12: No additional constraints.

Problem credits: Suhas Nagar

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

2025 年 1 月USACO竞赛银奖组问题三—Table Recovery

Bessie has an N×N (1≤N≤1000) addition table where the integer in the cell at row r and column c is r+c, for all 1≤r,cN. For example, for N=3, the table would look like this:

2 3 4
3 4 5
4 5 6

Unfortunately, Elsie got ahold of the table and permuted it by performing the following three types of operations as many times as she wanted.

  1. Swap two rows
  2. Swap two columns
  3. Select two values a and b that are both present in the table, then simultaneously change every occurrence of a to b and every occurrence of b to a.

Elsie will always perform operations in increasing order of type; that is, she performs as many operations as she likes (possibly none) first of type 1, then of type 2, and finally of type 3.

Help Bessie recover a possible state of the table after Elsie finished applying all of her operations of types 1 and 2, but before applying any operations of type 3.There may be multiple possible answers, in which case you should output the lexicographically smallest one.

To compare two tables lexicographically, compare the first entries at which they differ, when reading both tables in the natural order (rows from top to bottom, left to right within a row).

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N.

The next N lines each contain N integers, representing Bessie's addition table after Elsie has permuted it.

OUTPUT FORMAT (print output to the terminal / stdout):

The lexicographically minimum possible state of the table after all operations of types 1 and 2, but before any operations of type 3. It is guaranteed that the answer exists.

SAMPLE INPUT:

1
2

SAMPLE OUTPUT:

2
Regardless of what operations Elsie performs, the table won't change.

SAMPLE INPUT:

3
3 4 2
5 2 3
6 3 5

SAMPLE OUTPUT:

4 2 3
5 3 4
6 4 5

Here is a possible sequence of operations Elsie might have performed.

2 3 4
3 4 5
4 5 6
-> (op 1: swap columns 2 and 3)
2 4 3
3 5 4
4 6 5
-> (op 1: swap columns 1 and 2)
4 2 3
5 3 4
6 4 5
-> (op 3: swap values 2 and 3)
4 3 2
5 2 4
6 4 5
-> (op 3: swap values 3 and 4)
3 4 2
5 2 3
6 3 5

Note: the following is also a possible state of the table after operations of types 1 and 2, but it is not the lexicographically smallest because the second entry of the first row is larger than in the correct answer.

4 6 5
3 5 4
2 4 3

SAMPLE INPUT:

6
8 10 5 6 7 4
12 11 10 4 8 2
5 4 6 7 9 8
10 2 4 8 5 12
6 8 7 9 3 5
4 12 8 5 6 10

SAMPLE OUTPUT:

7 5 8 9 10 6
4 2 5 6 7 3
8 6 9 10 11 7
5 3 6 7 8 4
9 7 10 11 12 8
6 4 7 8 9 5

SCORING:

Inputs 4-5: N≤6
Inputs 6-7: N≤8
Inputs 8-11: N≤100
Inputs 12-15: No additional constraints.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码