답안 #467095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467095 2021-08-21T17:18:48 Z mtxas Exam (eJOI20_exam) C++14
12 / 100
30 ms 1872 KB
#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mfsadfp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mii map<int, int>
#define all(a) a.begin(), a.end()
#define _fre() freopen("input.txt", "r", stdin)
#define turbo() cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define sz(x) ((int)x.size())
#define _for(a, b, c) for(int (a) = (b); (a) < (c); (a)++)
#define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
#define _forneq(a, b, c) for(int (a) = (b); (a) >= (c); (a)--)
#define _forn(a, b, c) for(int (a) = (b); (a) > (c); (a)--)
#define MyMax(a, b) if(a < (b)) a = (b);
using namespace std;
#define int ll
/***********************************************************************************
                                 STRUCTS
************************************************************************************/

/***********************************************************************************
                                VARIABLES
************************************************************************************/
const int maxn = 1e5+2;
int n;
int a[maxn], b[maxn];
/***********************************************************************************
                                FUNCTIONS
************************************************************************************/
int pass(int l, int r){
    int mx = 0;
    _foreq(i, l, r) mx = max(mx, a[i]);
    int ans = 0;
    _foreq(i, l, r) ans += (mx == b[i]);
    return ans;
}
bool subtask2(){
    bool yes = 1;
    _foreq(i, 2, n) yes &= (b[i] == b[i-1]);
    return yes;
}
bool subtask3(){
    _foreq(i, 2, n)
        if(a[i-1] >= a[i]) return false;
    return true;
}
int solve2(){
    int B = b[1]; a[n+1] = B+1;
    bool exists = 0;
    _foreq(i, 1, n) exists |= (a[i] == B);
    if(!exists){cout<<0; return 0;}
    int ans = 0;
    int start = 1; bool haveB = 0;
    _foreq(i, 1, n+1){
        if(a[i] > B) {
            if(haveB) ans += i-start;
            haveB = 0;
            start = i+1;
        }
        else if(a[i] == B) haveB = 1;
    }
    return ans;
}
int solve3(){
    vi best(n+1, 0);
    vector<vi> cnt(n+1, vi(n+1, 0)); vector<vi> dp(n+1, vi(n+1, 0));
    _foreq(i, 1, n)
        _foreq(j, 1, n)
            cnt[j][i] = cnt[j][i-1] + (b[i] == a[j]);

    _foreq(i, 1, n){
        _foreq(j, 1, n)
            dp[i][j] = best[j] + cnt[j][i];

        _foreq(j, 1, n){
            MyMax(best[j], best[j-1] + cnt[j-1][i] - cnt[j][i]);
            MyMax(best[j], dp[i][j-1] - cnt[j][i]);
        }
    }
//    _foreq(i, 1, n)
//        _foreq(j, 1, n){
//            int mx = 0;
//            _foreq(y, 1, j)
//                MyMax(mx, dp[i-1][y]);
//            dp[i][j] = mx + (b[i] == a[j]);
//        }
    return dp[n][n];
}
void readInput(){
    cin>>n; _foreq(i, 1,n) cin>>a[i]; _foreq(i, 1, n) cin>>b[i];
}
/***********************************************************************************
                                  MAIN
************************************************************************************/
signed main(){
   // _fre();
    turbo();
    readInput();
    if(subtask2()) cout<<solve2();
    else if(subtask3()) cout<<solve3();
}


Compilation message

exam.cpp: In function 'long long int pass(long long int, long long int)':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:39:5: note: in expansion of macro '_foreq'
   39 |     _foreq(i, l, r) mx = max(mx, a[i]);
      |     ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:41:5: note: in expansion of macro '_foreq'
   41 |     _foreq(i, l, r) ans += (mx == b[i]);
      |     ^~~~~~
exam.cpp: In function 'bool subtask2()':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:46:5: note: in expansion of macro '_foreq'
   46 |     _foreq(i, 2, n) yes &= (b[i] == b[i-1]);
      |     ^~~~~~
exam.cpp: In function 'bool subtask3()':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:50:5: note: in expansion of macro '_foreq'
   50 |     _foreq(i, 2, n)
      |     ^~~~~~
exam.cpp: In function 'long long int solve2()':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:57:5: note: in expansion of macro '_foreq'
   57 |     _foreq(i, 1, n) exists |= (a[i] == B);
      |     ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:61:5: note: in expansion of macro '_foreq'
   61 |     _foreq(i, 1, n+1){
      |     ^~~~~~
exam.cpp: In function 'long long int solve3()':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:74:5: note: in expansion of macro '_foreq'
   74 |     _foreq(i, 1, n)
      |     ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:75:9: note: in expansion of macro '_foreq'
   75 |         _foreq(j, 1, n)
      |         ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:78:5: note: in expansion of macro '_foreq'
   78 |     _foreq(i, 1, n){
      |     ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:79:9: note: in expansion of macro '_foreq'
   79 |         _foreq(j, 1, n)
      |         ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:82:9: note: in expansion of macro '_foreq'
   82 |         _foreq(j, 1, n){
      |         ^~~~~~
exam.cpp: In function 'void readInput()':
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:97:13: note: in expansion of macro '_foreq'
   97 |     cin>>n; _foreq(i, 1,n) cin>>a[i]; _foreq(i, 1, n) cin>>b[i];
      |             ^~~~~~
exam.cpp:18:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
exam.cpp:97:39: note: in expansion of macro '_foreq'
   97 |     cin>>n; _foreq(i, 1,n) cin>>a[i]; _foreq(i, 1, n) cin>>b[i];
      |                                       ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 5 ms 552 KB Output is correct
3 Correct 18 ms 1612 KB Output is correct
4 Correct 15 ms 1792 KB Output is correct
5 Correct 28 ms 1848 KB Output is correct
6 Correct 16 ms 1808 KB Output is correct
7 Correct 16 ms 1868 KB Output is correct
8 Correct 30 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -