advent-of-code/2023/6/main-2.cpp
2023-12-06 20:40:03 -08:00

33 lines
654 B
C++

#include <bits/stdc++.h>
using namespace std;
inline long solve(long time, long distance) {
long ways = 0;
for (long i = 0; i <= time; i++) {
if (i * (time - i) > distance) {
ways++;
}
}
return ways;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long time, distance;
string line, line2;
getline(cin, line);
line.erase(remove(line.begin(), line.end(), ' '), line.end());
istringstream s1s(line);
s1s.ignore(500, ':');
s1s >> time;
getline(cin, line);
line.erase(remove(line.begin(), line.end(), ' '), line.end());
istringstream s2s(line);
s2s.ignore(500, ':');
s2s >> distance;
cout << solve(time, distance) << '\n';
}