# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
463588 | 2021-08-11T10:40:43 Z | kilikuma | Exam (eJOI20_exam) | C++14 | 45 ms | 460 KB |
#include <bits/stdc++.h> using namespace std; struct Segment { int deb, fin; }; bool comp(Segment a, Segment b) { if (a.deb < b.deb) return (a.deb < b.deb); else return (a.fin < b.fin); } int main() { int N; scanf("%d",&N); int A[5005], B[5005]; int nbSegments =0; Segment seg[5005]; int dp[5005]; for (int i=0;i<5005;i++) { dp[i] = -1; } dp[0] = N+1; for (int i=1;i<=N;i++) { scanf("%d",&A[i]); } for (int i=1;i<=N;i++) { scanf("%d",&B[i]); } for (int i=1;i<=N;i++) { for (int j=i; j<= N; j++) { if (A[j] == B[i]) { seg[nbSegments].deb = i; seg[nbSegments].fin = j; nbSegments ++; } } } sort(seg, seg + nbSegments, comp); int dp1[5005]; for (int iSegment = nbSegments-1;iSegment >= 0; iSegment--) { for (int i=0;i<5005;i++) dp1[i] = -1; for (int iCase = 0; iCase <= nbSegments; iCase ++) { if (dp[iCase] == -1) ; else { if (seg[iSegment].fin <= dp[iCase]) { dp1[iCase+1] = max(dp[iCase+1], seg[iSegment].fin); } } } for (int iCase =0; iCase <=nbSegments;iCase ++) { if(dp1[iCase] != -1) dp[iCase] = dp1[iCase]; } } int maxi =0; for (int iCase = 0; iCase <= nbSegments; iCase ++) { if (dp[iCase] != -1) maxi = max(maxi, iCase); } printf("%d\n", maxi); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Incorrect | 1 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 45 ms | 404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 460 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Incorrect | 1 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Incorrect | 1 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |