File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+
4
+ using namespace std ;
5
+
6
+ long long power_mod (long long x, long long power, long long mod)
7
+ {
8
+ long long result = 1 ;
9
+
10
+ while (power)
11
+ {
12
+ if (power%2 == 1 )
13
+ result = (result*x)%mod;
14
+
15
+ x = (x*x)%mod;
16
+ power = power >> 1 ;
17
+ }
18
+
19
+ return result;
20
+ }
21
+
22
+ void solve ()
23
+ {
24
+ int rows, columns;
25
+ cin >> rows >> columns;
26
+
27
+ vector <string> grid (rows);
28
+ for (int i = 0 ; i < rows; i++)
29
+ {
30
+ cin >> grid[i];
31
+ }
32
+
33
+ const char FREE_SPACE = ' #' ;
34
+ int free_spaces = 0 ;
35
+ for (int r = 0 ; r < rows; r++)
36
+ {
37
+ for (int c = 0 ; c < columns; c++)
38
+ {
39
+ free_spaces += (grid[r][c] == FREE_SPACE);
40
+ }
41
+ }
42
+
43
+ const int MOD = 1e9 + 7 ;
44
+ long long answer = power_mod (2 , free_spaces, MOD);
45
+
46
+ if (free_spaces == rows*columns)
47
+ {
48
+ answer = (answer + MOD - 1 )%MOD;
49
+ }
50
+
51
+ cout << answer << " \n " ;
52
+ }
53
+
54
+ int main ()
55
+ {
56
+ int no_of_test_cases;
57
+ cin >> no_of_test_cases;
58
+
59
+ while (no_of_test_cases--)
60
+ solve ();
61
+
62
+ return 0 ;
63
+ }
64
+
You can’t perform that action at this time.
0 commit comments