Submission #19712502


Source Code Expand

Copy
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

const int N = 505;

bool ok[N][4];
int f[N][4];
int val[N];

int main() {
	int n;
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(val[i]);
	}
	ok[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		//1
		if (ok[i - 1][0]) {
			ok[i][1] = 1;
			f[i][1] = f[i - 1][0] + val[i];
		}
		if (ok[i - 1][3]) {
			if (ok[i][1]) f[i][1] = max(f[i][1], f[i - 1][3] + val[i]);
			else f[i][1] = f[i - 1][3] + val[i], ok[i][1] = 1;
		}
		//2
		if (ok[i - 1][1]) {
			ok[i][2] = 1;
			f[i][2] = f[i - 1][1] + val[i];
		}
		if (i - 4 >= 1) {
			if (ok[i - 4][1]) {
				if (ok[i][2]) f[i][2] = max(f[i][2], f[i - 4][1] + val[i]);
				else f[i][2] = f[i - 4][1] + val[i], ok[i][2] = 1;
			}
		}
		//3
		if (ok[i - 1][2]) {
			ok[i][3] = 1;
			f[i][3] = f[i - 1][2] + val[i];
		}
		if (i - 4 >= 1) {
			if (ok[i - 4][2]) {
				if (ok[i][3]) f[i][3] = max(f[i][3], f[i - 4][2] + val[i]);
				else f[i][3] = f[i - 4][2] + val[i], ok[i][3] = 1;
			}
		}
		//0
		ok[i][0] = 1;
		if (ok[i - 1][3]) f[i][0] = max(f[i][0], f[i - 1][3]);
		if (i - 4 >= 0) {
			f[i][0] =max(f[i][0], f[i - 4][0]);
		}
	}
	printf("%d\n", max(f[n][0], f[n][3]));
    return 0;
}

Submission Info

Submission Time
Task B - Three Coins
User jiaangk
Language C++ (GCC 9.2.1)
Score 0
Code Size 1579 Byte
Status WA
Exec Time 9 ms
Memory 3732 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 5
WA × 44
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, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt WA 9 ms 3572 KB
001.txt WA 2 ms 3720 KB
002.txt WA 2 ms 3568 KB
003.txt WA 1 ms 3660 KB
004.txt WA 2 ms 3460 KB
005.txt WA 6 ms 3728 KB
006.txt WA 2 ms 3612 KB
007.txt WA 2 ms 3560 KB
008.txt WA 2 ms 3612 KB
009.txt WA 3 ms 3728 KB
010.txt WA 2 ms 3624 KB
011.txt WA 3 ms 3652 KB
012.txt WA 3 ms 3616 KB
013.txt WA 2 ms 3456 KB
014.txt WA 2 ms 3728 KB
015.txt WA 5 ms 3564 KB
016.txt WA 2 ms 3564 KB
017.txt WA 2 ms 3640 KB
018.txt WA 2 ms 3460 KB
019.txt WA 2 ms 3732 KB
020.txt WA 2 ms 3664 KB
021.txt WA 3 ms 3664 KB
022.txt WA 3 ms 3724 KB
023.txt WA 2 ms 3728 KB
024.txt WA 5 ms 3560 KB
025.txt WA 2 ms 3648 KB
026.txt WA 3 ms 3720 KB
027.txt WA 2 ms 3728 KB
028.txt WA 2 ms 3648 KB
029.txt WA 2 ms 3724 KB
030.txt WA 3 ms 3536 KB
031.txt WA 2 ms 3648 KB
032.txt WA 2 ms 3516 KB
033.txt WA 2 ms 3460 KB
034.txt WA 2 ms 3640 KB
035.txt AC 1 ms 3664 KB
036.txt WA 2 ms 3652 KB
037.txt WA 1 ms 3732 KB
038.txt WA 3 ms 3720 KB
039.txt WA 2 ms 3636 KB
040.txt WA 2 ms 3668 KB
041.txt WA 2 ms 3648 KB
042.txt WA 2 ms 3516 KB
043.txt WA 2 ms 3724 KB
044.txt WA 2 ms 3532 KB
045.txt AC 2 ms 3460 KB
example0.txt AC 3 ms 3656 KB
example1.txt AC 2 ms 3556 KB
example2.txt AC 2 ms 3660 KB