Submission #772040

# Submission time Handle Problem Language Result Execution time Memory
772040 2023-07-03T14:40:23 Z birthdaycake Fruits (NOI22_fruits) C++17
0 / 100
1000 ms 39836 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 mx[400001];
int m,sz;
vector<int>x;
int solve(int array_plc, int prev){
    if(array_plc == m) return 0;
    if(dp[array_plc][prev] != -1) return dp[array_plc][prev];
    dp[array_plc][prev] = 0;
    if(a[array_plc] == -1){
        int j = upper_bound(x.begin(), x.end(), prev) - x.begin();
        for(int k = j; k < sz; k++) {
            int xx = solve(array_plc + 1, max(x[k],prev));
            if(x[k] > prev) xx += c[x[k]];
            dp[array_plc][prev] = max(dp[array_plc][prev], xx);
        }
        if(j == sz){
            dp[array_plc][prev] = max(dp[array_plc][prev],solve(array_plc + 1, prev));
        }
        return dp[array_plc][prev];
    }else{
        dp[array_plc][prev] = solve(array_plc + 1, max(prev, a[array_plc]));
        if(a[array_plc] > prev) dp[array_plc][prev] += c[a[array_plc]];
        return dp[array_plc][prev];
    }
}
signed main(){
    
    
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        if(i) b[i] = max(b[i], b[i - 1]);
    }
    for(int i = 1; i <= n; i++) cin >> c[i];
    set<int>d;
    for(int j = 1; j <= n; j++) d.insert(j);
    for(int j = 0; j < n; j++) d.erase(a[j]);
    for(auto s: d) x.push_back(s);
    sz = x.size();
    
    for(int i = 0; i < n; i++){
        for(int j = max(b[i],*x.begin()); j <= n; j++){
            if(a[i] == -1){
                if(d.count(j)) dp[i][j] = dp[i - 1][j - 1] + c[j];
                else dp[i][j] = dp[i - 1][j];
            }else{
                if(b[i] == 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]);
            dp[i][j] = max(dp[i - 1][j], dp[i][j]);
        }
        for(int j = 1; j < max(b[i],*x.begin()); j++){
            dp[i][j] = -1e18;
        }
    }
    int mx = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= n; j++) mx = max(mx, dp[i][j]);
        cout << mx << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Runtime error 3 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1436 KB Output is correct
2 Correct 197 ms 39836 KB Output is correct
3 Execution timed out 1077 ms 33196 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Runtime error 3 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Runtime error 3 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 33048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Runtime error 3 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -