답안 #983524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
983524 2024-05-15T15:32:20 Z Whisper Visiting Singapore (NOI20_visitingsingapore) C++17
4 / 100
19 ms 24664 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     1005

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;
      |               ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12124 KB Output is correct
2 Correct 9 ms 12332 KB Output is correct
3 Correct 2 ms 12124 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12172 KB Output is correct
9 Correct 6 ms 12124 KB Output is correct
10 Correct 10 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 19 ms 24664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 19 ms 24664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 19 ms 24664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12124 KB Output is correct
2 Correct 9 ms 12332 KB Output is correct
3 Correct 2 ms 12124 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12172 KB Output is correct
9 Correct 6 ms 12124 KB Output is correct
10 Correct 10 ms 12124 KB Output is correct
11 Incorrect 2 ms 12120 KB Output isn't correct
12 Halted 0 ms 0 KB -