Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- typedef long long ll;
- #define pb push_back
- #define ff first
- #define ss second
- const int N=2e3+7;
- const int mod=998244353;
- const double eps=1e-9;
- const double pi= 3.14159265358979323846;
- using namespace std;
- using namespace __gnu_pbds;
- typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
- tree_order_statistics_node_update>
- op_set;
- int32_t main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- int ar[n];
- for(int i=0;i<n;i++)
- cin >> ar[i];
- int br[n];
- for(int i=0;i<n;i++)
- cin >> br[i];
- int cr[n];
- for(int i=0;i<n;i++)
- cin >> cr[i];
- vector<vector<long long>> dp(n+1,vector<long long>(n+1,0ll));
- dp[0][0]=1ll;
- for(int i=1;i<=n;i++)
- {
- vector<vector<long long>> pre(n+1,vector<long long>(n+1,0ll));
- pre[0][0]=dp[0][0];
- for(int row=1;row<=n;row++)
- pre[row][0]=pre[row-1][0]+dp[row][0];
- for(int col=1;col<=n;col++)
- pre[0][col]=pre[0][col-1]+dp[0][col];
- for(int row=1;row<=n;row++)
- for(int j=1;j<=n;j++)
- pre[row][j]=dp[row][j]+pre[row-1][j]+pre[row][j-1]-pre[row-1][j-1];
- for(int a=1;a<=n;a++)
- {
- for(int b=1;b<=n;b++)
- {
- if(ar[a-1]==cr[i-1] &&cr[i-1]==br[b-1])
- dp[a][b]=(dp[a][b]+pre[a-1][b-1])%mod;
- }
- }
- }
- long long ans=0ll;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- ans=(ans+dp[i][j])%mod;
- cout << ans << "\n";
- }
- /*
- And this shit sucks, need some love, my Aphrodite I can touch
- When I cry at night, like every night, just come right here and see
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement