Submission #9789200
Source Code Expand
Copy
#include<iostream> #include<string> #include<algorithm> #include<stack> #include<math.h> #include<map> #include<unordered_map> #include<vector> #include<queue> #include<set> #include<deque> #include<bitset> #include<string> #define N 40 #define K 300005 #define MOD 1e9+7 #define int long long #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; int n; int mod = 1e9 + 7; vector<vector<int>> pro(vector<vector<int>> mat1, vector<vector<int>> mat2){ vector<vector<int>>ans(n, vector<int>(n,0)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int t = 0; for(int k = 0; k<n;k++){ t += (mat1[i][k] * mat2[k][j]); if(t >= mod) t %= mod; } ans[i][j] = t; } } return ans; } vector<vector<int>> solve(vector<vector<int>> mat, int p){ if(p == 1){ return mat; } vector<vector<int>>temp(n, vector<int>(n)); vector<vector<int>>ans(n, vector<int>(n)); temp = solve(mat, p/2); ans = pro(temp, temp); if(p %2 == 0) return ans; else return pro(ans, mat); } int32_t main(){ int k; cin>>n>>k; if(n == 1){ cout<<0; return 0; } vector<vector<int>>a(n, vector<int>(n)); vector<int>col(n); for(int i=0;i<n;i++){ int o = 0; for(int j=0;j<n;j++){ cin>>a[i][j]; o += a[i][j]; } col[i] = o; } vector<vector<int>>res(n, vector<int>(n)); res = solve(a, k-1); int for_each[n]; for(int i=0;i<n;i++){ for_each[i] = 0; int t = 0; for(int j = 0; j<n; j++){ t += (res[i][j] * col[j]); if(t >= mod) t %= mod; } for_each[i] = t; } int ans = 0; for(int i=0;i<n;i++){ ans += for_each[i]; if(ans >= mod) ans -= mod; } cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | R - Walk |
User | Andu110299 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1818 Byte |
Status | |
Exec Time | 2583 ms |
Memory | 5620 KB |
Test Cases
Set Name | Score / Max Score | Test Cases |
---|---|---|
All | 0 / 100 | 0_00, 0_01, 0_02, 0_03, 0_04, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00 | 1 ms | 256 KB | |
0_01 | 1 ms | 256 KB | |
0_02 | 1 ms | 256 KB | |
0_03 | 1 ms | 256 KB | |
0_04 | 2 ms | 512 KB | |
1_00 | 1 ms | 256 KB | |
1_01 | 1 ms | 256 KB | |
1_02 | 2583 ms | -628484 KB | |
1_03 | 29 ms | 5620 KB | |
1_04 | 2076 ms | -628300 KB | |
1_05 | 156 ms | 5620 KB | |
1_06 | 2003 ms | -628260 KB | |
1_07 | 158 ms | 5492 KB | |
1_08 | 151 ms | 4096 KB | |
1_09 | 140 ms | 4224 KB | |
1_10 | 109 ms | 3840 KB | |
1_11 | 113 ms | 3968 KB | |
1_12 | 105 ms | 3712 KB | |
1_13 | 132 ms | 4224 KB | |
1_14 | 124 ms | 3712 KB | |
1_15 | 135 ms | 4096 KB | |
1_16 | 142 ms | 4224 KB | |
1_17 | 146 ms | 4224 KB |