summary refs log tree commit diff
path: root/22.6/main.cpp
blob: e7eee34379092bd08b4086af065947af18fc2e48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int
part1(string signal, int target)
{
	constexpr int amt = 'z' - 'a' + 1;
	int last[amt];
	int last_rep = -1;
	fill(begin(last), end(last), -10);
	for (int i = 0; i < signal.length(); i++) {
		int c = signal[i] - 'a';
		if (c >= amt) throw "bad input";
		last_rep = max(last_rep, last[c]);
		if (i - last_rep >= target) {
			return i + 1;
		}
		last[c] = i;
	}
	return -1;
}

int
main()
{
	for (string line; getline(cin, line); ) {
		cout << part1(line, 4) << endl;
		cout << part1(line, 14) << endl;
	}
}