Submission #63596962


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const int mod = 998244353;
const LL LINF = 1e18;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}

int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}

int mult(int a, int b)
{
	return (LL)a * b % mod;
}

int binpow(int a, LL n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	int n;
	cin >> n;
	VI a(n);
	for (int& ai : a)
		cin >> ai;
	vector<LL> dp(n + 1, -LINF);
	dp[0] = 0;
	FOR(i, 1, n + 1)
	{
		dp[i] = dp[i - 1] + a[i - 1];
		if (i > 1)
		{
			dp[i] = max(dp[i], dp[i - 2]);
		}
	}
	cout << dp[n] << "\n";
	return 0;
}

Submission Info

Submission Time
Task A - Operations on a Stack
User mshcherba
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1193 Byte
Status AC
Exec Time 14 ms
Memory 5520 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
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 3448 KiB
001.txt AC 1 ms 3396 KiB
002.txt AC 13 ms 5368 KiB
003.txt AC 13 ms 5392 KiB
004.txt AC 13 ms 5372 KiB
005.txt AC 13 ms 5376 KiB
006.txt AC 13 ms 5372 KiB
007.txt AC 1 ms 3416 KiB
008.txt AC 1 ms 3472 KiB
009.txt AC 1 ms 3412 KiB
010.txt AC 8 ms 4320 KiB
011.txt AC 3 ms 3524 KiB
012.txt AC 6 ms 4080 KiB
013.txt AC 8 ms 4304 KiB
014.txt AC 9 ms 4356 KiB
015.txt AC 13 ms 5508 KiB
016.txt AC 14 ms 5424 KiB
017.txt AC 13 ms 5400 KiB
018.txt AC 13 ms 5372 KiB
019.txt AC 14 ms 5428 KiB
020.txt AC 14 ms 5360 KiB
021.txt AC 14 ms 5376 KiB
022.txt AC 14 ms 5520 KiB
023.txt AC 14 ms 5420 KiB
024.txt AC 14 ms 5452 KiB
example0.txt AC 1 ms 3596 KiB
example1.txt AC 1 ms 3532 KiB
example2.txt AC 1 ms 3412 KiB