Submission #63597752
Source Code Expand
#include "bits/stdc++.h"
#include <chrono>
using namespace std;
#define LL long long
#define mod 998244353ll
//#define mod 1000000007ll
#define PI acos(-1.0)
#define set0(ar) memset(ar, 0, sizeof ar)
#define setinf(ar) memset(ar, 126, sizeof ar)
inline LL bigmod(LL p, LL e, LL M) {
LL r = 1;
for (; e > 0; e >>= 1, p = (p * p) % M)
if (e & 1) r = (r * p) % M;
return r;
}
inline LL modinverse(LL a, LL M) { return bigmod(a, M - 2, M); }
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
LL ar[200001];
void solve() {
int n; cin >> n;
for(int i = 1; i <= n; i++) cin >> ar[i];
if(n == 1) {
cout << ar[1] << endl;
return;
}
LL sum[2];
sum[n%2] = ar[n];
sum[(n-1)%2] = 0;
for(int i = n-1; i >= 1; i--) {
sum[i%2] = max(sum[i%2], ar[i] + sum[1-(i%2)]);
}
cout << sum[1] << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
for (int ts = 1; ts <= T; ts++) {
//cout << "Case " << ts << ": ";
solve();
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Operations on a Stack |
| User | nfssdq |
| Language | C++ 23 (gcc 12.2) |
| Score | 400 |
| Code Size | 1073 Byte |
| Status | AC |
| Exec Time | 14 ms |
| Memory | 5164 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 1 ms | 3516 KiB |
| 001.txt | AC | 1 ms | 3372 KiB |
| 002.txt | AC | 12 ms | 4968 KiB |
| 003.txt | AC | 12 ms | 5028 KiB |
| 004.txt | AC | 12 ms | 5028 KiB |
| 005.txt | AC | 13 ms | 4980 KiB |
| 006.txt | AC | 13 ms | 4948 KiB |
| 007.txt | AC | 1 ms | 3440 KiB |
| 008.txt | AC | 1 ms | 3468 KiB |
| 009.txt | AC | 1 ms | 3388 KiB |
| 010.txt | AC | 7 ms | 4220 KiB |
| 011.txt | AC | 3 ms | 3592 KiB |
| 012.txt | AC | 6 ms | 4128 KiB |
| 013.txt | AC | 8 ms | 4304 KiB |
| 014.txt | AC | 9 ms | 4344 KiB |
| 015.txt | AC | 13 ms | 4976 KiB |
| 016.txt | AC | 13 ms | 5028 KiB |
| 017.txt | AC | 13 ms | 5040 KiB |
| 018.txt | AC | 13 ms | 5164 KiB |
| 019.txt | AC | 13 ms | 4980 KiB |
| 020.txt | AC | 13 ms | 4976 KiB |
| 021.txt | AC | 14 ms | 4960 KiB |
| 022.txt | AC | 13 ms | 5028 KiB |
| 023.txt | AC | 13 ms | 5028 KiB |
| 024.txt | AC | 13 ms | 5088 KiB |
| example0.txt | AC | 1 ms | 3392 KiB |
| example1.txt | AC | 1 ms | 3408 KiB |
| example2.txt | AC | 1 ms | 3456 KiB |