QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#816137 | #3032. Cheese Game | DeadlyCritic# | AC ✓ | 97ms | 6440kb | C++17 | 3.7kb | 2024-12-15 23:20:13 | 2024-12-15 23:20:13 |
Judging History
answer
// template.cpp
// add use inp.txt for file input
/*
Pragma:
If ever in doubt about whether your pragmas are correct,
turn on most compiler warnings with the command-line option -Wall(or the more specific -Wunknown-pragmas).
use assert(__builtin_cpu_supports("avx2")) to check if intruction set is available
*/
// #pragma GCC optimize("O3","unroll-loops")
// #pragma GCC optimize ("Ofast")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
// #pragma GCC target("sse4") // instead of avx2
// __attribute__((target("avx2"), optimize("O3", "unroll-loops")))
#include <bits/stdc++.h>
#define oo (1000'000'000'000'000'000LL)
#define cif(i, n) for(int i = 0; i < n; i++)
#define ccif(i, l, r) for(int i = l; i < r; i++)
#define rif(i, n) for(int i = n-1; i >= 0; i--)
#define scan(a, __n) {for(int __ = 0; __ < __n; __++)cin >> a[__];}
#define print(a, __n) {for(int __ = 0; __ < __n; __++)cout << a[__] << ' '; cout << '\n';}
#define sz(s) ((int)s.size())
#define dbg(x) cerr << #x << " : " << x << endl;
// #define mset(a, chr) memset(a, chr, sizeof a)
#define mset(a) memset(a, 0, sizeof a)
// #define int ll
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define uni(v) sort(all(v)), v.resize(unique(all(v))-v.begin());
// #define c0 (v<<1)
// #define c1 (c0|1)
// #define md ((l+r)/2)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ld> vd;
typedef pair<ld, ld> pt;
typedef vector<pt> vpt;
const int mod = 1e9+7;
// const string fileName = "";
// const int maxFac = 1e6+7;
// ll fac[maxFac], _fac[maxFac];
// ll po(ll b, ll p){
// b %= mod;
// p %= mod-1;
// ll r = 1;
// while(p){
// if(p&1)r = r*b%mod;
// p >>= 1;
// b = b*b%mod;
// }
// return r;
// }
// ll choose(ll k, ll n){
// return fac[n]*_fac[k]%mod*_fac[n-k]%mod;
// }
// ll factorial(ll n, ll k){
// ll ret = 1;
// for(ll i = n; i >= n-k+1; i--){
// ret = ret*i%mod;
// }
// return ret;
// }
const int maxN = 1e6+7;
void slv(){
int n;
cin >> n;
int a[n];
scan(a, n);
if(n == 1){
cout << a[0] << '\n';
return;
}
if(n == 2){
cout << max(a[0], a[1]) << '\n';
return;
}
ll dp[n+1][3];
mset(dp);
cif(i, n){
dp[i+1][2] = 0;
if(i > 0)dp[i+1][2] = max(dp[i+1][2], dp[i-1][0]+min(a[i], a[i-1]));
dp[i+1][1] = dp[i][0];
dp[i+1][0] = a[i]+max(dp[i][1], dp[i][2]);
}
cout << max({dp[n][0], dp[n][1], dp[n][2]}) << '\n';
}
void prep(){
// fac[0] = 1;
// for(int i = 1; i < maxFac; i++)fac[i] = fac[i-1]*i%mod;
// _fac[maxFac-1] = po(fac[maxFac-1], mod-2);
// for(int i = maxFac-2; i >= 0; i--)_fac[i] = _fac[i+1]*(i+1)%mod;
// w[0] = 1;
// for(int i = 1; i < maxN; i++)w[i] = w[i-1]*p%mod;
// _w[maxN-1] = po(w[maxN-1], mod-2);
// for(int i = maxN-2; i >= 0; i--)_w[i] = _w[i+1]*p%mod;
}
signed main(){
// if(fileName.size() > 0){
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// }
fastIO;
// cout << fixed << setprecision (15);
prep();
int t = 1;
cin >> t;
while(t--){
// cout << slv() << '\n';
slv();
// string s;
// cin >> s;
// bool x = slv();
// cout << (x?"YES":"NO") << '\n';
}
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
20 2 2 1 1 1000000 4 3 2 4 3 8 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 8 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 9 723059 133070 898168 961394 18457 175012 478043 176230 377374 8 289384 930887 692778 636916 747794 238336 885387 760493 8 516650 641422 202363 ...
output:
2 1000000 8 5000000 5000000 2691397 3314426 2475496 4999998 10 3 1 2 8 4000001 15 3213803 24 3000002 4
result:
ok 20 lines
Test #2:
score: 0
Accepted
time: 97ms
memory: 6440kb
input:
20 100000 859485 390674 819590 695284 505824 962572 577989 53378 307332 754253 103728 302519 19948 48169 659522 389802 262161 848413 224854 965949 70782 789156 772974 876205 410327 900390 392837 362222 582187 762071 74734 958024 152744 410676 169659 174919 373247 264000 744649 196931 18252 848376 15...
output:
33024883937 33135467117 66667000000 33237375393 58332975002 33104918259 33172888838 33156623430 33090460100 33042109608 32999667097 33111199056 3333366667 32982135568 33144273501 56831006063 33108905993 33124668910 33126313979 33069028435
result:
ok 20 lines