답안 #412202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412202 2021-05-26T15:38:05 Z Theo830 Exam (eJOI20_exam) C++17
65 / 100
235 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a[n],b[n];
    f(i,0,n){
        cin>>a[i];
    }
    f(i,0,n){
        cin>>b[i];
    }
    ll l[n],r[n];
    priority_queue<ii,vector<ii>,greater<ii> >pq;
    f(i,0,n){
        pq.push(ii(a[i],i));
        while(pq.top().F < a[i]){
            r[pq.top().S] = i-1;
            pq.pop();
        }
    }
    while(!pq.empty()){
        r[pq.top().S] = n-1;
        pq.pop();
    }
    for(ll i=n-1;i >= 0;i--){
        pq.push(ii(a[i],i));
        while(pq.top().F < a[i]){
            l[pq.top().S] = i+1;
            pq.pop();
        }
    }
    while(!pq.empty()){
        l[pq.top().S] = 0;
        pq.pop();
    }
    ll dp[n+1][n+1];
    f(i,0,n+1){
        f(j,0,n+1){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                if(a[i-1] == b[j-1] && (l[i-1] <= j-1 && j-1 <= r[i-1])){
                    dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                }
            }
        }
    }
    cout<<dp[n][n]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4172 KB Output is correct
2 Runtime error 218 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
3 Correct 23 ms 16044 KB Output is correct
4 Correct 127 ms 90676 KB Output is correct
5 Correct 142 ms 98276 KB Output is correct
6 Correct 151 ms 98360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 98284 KB Output is correct
2 Runtime error 235 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 1228 KB Output is correct
9 Correct 23 ms 16044 KB Output is correct
10 Correct 127 ms 90676 KB Output is correct
11 Correct 142 ms 98276 KB Output is correct
12 Correct 151 ms 98360 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 7 ms 4172 KB Output is correct
23 Correct 181 ms 98404 KB Output is correct
24 Correct 173 ms 98380 KB Output is correct
25 Correct 143 ms 98356 KB Output is correct
26 Correct 137 ms 98288 KB Output is correct
27 Correct 138 ms 98280 KB Output is correct
28 Correct 142 ms 98276 KB Output is correct
29 Correct 142 ms 98424 KB Output is correct
30 Correct 138 ms 98376 KB Output is correct
31 Correct 140 ms 98300 KB Output is correct
32 Correct 145 ms 98328 KB Output is correct