Submission #7590077


Source Code Expand

Copy
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;
typedef pair<pair<int,int>,pair<LL,LL>> pr;

const int maxn=20;

int n;
LL a[maxn];

map<pr,LL> f;
LL dfs(int l,int r,LL x,LL y)
{
	if (l+1>=r) return 0;
	pr now=make_pair(make_pair(l,r),make_pair(x,y));
	if (f.count(now)) return f[now];
	LL re=5e18;
	fo(i,l+1,r-1)
		re=min(re,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));
	return f[now]=re;
}

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%lld",&a[i]);
	
	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);
}

Submission Info

Submission Time
Task D - Add and Remove
User kqp
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 588 Byte
Status AC
Exec Time 250 ms
Memory 22656 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:27:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:28:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n) scanf("%lld",&a[i]);
                               ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 102
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 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, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, 75.txt, 76.txt, 77.txt, 78.txt, 79.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, 96.txt, 97.txt, 98.txt, 99.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 238 ms 20608 KB
02.txt AC 236 ms 20608 KB
03.txt AC 236 ms 21248 KB
04.txt AC 237 ms 20608 KB
05.txt AC 238 ms 20608 KB
06.txt AC 244 ms 20608 KB
07.txt AC 241 ms 20608 KB
08.txt AC 238 ms 20608 KB
09.txt AC 234 ms 20608 KB
10.txt AC 235 ms 20608 KB
11.txt AC 241 ms 20608 KB
12.txt AC 235 ms 20608 KB
13.txt AC 235 ms 20608 KB
14.txt AC 103 ms 10368 KB
15.txt AC 236 ms 20608 KB
16.txt AC 238 ms 20608 KB
17.txt AC 242 ms 20608 KB
18.txt AC 233 ms 20608 KB
19.txt AC 234 ms 20608 KB
20.txt AC 237 ms 20608 KB
21.txt AC 241 ms 20608 KB
22.txt AC 103 ms 10368 KB
23.txt AC 237 ms 20608 KB
24.txt AC 103 ms 10368 KB
25.txt AC 233 ms 20608 KB
26.txt AC 239 ms 20608 KB
27.txt AC 237 ms 20608 KB
28.txt AC 235 ms 20608 KB
29.txt AC 105 ms 10368 KB
30.txt AC 237 ms 20608 KB
31.txt AC 235 ms 20608 KB
32.txt AC 236 ms 20608 KB
33.txt AC 234 ms 20608 KB
34.txt AC 104 ms 10368 KB
35.txt AC 240 ms 20608 KB
36.txt AC 242 ms 20608 KB
37.txt AC 239 ms 20608 KB
38.txt AC 244 ms 20608 KB
39.txt AC 241 ms 20608 KB
40.txt AC 250 ms 20608 KB
41.txt AC 241 ms 20608 KB
42.txt AC 238 ms 20608 KB
43.txt AC 238 ms 20608 KB
44.txt AC 245 ms 20608 KB
45.txt AC 236 ms 20608 KB
46.txt AC 234 ms 20608 KB
47.txt AC 222 ms 20608 KB
48.txt AC 241 ms 20608 KB
49.txt AC 106 ms 10368 KB
50.txt AC 247 ms 20608 KB
51.txt AC 239 ms 20608 KB
52.txt AC 103 ms 10368 KB
53.txt AC 238 ms 20608 KB
54.txt AC 104 ms 10368 KB
55.txt AC 236 ms 20608 KB
56.txt AC 240 ms 20608 KB
57.txt AC 236 ms 20608 KB
58.txt AC 238 ms 20608 KB
59.txt AC 236 ms 20608 KB
60.txt AC 234 ms 20608 KB
61.txt AC 236 ms 20608 KB
62.txt AC 237 ms 20608 KB
63.txt AC 233 ms 20608 KB
64.txt AC 238 ms 20608 KB
65.txt AC 107 ms 10368 KB
66.txt AC 248 ms 20608 KB
67.txt AC 236 ms 20608 KB
68.txt AC 237 ms 20608 KB
69.txt AC 239 ms 20608 KB
70.txt AC 237 ms 20608 KB
71.txt AC 235 ms 20608 KB
72.txt AC 238 ms 20608 KB
73.txt AC 246 ms 20608 KB
74.txt AC 239 ms 20608 KB
75.txt AC 240 ms 20608 KB
76.txt AC 241 ms 22656 KB
77.txt AC 236 ms 20608 KB
78.txt AC 237 ms 20608 KB
79.txt AC 235 ms 20608 KB
80.txt AC 236 ms 20608 KB
81.txt AC 237 ms 20608 KB
82.txt AC 239 ms 20608 KB
83.txt AC 239 ms 20608 KB
84.txt AC 235 ms 20608 KB
85.txt AC 236 ms 20608 KB
86.txt AC 103 ms 10368 KB
87.txt AC 234 ms 20608 KB
88.txt AC 234 ms 20608 KB
89.txt AC 236 ms 20608 KB
90.txt AC 234 ms 20608 KB
91.txt AC 239 ms 20608 KB
92.txt AC 238 ms 20608 KB
93.txt AC 1 ms 256 KB
94.txt AC 1 ms 256 KB
95.txt AC 1 ms 256 KB
96.txt AC 1 ms 256 KB
97.txt AC 1 ms 256 KB
98.txt AC 1 ms 256 KB
99.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB