LCOV - code coverage report
Current view: top level - 13 - b.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 23 23
Test Date: 2025-10-12 18:20:59 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100.0 % 10 10

             Branch data     Line data    Source code
       1                 :             : #include <iostream>
       2                 :             : #include <fstream>
       3                 :             : #include <regex>
       4                 :             : using namespace std;
       5                 :             : 
       6                 :           2 : int main() {
       7                 :           2 :     ifstream infile("input.txt");
       8         [ +  + ]:           2 :     if (!infile) {
       9                 :           1 :         cerr << "Error opening file" << endl;
      10                 :           1 :         return 1;
      11                 :             :     }
      12                 :             : 
      13                 :           1 :     string content((istreambuf_iterator<char>(infile)), istreambuf_iterator<char>());
      14                 :           1 :     regex rx(R"(Button A: X([+-]?\d+), Y([+-]?\d+)\nButton B: X([+-]?\d+), Y([+-]?\d+)\nPrize: X=([+-]?\d+), Y=([+-]?\d+))");
      15                 :             :     
      16                 :           1 :     int64_t res = 0;
      17         [ +  + ]:         321 :     for (sregex_iterator it(content.begin(), content.end(), rx), end; it != end; ++it) {
      18                 :         320 :         auto& m = *it;
      19                 :         320 :         int64_t ax = stoi(m[1]);
      20                 :         320 :         int64_t ay = stoi(m[2]);
      21                 :         320 :         int64_t bx = stoi(m[3]);
      22                 :         320 :         int64_t by = stoi(m[4]);
      23                 :         320 :         int64_t X = stoll(m[5]) + 10000000000000;
      24                 :         320 :         int64_t Y = stoll(m[6]) + 10000000000000;
      25                 :         320 :         int64_t b = (Y * ax - X * ay) / (by * ax - bx * ay);
      26                 :         320 :         int64_t a = (X - b * bx) / ax;
      27   [ +  +  +  + ]:         320 :         if (a * ax + b * bx == X && a * ay + b * by == Y) {
      28                 :         147 :             res += 3 * a + b;
      29                 :             :         }
      30                 :           1 :     }
      31                 :             : 
      32                 :           1 :     cout << res << endl;
      33         [ +  + ]:           3 : }
        

Generated by: LCOV version 2.0-1