답안 #466246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466246 2021-08-18T11:52:15 Z idas Exam (eJOI20_exam) C++11
43 / 100
1000 ms 98516 KB
#include<bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PB push_back
#define F first
#define S second

const int INF=1e9;
const long long LINF=1e18;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;

void setIO()
{
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=5e3+10;
int n, a[N], b[N], t[2*N], dp[N][N];

void build()
{
    for(int i=n-1; i>=0; i--) t[i]=max(t[i<<1], t[i<<1|1]);
}

int get(int l, int r)
{
    int ret=0;
    for(l+=n, r+=n; l<r; l>>=1, r>>=1){
        if(l&1) ret=max(ret, t[l++]);
        if(r&1) ret=max(ret, t[--r]);
    }
    return ret;
}

int main()
{
    setIO();
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> a[i+1];
        t[i+n]=a[i+1];
    }
    FOR(i, 0, n) cin >> b[i+1];
    build();

    FOR(i, 1, n+1)
    {
        FOR(j, 1, n+1)
        {
            if(a[i]==b[j]){
                int mx=get(min(i-1, j-1), max(i, j));
                if(mx==a[i]){
                    dp[i][j]=1;
                    dp[i][j]+=max(dp[i][j-1], dp[i-1][j-1]);
                }
                else{
                    dp[i][j]=max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]);
                }
            }
            else{
                dp[i][j]=max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]);
            }
        }
    }

    cout << dp[n][n];
}

Compilation message

exam.cpp: In function 'void setIO(std::string)':
exam.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exam.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8268 KB Output is correct
2 Runtime error 7 ms 396 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 3 ms 3276 KB Output is correct
3 Correct 21 ms 24056 KB Output is correct
4 Correct 93 ms 94464 KB Output is correct
5 Correct 113 ms 98516 KB Output is correct
6 Correct 108 ms 98372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 98396 KB Output is correct
2 Runtime error 6 ms 392 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 2 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 3 ms 3276 KB Output is correct
9 Correct 21 ms 24056 KB Output is correct
10 Correct 93 ms 94464 KB Output is correct
11 Correct 113 ms 98516 KB Output is correct
12 Correct 108 ms 98372 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 2 ms 1228 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 1 ms 1228 KB Output is correct
22 Correct 9 ms 8268 KB Output is correct
23 Execution timed out 1087 ms 72072 KB Time limit exceeded
24 Halted 0 ms 0 KB -