Submission #772821

# Submission time Handle Problem Language Result Execution time Memory
772821 2023-07-04T11:38:00 Z birthdaycake Fruits (NOI22_fruits) C++17
30 / 100
772 ms 278428 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] = max(a[i], b[i - 1]);
        if(a[i] > -1) boo[a[i]] = 1;
    }
    for(int i = 1; i <= n; i++) cin >> c[i];
    int mn = n + 1;
    vector<int>x;
    for(int j = 1; j <= n; j++){
        if(!boo[j]) {
            x.push_back(j);
        }
    }
    int k = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == -1) b[i] = max(b[i], x[k++]);
        b[i] = max(b[i - 1], b[i]);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i][j] = -1e9;
    }
    // dp[i][j] = max score for the first i elements such that j is the max element...
    //
    for(int i = 1; i <= n; i++){
        int xx = b[i];
        for(int j = xx; j <= n; j++){
            if(a[i] == -1){
                if(!boo[j]) dp[i][j] = max(dp[i - 1][j - 1] + c[j],dp[i][j]);
            }else{
                if(j == a[i]) dp[i][j] = max(dp[i - 1][j - 1] + c[j],dp[i][j]);
                else dp[i][j] = max(dp[i - 1][j], dp[i][j]);

            }
            dp[i][j] = max(dp[i - 1][j], dp[i][j]);
            dp[i][j] = max(dp[i][j - 1], dp[i][j]);
        }
        /*for(int j = 1; j <= n; j++){
            cout << dp[i][j] << ' ';
        }
        cout << endl;*/
        
    }
    int mx = 0;
    for(int i = 1; i <= n; i++){
        mx = max(mx,dp[i][n]);
        cout << mx << ' ';
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:107:9: warning: unused variable 'mn' [-Wunused-variable]
  107 |     int mn = n + 1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 20 ms 39764 KB Output is correct
3 Runtime error 215 ms 268472 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 22 ms 39688 KB Output is correct
29 Correct 22 ms 39792 KB Output is correct
30 Correct 18 ms 39804 KB Output is correct
31 Correct 6 ms 12208 KB Output is correct
32 Correct 7 ms 12244 KB Output is correct
33 Correct 16 ms 24004 KB Output is correct
34 Correct 17 ms 29792 KB Output is correct
35 Correct 13 ms 24032 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 17 ms 31424 KB Output is correct
39 Correct 16 ms 26836 KB Output is correct
40 Correct 19 ms 33032 KB Output is correct
41 Correct 20 ms 34676 KB Output is correct
42 Correct 20 ms 35496 KB Output is correct
43 Correct 20 ms 35752 KB Output is correct
44 Correct 20 ms 35996 KB Output is correct
45 Correct 23 ms 39744 KB Output is correct
46 Correct 23 ms 39736 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 772 ms 278428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 20 ms 39764 KB Output is correct
13 Runtime error 215 ms 268472 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -