답안 #772084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772084 2023-07-03T15:32:01 Z birthdaycake Fruits (NOI22_fruits) C++17
0 / 100
1000 ms 267708 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
#define mod 1000000007
using namespace std;
 
 
int a[400001],c[400001],b[40001];
int dp[4001][4001];
int boo[400001];
int m,sz;
vector<int>x;
signed main(){
    
    
    int n; cin >> n;
    b[0] = -1;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
        b[i] = max(b[i], b[i - 1]);
        if(a[i] > 0) boo[a[i]] = 1;
    }
    for(int i = 1; i <= n; i++) cin >> c[i];
    int mn = n + 1;
    for(int j = 1; j <= n; j++){
        if(!boo[j]) {
            mn = j;
            break;
        }
    }
    

    for(int i = 1; i <= n; i++){
        int xx = b[i];
        if(a[i] == -1) xx = mn;
        for(int j = 0; j < xx; j++) dp[i][j] = -1e18;
        for(int j = xx; j <= n; j++){
            if(a[i] == -1){
                if(!boo[j]) dp[i][j] = dp[i - 1][j - 1] + c[j];
                else dp[i][j] = dp[i - 1][j];
            }else{
                if(j == a[i]) dp[i][a[i]] = dp[i - 1][a[i] - 1] + c[a[i]];
                else dp[i][j] = dp[i - 1][j];
            }
            dp[i][j] = max(dp[i][j - 1], dp[i][j]);
            if(i != 0) dp[i][j] = max(dp[i - 1][j], dp[i][j]);
        }
        
    }
    int mx = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) mx = max(mx, dp[i][j]);
        cout << mx << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 28 ms 39752 KB Output is correct
3 Runtime error 315 ms 267708 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 31708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -