Advertisement
Guest User

Code

a guest
Nov 30th, 2022
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | Source Code | 0 0
  1. /* Creation Date - 30-11-2022 */
  2. /* Creation Time - 20:53:26.80 */
  3. #define ill
  4. #define mod_2
  5. /*
  6. Written By : mafailure
  7. In the name of God
  8. O Allah, May you grant peace and honor on Muhammad and his family.
  9. Allahumm-a-Sall-iAla Muhammad-in Wa Al-i Muhammad
  10. */
  11.  
  12. #ifdef LOCAL
  13. #define AATIF_DEBUG
  14. #endif
  15. /*Add -DLOCAL in
  16. compiler command
  17. to trigger it*/
  18.  
  19. #include<bits/stdc++.h>
  20. #include <ext/pb_ds/assoc_container.hpp> // Common file
  21. #include <ext/pb_ds/tree_policy.hpp>
  22. #include <functional> // for less
  23. using namespace std;
  24. using namespace __gnu_pbds;
  25. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  26.  
  27. #define endl "\n"
  28. /*------------------------int to long long -----------------*/
  29. #ifdef ill
  30. #define int long long
  31. #endif
  32. /*---------------------------DEBUG HELPER--------------------------------------*/
  33. template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
  34. template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
  35. template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
  36. template<typename T,typename K> ostream& operator<<(ostream & os,const map<T,K> & mapp){ os<<"{"; string sep=""; for(const auto& x:mapp)os<<sep<<x,sep=", "; return os<<'}'; }
  37. template <typename T> ostream & operator<<(ostream & os,const set<T> & sett){os<<'{'; string sep=""; for(const auto & x:sett)os<<sep<<x,sep=", "; return os<<'}';}
  38.  
  39. void dbg_out() { cerr << endl; }
  40. template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
  41.  
  42. #ifdef AATIF_DEBUG
  43. #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
  44. #else
  45. #define dbg(...)
  46. #endif
  47.  
  48. //#define int long long
  49. // int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
  50. // int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
  51. #ifndef mod_2
  52. long long mod = 1e9 + 7;
  53. #else
  54. long long mod =998244353;
  55. #endif
  56. const double eps=1e-9;
  57. typedef vector<int> vi;
  58. typedef vector<vi> vvi;
  59. typedef vector<string> vs;
  60. typedef vector<bool> vb;
  61. typedef pair<int, int> ii;
  62. typedef vector< pair< int, int > > vii;
  63. typedef map<int, int> mii;
  64. typedef pair<int, ii> pip;
  65. typedef pair<ii, int> ppi;
  66. #define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
  67. #define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
  68. #define w(t) int t;cin>>t; while(t--)
  69. #define takeInp(n) int n;cin>>n;
  70. #define fr(i,init,final) for(int i=init;i<final;i++)
  71. #define frr(i,init,final) for(int i=init;i>=final;i--)
  72. #define Fr(i,final) for(int i=0;i<final;i++)
  73. #define Frr(i,first) for(int i=first;i>=0;i--)
  74. #define fi first
  75. #define se second
  76. #define mp make_pair
  77. #define pb push_back
  78. #define all(c) (c).begin(),(c).end()
  79. #define rall(c) (c).rbegin(),(c).rend()
  80. #define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
  81. #define setb __builtin_popcount
  82. #define lsone(n) (n&(-n))
  83. #define rlsone(n) (n&(n-1))
  84. #define clr(a,b) memset(a,b,sizeof(a))
  85. #ifdef ill
  86. const int inf =1e18;
  87. #else
  88. const int inf=1e9;
  89. #endif
  90. /*-----------------------------RANDOM NUMBER GENERATOR ---------------------*/
  91. #ifdef RNG
  92. unsigned seed=chrono::high_resolution_clock::now().time_since_epoch().count();
  93. mt19937 rng(seed);
  94. #endif
  95. /*------------------------------UNORDERED MAP HASH --------------------------------------------*/
  96. //To make unordered_map unhackable
  97. // use it as unordered_map<int,int,custom_hash> mapp;
  98. struct custom_hash {
  99. static uint64_t splitmix64(uint64_t x) {
  100. /* http://xorshift.di.unimi.it/splitmix64.c */
  101. x += 0x9e3779b97f4a7c15;
  102. x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  103. x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  104. return x ^ (x >> 31);
  105. }
  106.  
  107. size_t operator()(uint64_t x) const {
  108. static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  109. return splitmix64(x + FIXED_RANDOM);
  110. }
  111. };
  112. /*---------------------------ORDERED SET--------------------------------------*/
  113. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  114. /*----------------------------------------------------------------------------*/
  115. vi init(string s)
  116. {
  117. istringstream sin(s);
  118. int n;
  119. vi arr;
  120. while(sin>>n)arr.push_back(n);
  121. return arr;
  122. }
  123. int power(int x, int y)
  124. {
  125. if(y==0)return 1;
  126. int u=power(x,y/2);
  127. u=(u*u)%mod;
  128. if(y%2)u=(x*u)%mod;
  129. return u;
  130.  
  131. }
  132. int gcd(int a,int b)
  133. {
  134. if(a<b)return gcd(b,a);
  135. return (b==0?a:(a%b?gcd(b,a%b):b));
  136. }
  137. int gcd_e(int a,int b,int &x,int &y)
  138. {
  139.  
  140. if(b==0){x=1; y=0; return a;}
  141. int x1,y1;
  142. int p=gcd_e(b,a%b,x1,y1);
  143. x=y1;
  144. y=x1-(a/b)*y1;
  145. return p;
  146. }
  147. /*-----------------to solve int to long long problem-----------------*/
  148. int Min (int a,int b){return min(a,b);}
  149. int Max(int a,int b){ return max(a,b);}
  150. inline int add(int a,int b,int mod=mod){return (a+b)%mod;}
  151. inline int sub(int a,int b,int mod=mod){return (a-b+mod)%mod;}
  152. inline int mul(int a,int b,int mod=mod){return (a*b%mod);}
  153. inline int divide(int a,int b,int mod=mod){return a*power(b,mod-2)%mod;}
  154. inline int high(int a,int b){return (a>>b)&1;}
  155. //786 121 786 121 786 121 786 121 786 121 786 121 786 121 786 121 786 121
  156. /*========================CODE*****CODE****CODE======================*/
  157.  
  158. int dp[101][101][101];
  159. signed main()
  160. {
  161. IOS
  162.  
  163. dp[0][0][0]=1;
  164. int n;
  165. cin>>n;
  166. vi a(n),b(n),c(n);
  167. fr(i,0,n)cin>>a[i];
  168. fr(i,0,n)cin>>b[i];
  169. fr(i,0,n)cin>>c[i];
  170. //int t=0;
  171. int ans=0;
  172. for(int i=0;i<n;i++)
  173. {
  174. for(int j=0;j<n;j++)
  175. {
  176. for(int k=0;k<n;k++)
  177. {
  178. if(j&&k)dp[i][j][k]=sub(dp[i][j][k],dp[i][j-1][k-1]);
  179. if(i&&j)dp[i][j][k]=sub(dp[i][j][k],dp[i-1][j-1][k]);
  180. if(i&&k)dp[i][j][k]=sub(dp[i][j][k],dp[i-1][j][k-1]);
  181. if(i&&j&&k)dp[i][j][k]=add(dp[i][j][k],dp[i-1][j-1][k-1]);
  182. dp[i][j+1][k]=add(dp[i][j+1][k],dp[i][j][k]);
  183. dp[i][j][k+1]=add(dp[i][j][k+1],dp[i][j][k]);
  184. dp[i+1][j][k]=add(dp[i+1][j][k],dp[i][j][k]);
  185. if(a[i]==b[j]&&b[j]==c[k])dp[i+1][j+1][k+1]=add(dp[i+1][j+1][k+1],dp[i][j][k]),ans=add(ans,dp[i][j][k]);
  186. }
  187. }
  188. }
  189. cout<<ans<<endl;
  190.  
  191.  
  192.  
  193.  
  194.  
  195. }
  196.  
  197.  
  198.  
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement