advent-of-code/2023/6/main-1.cpp

40 lines
677 B
C++
Raw Permalink Normal View History

2023-12-06 20:40:03 -08:00
#include <bits/stdc++.h>
using namespace std;
inline int solve(int time, int distance) {
int ways = 0;
for (int i = 0; i <= time; i++) {
if (i * (time - i) > distance) {
ways++;
}
}
return ways;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vector<int> times, distances;
string line, line2;
getline(cin, line);
getline(cin, line2);
istringstream s1s(line), s2s(line2);
s1s.ignore(500, ':');
s2s.ignore(500, ':');
while (!s1s.eof()) {
int n;
s1s >> n;
times.push_back(n);
s2s >> n;
distances.push_back(n);
}
int ret = 1;
for (int i = 0; i < distances.size(); i++) {
ret *= solve(times[i], distances[i]);
}
cout << ret << '\n';
}