Authors: Nathan Wang, Benjamin Qi, Maggie Liu

Prerequisites

StepsCode ConventionsC++

See Working With MDX for additional information.

Steps

1. Fork the GitHub repository.

2. If it doesn't already exist, create a new mdx file in solutions/ including frontmatter, ex. the following in USACO jan17-cow-dance-show.mdx:

---
id: usaco-690
source: USACO Silver 2017 January
title: Cow Dance Show
author: Óscar Garries
---

[Official Analysis](http://www.usaco.org/current/data/sol_cowdance_silver_jan17.html)

## Explanation

Use \texttt{} around variable names with length *greater than one*, like so. Place long equations on separate lines with display math, and use \cdot instead of * to denote multiplication.

$$\texttt{arr}[i]=2\cdot (a+b+c+d+e)+\sum_{j=0}^{i-1}\texttt{arr}[j]$$

Some additional text styles which you might consider using:

http://latexref.xyz/Font-styles.html

http://applied-r.com/latex-font-styles/

$func(var)$

$\textit{func(var)}$

$\textrm{func(var)}$

$\text{func(var)}$

$\textsf{func(var)}$

$\textbf{func(var)}$

$\texttt{func(var)}$

## Implementation

**Time Complexity:** $\mathcal{O}(N\log^2N)$

^ Format time complexity like this. Should appear outside of <LanguageSection> if it's the same for all implementations.

<LanguageSection>

<CPPSection>

</CPPSection>

<PySection>

(if you have Python code)

</PySection>

<JavaSection />

{/*  if you have no Java code */}

</LanguageSection>

Keep file names and solution IDs consistent; namely, USACO IDs should correspond to the URL on usaco.org.

• Use tabs to indent.

• Lines should not exceed 80 characters.

• Be consistent about formatting your code, unlike the following snippet. We don't care about which one you use (a+b or a + b), but pick one and stick with it!

a,b = (0,1)print(a+b)print(a + b)

It is not necessary to add an alternative implementation in the same language as the official analysis (unless the alternative implementation takes a different approach or is written better / differently from the official implementation).

4. In the module's .problems.json file (in this case, Binary_Search.problems.json), change the kind of the solutionMetadata field to internal and remove all other fields. Also add tags (if you want). If the problem is not in a module, you can add the problem to extraProblems.json.

{
"uniqueId": "usaco-690",
"name": "Cow Dance Show",
"url": "http://www.usaco.org/index.php?page=viewproblem2&cpid=690",
"source": "Silver",
"difficulty": "Easy",
"isStarred": false,
"tags": ["Binary Search", "Ordered Set"],
"kind": "internal"
}
},
5. Check that both the module and the solution render properly using the live editor before submitting a pull request.

Code Conventions

Since code for the USACO Guide is contributed from several authors, code style will not be uniform. Of course, we still strive for code that is readable and understandable. If any code does not compile or is hard to read, please contact us.

Please read the following resource before contributing code (although you do not have to follow all of the recommendations):

Resources
CF

C++ style guide

This section is not complete.

Any help would be appreciated! Just submit a Pull Request on Github.

C++

C++

For Bronze through Gold, please only use the macros listed in the template below (see Github #806):

#include <bits/stdc++.h> // see /general/running-code-locallyusing namespace std;
using ll = long long;
using vi = vector<int>;#define pb push_back#define all(x) begin(x), end(x)#define sz(x) (int)(x).size()


You don't have to use the template, but avoid using additional macros beyond the ones listed above. In particular, for loop macros are highly discouraged.

Java

Java

Regarding input and output, Scanner is significantly slower than BufferedReader and should be avoided.

To improve readability, Java solutions using BufferedReader should use a wrapper class around input (preferably Kattio for consistency, or use your own variant if you really want).

Python

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!