답안 #931620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931620 2024-02-22T07:12:45 Z PieArmy Exam (eJOI20_exam) C++17
0 / 100
1000 ms 524288 KB
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n';
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}

void code(){
    int n;cin>>n;
    int A[n+1],B[n+1];
    for(int i=1;i<=n;i++)
        cin>>A[i];
    set<int>st;
    for(int i=1;i<=n;i++){
        cin>>B[i];
        st.insert(B[i]);
    }
    map<int,int>mp;
    int las=0;
    for(int x:st)
        mp[x]=las++;
    int pref[las+1][n+1];
    for(int i=0;i<=las;i++)
        pref[i][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=las;j++){
            pref[j][i]=pref[j][i-1];
        }
        pref[mp[B[i]]][i]++;
    }
    int dp[n+1];dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1];
        int mx=0;
        int cur;
        for(int j=i;j;j--){
            if(A[j]>mx){
                mx=A[j];
                if(st.find(mx)==st.end())
                    cur=las;
                else cur=mp[mx];
            }
            dp[i]=max(dp[i],dp[j-1]+pref[cur][i]-pref[cur][j-1]);
        }
    }
    cout<<dp[n]<<" ";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
    int t=1;
    if(!t)cin>>t;
    while(t--){code();cout<<endl;}
    return 0;
}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:57:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~
exam.cpp:57:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~
exam.cpp: In function 'void code()':
exam.cpp:49:63: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |             dp[i]=max(dp[i],dp[j-1]+pref[cur][i]-pref[cur][j-1]);
      |                                                  ~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 351 ms 1212 KB Output is correct
3 Execution timed out 1042 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 62332 KB Output is correct
2 Runtime error 300 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -