Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
xyp
#include<bits/stdc++.h> using namespace std; //DBEST TEMPLATE START #define ll long long int #define pb push_back #define mp make_pair #define T int t;cin >> t;while(t--) #define pii pair<int,int> #define pll pair<ll,ll> #define p(x) printf("%d",x) #define s(x) scanf("%d",&x) #define M 1000000007 #define Q int q;cin >> q;while(q--) #define Pi 3.1415926535897 #define endl '\n' #define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define kick(a,x) cout << "Case " << a << ": " << x << endl; #define ff first #define MM 1e18 #define ss second #define pp push #define err(x) cout << x << endl; ll power(ll x,ll y) { ll res=1; x%=M; while(y){ if(y&1) res=res*x%M; x=x*x%M; y = y/2; } return res; } ll get(ll x, ll b){ ll ret = 0; while(x % b == 0 && x > 0){ ret++; x = x/b; } return ret; } int main(){ ll n,m; cin >> n >> m; ll arr[n][m]; for(int i = 0; i < n;i++){ for(int j = 0; j < m;j++){ cin >> arr[i][j]; } } ll ans[n][m][3][3][2]; memset(ans,0,sizeof(ans)); ll a = get(arr[0][0],107); ll b = get(arr[0][0],1361); ll c = get(arr[0][0],10000019); if(a >= 2 && b >= 2 && c >= 1); else { a = min(a,2LL); b = min(b,2LL); c = min(c,1LL); ans[0][0][a][b][c] = 1; } ll p,q,r; for(int i = 1;i < m;i++){ ll x = get(arr[0][i],107); ll y = get(arr[0][i],1361); ll z = get(arr[0][i],10000019); for(int a = 0;a < 3; a++){ for(int b = 0;b < 3;b++){ for(int c = 0; c < 2;c++){ ll dum = ans[0][i-1][a][b][c]; if(x+a >= 2 && y+b >= 2 && z+c >= 1); else { p = min(x+a,2LL); q = min(y+b,2LL); r = min(z+c,1LL); ans[0][i][p][q][r] = (ans[0][i][p][q][r]+dum)%M; } } } } //cout << ans[0][i][0][0][0] << endl; } for(int i = 1;i < n;i++){ ll x = get(arr[i][0],107); ll y = get(arr[i][0],1361); ll z = get(arr[i][0],10000019); for(int a = 0;a < 3; a++){ for(int b = 0;b < 3;b++){ for(int c = 0; c < 2;c++){ ll dum = ans[i-1][0][a][b][c]; if(x+a >= 2 && y+b >= 2 && z+c >= 1); else { p = min(x+a,2LL); q = min(y+b,2LL); r = min(z+c,1LL); ans[i][0][p][q][r] = (ans[i][0][p][q][r]+dum)%M; } } } } // cout << ans[i][0][0][0][0] << endl; } for(int i = 1 ; i < n;i++){ for(int j = 1 ; j < m;j++){ ll x = get(arr[i][j],107); ll y = get(arr[i][j],1361); ll z = get(arr[i][j],10000019); // cout <<ans[i][j][0][0][0] <<" "; for(int a = 0;a < 3; a++){ for(int b = 0;b < 3;b++){ for(int c = 0; c < 2;c++){ ll dum = ans[i-1][j][a][b][c]; // if(a == 0 && b ==0 && c ==0) // cout << endl << dum << "D" << endl; if(x+a >= 2 && y+b >= 2 && z+c >= 1); else { p = min(x+a,2LL); q = min(y+b,2LL); r = min(z+c,1LL); ans[i][j][p][q][r] = (ans[i][j][p][q][r]+dum)%M; } } } } for(int a = 0;a < 3; a++){ for(int b = 0;b < 3;b++){ for(int c = 0; c < 2;c++){ ll dum = ans[i][j-1][a][b][c]; //if(a == 0 && b ==0 && c ==0) // cout << dum << "D" << endl; if(x+a >= 2 && y+b >= 2 && z+c >= 1); else { p = min(x+a,2LL); q = min(y+b,2LL); r = min(z+c,1LL); ans[i][j][p][q][r] = (ans[i][j][p][q][r]+dum)%M; } } } } //cout <<ans[i][j][0][0][0] <<" "; } //cout << endl; } ll ret = 0; for(int a = 0;a < 3; a++){ for(int b = 0;b < 3;b++){ for(int c = 0; c < 2;c++){ if(a >= 2 && b >= 2 && c >= 1); else { ret = (ret + ans[n-1][m-1][a][b][c])%M; } } } } cout << ret << endl; }
run
|
edit
|
history
|
help
0
new
string match2
Stream2
on_off
pranav pandey
Wave Sort
GL interview
mutable constexpr
773. Sliding Puzzle
Vectors as Inputs to Map