Submission #983523

# Submission time Handle Problem Language Result Execution time Memory
983523 2024-05-15T15:31:35 Z Whisper Visiting Singapore (NOI20_visitingsingapore) C++17
4 / 100
163 ms 215020 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//#define int long long
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define Ford(i, a, b) for (int i = (b); i >= (a); i --)
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define Repd(i, n) for (int i = (n) - 1; i >= 0; --i)

#define overload(_1, _2, _3, NAME, ...) NAME
#define FOR(...) overload(__VA_ARGS__, For, Rep)(__VA_ARGS__)
#define FORD(...) overload(__VA_ARGS__, Ford, Repd)(__VA_ARGS__)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int numEvent, nArr, mArr, a, b;
#define MAXN    1005
#define MAX     3001

int value[MAXN], order[MAX], event[MAX];

int dp[MAX][MAX][3];
//maximum happiness till i if we joined j event in order and
//current state of event i is (0, 1, 2) and if we have attended more than one event before (0, 1)
#define SKIP    0
#define ATTEND  1
#define NOT     2

void Whisper(){
    cin >> numEvent >> nArr >> mArr >> a >> b;
    for (int i = 1; i <= numEvent; ++i) cin >> value[i];
    for (int i = 0; i < nArr; ++i) cin >> event[i];
    for (int i = 0; i < mArr; ++i) cin >> order[i];

    /*
        operator 1: attend event[i] and your happiness is increased by value[event[i]]
        operator 2: skip events order[i], order[i + 1], .. order[j] your happiness is reduced by A + (j - i + 1) * B
        operator 3: you don't attend event for d consecutive days, your hapiness is reduced by A + d * B
    */
    memset(dp, -0x3f, sizeof dp);
    dp[0][0][0] = dp[0][0][1] = dp[0][0][2] = 0;

    FOR(i, nArr){
        dp[i][0][0] = dp[i][0][1] = dp[i][0][2] = 0;
        FOR(j, mArr) FOR(s, 3){
            maximize(dp[i][j + 1][SKIP], dp[i][j][s] + b + a * (SKIP != s || !j));
            maximize(dp[i + 1][j][NOT], dp[i][j][s] + b + a * (NOT != s || !j));
            if (order[j] == event[i]){
                maximize(dp[i + 1][j + 1][ATTEND], dp[i][j][s] + value[order[j]]);
            }
        }
    }
    int ans = -LINF;
    FOR(i, 1, nArr) FOR(s, 3){
        maximize(ans, dp[i][mArr][s]);
    }
    cout << ans;
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


Compilation message

VisitingSingapore.cpp: In function 'void Whisper()':
VisitingSingapore.cpp:85:15: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1152921504606846976' to '0' [-Woverflow]
   85 |     int ans = -LINF;
      |               ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 106076 KB Output is correct
2 Correct 20 ms 106072 KB Output is correct
3 Correct 13 ms 106076 KB Output is correct
4 Correct 13 ms 106024 KB Output is correct
5 Correct 14 ms 106048 KB Output is correct
6 Correct 15 ms 106000 KB Output is correct
7 Correct 13 ms 106076 KB Output is correct
8 Correct 13 ms 106052 KB Output is correct
9 Correct 17 ms 106072 KB Output is correct
10 Correct 23 ms 106204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 106072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 106072 KB Output is correct
2 Correct 21 ms 106076 KB Output is correct
3 Runtime error 163 ms 215020 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 106072 KB Output is correct
2 Correct 21 ms 106076 KB Output is correct
3 Runtime error 163 ms 215020 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 106072 KB Output is correct
2 Correct 21 ms 106076 KB Output is correct
3 Runtime error 163 ms 215020 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 106072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 106076 KB Output is correct
2 Correct 20 ms 106072 KB Output is correct
3 Correct 13 ms 106076 KB Output is correct
4 Correct 13 ms 106024 KB Output is correct
5 Correct 14 ms 106048 KB Output is correct
6 Correct 15 ms 106000 KB Output is correct
7 Correct 13 ms 106076 KB Output is correct
8 Correct 13 ms 106052 KB Output is correct
9 Correct 17 ms 106072 KB Output is correct
10 Correct 23 ms 106204 KB Output is correct
11 Incorrect 14 ms 106072 KB Output isn't correct
12 Halted 0 ms 0 KB -