Submission #983519

#TimeUsernameProblemLanguageResultExecution timeMemory
983519WhisperVisiting Singapore (NOI20_visitingsingapore)C++17
0 / 100
87 ms262144 KiB
#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 5005 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'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...