# USACO 2017 January Contest, Bronze Problem 3. Cow Tipping

## Problem Info

USACO 2017 January Contest, Bronze Problem 3. Cow Tipping

## My Work

``````#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b); for (int i = a; i < b; i++)
int main()
{
freopen("cowtip.in","r",stdin);
freopen("cowtip.out","w",stdout);
int n;
cin >> n;
vector<string> data;
string line;
bool swaps[n][n];
int ans = 0;
int word;
//set up bool array
FOR(i,0,n) {
FOR(j,0,n) {
swaps[i][j] = false;
}
}
//set up data
FOR(i,0,n) {
cin >> line;
data.push_back(line);
}
//decide if a new flip is needed
FOR(i,0,n) {
FOR(j,0,n) {
if(data[i][j] == '0') {
continue;
}else if(swaps[i][j] == true) {
continue;
}else {
//decide how big the flip should be
FOR(l,0,n - i) {
FOR(k,0,n - j) {
if(data[i+l][j + k] == '0') {
if(data[i+l + 1][j] == '1') {
continue;
}else {
ans += 1;
break;
}
}else if(j+k == n -1 && i+l == n -1) {
swaps[i+l][j+k] = true;
ans += 1;
break;
}else{
swaps[i+l][j+k] = true;
}
}
}
}
}
}
cout << ans;

}
``````

I created a bool array to keep track of what cows have already been flipped. the first 4 test cases ran fine but from the 5th test case it shows a run time error.

## Question

Why the error happened when the first 4 test case run fine.