Skip to content

Commit

Permalink
div7
Browse files Browse the repository at this point in the history
  • Loading branch information
megargayu committed Oct 10, 2022
1 parent a3cc0aa commit be2b777
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions contests/silver/2016/january/div7/div7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// #include <bits/stdc++.h> // for some reason the USACO grader doesn't like this for this problem?
#include <fstream>
#include <vector>
using namespace std;

#define MAX_N 50000
#define ll long long

vector<ll> cows(MAX_N + 1);

int main()
{
ifstream fin("div7.in");
ofstream fout("div7.out");

int N;
fin >> N;

cows[0] = 0;

for (int i = 1; i <= N; ++i)
{
fin >> cows[i];
}

for (int i = 1; i <= N; ++i)
{
cows[i] += cows[i - 1];
cows[i] %= 7;
}

vector<int> firstSum(7, -1);
int answer = 0;
for (int i = 1; i <= N; ++i)
{
if (firstSum[cows[i]] != -1)
answer = max(answer, i - firstSum[cows[i]]);
else
firstSum[cows[i]] = i;
}

fout << answer << '\n';

return 0;
}
8 changes: 8 additions & 0 deletions contests/silver/2016/january/div7/div7.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7
3
5
1
6
2
14
10
1 change: 1 addition & 0 deletions contests/silver/2016/january/div7/div7.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5

0 comments on commit be2b777

Please sign in to comment.