/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 103ms 660.0 KiB
#3 Accepted 107ms 644.0 KiB
#4 Accepted 111ms 1.312 MiB
#5 Accepted 122ms 8.258 MiB
#6 Accepted 182ms 77.723 MiB
#7 Accepted 180ms 77.723 MiB
#8 Accepted 183ms 77.727 MiB
#9 Accepted 184ms 77.723 MiB
#10 Accepted 184ms 77.727 MiB
#11 Accepted 184ms 77.73 MiB
#12 Accepted 181ms 77.73 MiB
#13 Accepted 180ms 77.727 MiB
#14 Accepted 175ms 77.723 MiB
#15 Accepted 171ms 77.727 MiB
#16 Accepted 173ms 77.609 MiB
#17 Accepted 55ms 24.387 MiB
#18 Accepted 26ms 3.57 MiB
#19 Accepted 35ms 4.234 MiB
#20 Accepted 179ms 77.727 MiB

Code

#ifndef COMMON_H
#define COMMON_H 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <random>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define szx(x) (int)(x).size()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
constexpr int LOG2(int x)
{
    return 32 - __builtin_clz(x) - 1;
}
#endif // COMMON_H
#ifndef DEBUG_H
#define DEBUG_H 1
#ifndef CLown1331
#define debug(...) 0
#define ASSERT(...) 0
#define dbg(...) 0
#endif
#endif // DEBUG_H
#ifndef solution_h
#define solution_h 1
namespace solution
{
const int sz = 2e5 + 105;
const int mod = 1e9 + 7;
const ll INF = 1e16;
int t, n;
ll ar[sz];
ll dp[sz][5][5];
int vis[sz][5][5];
int vs = 0;
ll rec(int x, int a, int b)
{
    if (x == n)
    {
        return 0;
    }
    ll &ret = dp[x][a][b];
    if (vis[x][a][b] == vs)
    {
        return ret;
    }
    ret = INF;
    vis[x][a][b] = vs;
    for (int i = 0; i < 5; i++)
    {
        if (i == a || i == b)
        {
            continue;
        }
        ret = min(ret, rec(x + 1, b, i) + ar[x] * i);
    }
    return ret;
}
void solve_case()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &ar[i]);
    }
    ll ans = INF;
    vs++;
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (i == j)
            {
                continue;
            }
            ans = min(ans, rec(2, i, j) + ar[0] * i + ar[1] * j);
        }
    }
    printf("%lld\n", ans);
}
void solve()
{
    vs = 0;
    scanf("%d", &t);
    while (t--)
    {
        solve_case();
    }
}
} // namespace solution
#endif // solution_h
#define _CRT_SECURE_NO_WARNINGS
int main()
{
    solution::solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-22 14:15:44
Judged At
2024-11-11 03:06:05
Judged By
Score
100
Total Time
184ms
Peak Memory
77.73 MiB