Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Avoiding visited networked paths
//Code of C#oder AnantCT7 #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FOR(i,a,b) for(ll i=a;i<b;++i) #define FORD(i,a,b) for(ll i=a;i>=b;--i) #define pb push_back #define mp make_pair #define ll long long int #define s(x) scanf("%d", &x) #define sd(x) scanf("%lf", &x) #define sl(x) scanf("%lld", &x) #define ss(x) scanf("%s" ,x) #define fi first #define se second #define p(x) printf("%d",x) #define pl(x) printf("%lld", x) #define pd(x) printf("%lf", x) #define ps(x) printf("%s", x) #define pn() printf("\n") #define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define N 1007 #define P 107 #define Q 1361 #define R 10000019 #define MOD 1000000007 using namespace __gnu_pbds; using namespace std; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll dp[N][N][3][3][1]; ll arr[N][N]; ll n,m; ll fun(ll i,ll j,ll cnt1,ll cnt2,ll cnt3){ if((i>=n) || (i<0) || (j>=m) || (j<0)){ return 0; } ll ncnt1=cnt1,ncnt2=cnt2,ncnt3=cnt3,val=arr[i][j]; while((val%P)==0){ ncnt1++; val/=P; } while((val%Q)==0){ ncnt2++; val/=Q; } while((val%R)==0){ ncnt3++; val/=R; } ncnt1=min(ncnt1,2LL); ncnt2=min(ncnt2,2LL); ncnt3=min(ncnt3,1LL); if((i==(n-1)) && (j==(m-1))){ if((ncnt1==2) && (ncnt2==2) && (ncnt3==1)){ return 0; } return 1; } if(dp[i][j][ncnt1][ncnt2][ncnt3]!=-1){ return dp[i][j][ncnt1][ncnt2][ncnt3]; } return dp[i][j][ncnt1][ncnt2][ncnt3] = (fun(i+1,j,ncnt1,ncnt2,ncnt3) + fun(i,j+1,ncnt1,ncnt2,ncnt3))%MOD; } int main(){ FASTER; memset(dp,-1,sizeof(dp)); cin>>n>>m; FOR(i,0,n){ FOR(j,0,m){ cin>>arr[i][j]; } } cout<<fun(0,0,0,0,0)<<endl; return 0; }
run
|
edit
|
history
|
help
0
ugly quick sort
Bind Function
hacker
Dar
alma
CPPTemplate
vector destruction - gcc
RegexMatch
shell sort
Straight Max-Min Divide and Conquer