Submission #4218697


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int l;
int a[200005];
int cost[200005][5];
int dp[200005][5];

signed main(){
	scanf("%ld", &l);
	for(int i = 1; i <= l; i++){
		scanf("%ld", &a[i]);
		cost[i][0] = cost[i][4] = a[i];
		cost[i][1] = cost[i][3] = (a[i] == 0) ? 2 : (a[i] % 2);
		cost[i][2] = (a[i]+1) % 2;
	}
	for(int i = 1; i <= l; i++){
		for(int j = 0; j < 5; j++){
			dp[i][j] = LINF;
			for(int k = 0; k <= j; k++){
				dp[i][j] = std::min(dp[i][j], dp[i-1][k] + cost[i][j]);
			}
		}
	}
	int ans = LINF;
	for(int i = 0; i < 5; i++){
		ans = std::min(ans, dp[l][i]);
	}
	printf("%ld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Ears
User Hewla
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1036 Byte
Status
Exec Time 34 ms
Memory 17408 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:31:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%ld", &l);
                  ^
./Main.cpp:33:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%ld", &a[i]);
                      ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 600 / 600 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 32 ms 17408 KB
02.txt 33 ms 17408 KB
03.txt 33 ms 17408 KB
04.txt 33 ms 17408 KB
05.txt 25 ms 17408 KB
06.txt 25 ms 17408 KB
07.txt 25 ms 17408 KB
08.txt 26 ms 17408 KB
09.txt 26 ms 17408 KB
10.txt 25 ms 17408 KB
11.txt 25 ms 17408 KB
12.txt 26 ms 17408 KB
13.txt 26 ms 17408 KB
14.txt 26 ms 17408 KB
15.txt 26 ms 17408 KB
16.txt 26 ms 17408 KB
17.txt 25 ms 17408 KB
18.txt 25 ms 17408 KB
19.txt 25 ms 17408 KB
20.txt 24 ms 17408 KB
21.txt 25 ms 17408 KB
22.txt 24 ms 17408 KB
23.txt 25 ms 17408 KB
24.txt 25 ms 17408 KB
25.txt 25 ms 17408 KB
26.txt 34 ms 17408 KB
27.txt 25 ms 17408 KB
28.txt 25 ms 17408 KB
29.txt 27 ms 17408 KB
30.txt 28 ms 17408 KB
31.txt 26 ms 17408 KB
32.txt 28 ms 17408 KB
33.txt 25 ms 17408 KB
34.txt 25 ms 17408 KB
35.txt 25 ms 17408 KB
36.txt 25 ms 17408 KB
37.txt 2 ms 4352 KB
38.txt 2 ms 4352 KB
39.txt 2 ms 4352 KB
40.txt 2 ms 4352 KB
41.txt 2 ms 4352 KB
42.txt 2 ms 4352 KB
s1.txt 2 ms 4352 KB
s2.txt 2 ms 4352 KB
s3.txt 2 ms 4352 KB