# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
641619 | 2022-09-17T10:08:56 Z | manizare | Exam (eJOI20_exam) | C++14 | 1000 ms | 524288 KB |
#include<bits/stdc++.h> #define all(a) a.begin(),a.end() #define pb push_back using namespace std ; const int maxn = 5002 , maxq = 1e5+10 , mod = 998244353 ,inf = 1e18 ; int dp[3][maxn][maxn] , a[maxn] , b[maxn] , l[maxn] , r[maxn] ; stack<int> s , t; signed main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n ; cin >>n ; for(int i =1 ; i <= n ; i++){ cin >> a[i]; } for(int i= 1; i <= n ; i++){ while(s.size() && a[i] >= a[s.top()])s.pop(); if(s.size() == 0){ l[i] = 0 ; }else{ l[i] = s.top(); } s.push(i); } for(int i = n; i >= 1 ; i--){ while(t.size() && a[i] >= a[t.top()])t.pop(); if(t.size() == 0){ r[i] = n+1 ; }else{ r[i] = t.top(); } t.push(i); } for(int i = 1; i <= n ; i++){ cin >> b[i] ; // cout << l[i] << " " << r[i] <<"<-\n"; } for(int i = 1; i <= n ; i++){ for(int j =1 ; j <= n ; j++){ dp[0][i][j] = max(dp[0][i-1][j] , dp[1][i-1][j]); dp[1][i][j] = max(dp[0][i-1][j-1] , dp[1][i][j-1]) + ((j > l[i] && r[i] > j) && a[i] == b[j]) ; } } for(int i = 1; i <= n ; i++){ for(int j =1 ; j <= n ; j++){ // cout << dp[0][i][j] << " " << dp[1][i][j] << " "; } // cout << "\n"; } cout << max(dp[0][n][n] , dp[1][n][n]) << "\n"; return 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Incorrect | 1 ms | 332 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 16200 KB | Output is correct |
2 | Execution timed out | 1042 ms | 524288 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 176 ms | 196316 KB | Output is correct |
2 | Execution timed out | 1090 ms | 245196 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Incorrect | 1 ms | 332 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Incorrect | 1 ms | 332 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |