Advertisement
Guest User

Newton School C

a guest
Nov 30th, 2022
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. typedef long long ll;
  5. #define pb push_back
  6. #define ff first
  7. #define ss second
  8. const int N=2e3+7;
  9. const int mod=998244353;
  10. const double eps=1e-9;
  11. const double pi=    3.14159265358979323846;
  12. using namespace std;  
  13. using namespace __gnu_pbds;
  14. typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
  15.              tree_order_statistics_node_update>
  16.     op_set;
  17.  
  18. int32_t main()
  19. {
  20.    ios_base::sync_with_stdio(false);
  21.    cin.tie(0);
  22.  
  23.    int n;
  24.    cin >> n;
  25.  
  26.    int ar[n];
  27.    for(int i=0;i<n;i++)
  28.         cin >> ar[i];
  29.    int br[n];
  30.    for(int i=0;i<n;i++)
  31.         cin >> br[i];
  32.    int cr[n];
  33.    for(int i=0;i<n;i++)
  34.         cin >> cr[i];
  35.    
  36.    vector<vector<long long>> dp(n+1,vector<long long>(n+1,0ll));
  37.    dp[0][0]=1ll;
  38.  
  39.    for(int i=1;i<=n;i++)
  40.    {
  41.         vector<vector<long long>> pre(n+1,vector<long long>(n+1,0ll));
  42.         pre[0][0]=dp[0][0];
  43.         for(int row=1;row<=n;row++)
  44.             pre[row][0]=pre[row-1][0]+dp[row][0];
  45.         for(int col=1;col<=n;col++)
  46.             pre[0][col]=pre[0][col-1]+dp[0][col];
  47.         for(int row=1;row<=n;row++)
  48.             for(int j=1;j<=n;j++)
  49.                 pre[row][j]=dp[row][j]+pre[row-1][j]+pre[row][j-1]-pre[row-1][j-1];
  50.            
  51.         for(int a=1;a<=n;a++)
  52.         {
  53.             for(int b=1;b<=n;b++)
  54.             {
  55.                 if(ar[a-1]==cr[i-1] &&cr[i-1]==br[b-1])
  56.                     dp[a][b]=(dp[a][b]+pre[a-1][b-1])%mod;
  57.             }
  58.         }
  59.    }
  60.  
  61.    long long ans=0ll;
  62.    for(int i=1;i<=n;i++)
  63.         for(int j=1;j<=n;j++)
  64.             ans=(ans+dp[i][j])%mod;
  65.    
  66.    cout << ans << "\n";
  67. }
  68.  
  69. /*
  70. And this shit sucks, need some love, my Aphrodite I can touch
  71. When I cry at night, like every night, just come right here and see
  72. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement