File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Contests/AtCoder Beginner Contest 121/Explanations Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ Calculate the Dot Product of every row of A with B and check for which rows A[i].B + C > 0
2
+
3
+ -----
4
+
5
+ #include <iostream>
6
+ #include <vector>
7
+ #include <algorithm>
8
+
9
+ using namespace std;
10
+
11
+ int dot_product(vector <int> &A, vector <int> &B)
12
+ {
13
+ int answer = 0;
14
+ for(int i = 1; i < A.size(); i++)
15
+ {
16
+ answer += A[i]*B[i];
17
+ }
18
+ return answer;
19
+ }
20
+
21
+ int main()
22
+ {
23
+ int no_of_rows, no_of_columns, C;
24
+ cin >> no_of_rows >> no_of_columns >> C;
25
+
26
+ vector <int> B(no_of_columns + 1);
27
+ for(int i = 1; i <= no_of_columns; i++)
28
+ {
29
+ cin >> B[i];
30
+ }
31
+
32
+ vector <vector <int> > A(no_of_rows + 1, vector <int> (no_of_columns + 1));
33
+ for(int i = 1; i <= no_of_rows; i++)
34
+ {
35
+ for(int j = 1; j <= no_of_columns; j++)
36
+ {
37
+ cin >> A[i][j];
38
+ }
39
+ }
40
+
41
+ int good_rows = 0;
42
+ for(int i = 1; i <= no_of_rows; i++)
43
+ {
44
+ good_rows += (dot_product(A[i], B) + C > 0);
45
+ }
46
+
47
+ cout << good_rows << "\n";
48
+
49
+ return 0;
50
+ }
51
+
52
+
53
+
You can’t perform that action at this time.
0 commit comments