#include <bits/stdc++.h>
#include <math.h>
#include <chrono>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10) //cin.tie(0); cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define what(x) cerr << #x << " is " << x << endl;
#define int long long
const int MAXN = 2e3 + 10;
const int MAXK = 44; //UWAGA
unsigned int E[MAXN][MAXN];
int n, a, b;
int tab[MAXN];
pii dist[MAXN];
int shortest[MAXN];
bitset<MAXN> wszystkie[MAXN];
void mini(pii A, pii &B)
{
B.st = min(B.st, A.st + 1);
B.nd = max(B.nd, A.nd + 1);
}
bool solveHeura(int q) //czy wynik zawiera sie na inkluzje w q
{
fill(dist, dist + MAXN, mp(100000, -100000));
dist[0] = {0, 0};
rep(i, n) for (int k = i + 1; k <= n; k++)
{
if ((E[i][k] | q) == q)
mini(dist[i], dist[k]);
}
//bitset<64> D(q);
//cerr << D << " " << dist[n].st << " " << dist[n].nd << endl;
return (dist[n].st <= b && dist[n].nd >= a);
}
bool solveShortest(int q)
{
fill(shortest, shortest + MAXN, 1e9);
shortest[0] = 0;
rep(i, n) for (int k = i + 1; k <= n; k++)
{
if ((E[i][k] | q) == q)
shortest[k] = min(shortest[k], shortest[i] + 1);
}
//cerr << shortest[n] << endl;
return shortest[n] <= b;
}
bool solveBitset(int q)
{
rep(i, MAXN) wszystkie[i].reset();
wszystkie[0][0] = true;
rep(i, n) for (int k = i + 1; k <= n; k++)
{
if ((E[i][k] | q) == q)
wszystkie[k] = (wszystkie[k] | (wszystkie[i] << 1));
}
for (int i = a; i <= b; i++)
if (wszystkie[n][i])
return true;
return false;
}
void Heura(int &wynik)
{
for (int k = MAXK; k >= 0; k--)
if (!solveHeura(wynik + (1ll << k) - 1))
wynik += (1ll << k);
}
void wzorShortest(int &wynik)
{
for (int k = MAXK; k >= 0; k--)
if (!solveShortest(wynik + (1ll << k) - 1))
wynik += (1ll << k);
}
void wzorBitset(int &wynik)
{
for (int k = MAXK; k >= 0; k--)
if (!solveBitset(wynik + (1ll << k) - 1))
wynik += (1ll << k);
}
void pre()
{
cin >> n >> a >> b;
rep(i, n) cin >> tab[i];
rep(i, n)
{
int val = tab[i];
for (int k = i + 1; k <= n; k++)
{
E[i][k] = val;
val += tab[k];
}
}
}
main()
{
_upgrade;
pre();
int wynik = 0;
//Huera(wynik);
//wzorShortest(wynik);
wzorBitset(wynik);
cout << wynik << endl;
}
Compilation message
sculpture.cpp: In function 'bool solveHeura(long long int)':
sculpture.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ((E[i][k] | q) == q)
~~~~~~~~~~~~~~^~~~
sculpture.cpp: In function 'bool solveShortest(long long int)':
sculpture.cpp:58:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ((E[i][k] | q) == q)
~~~~~~~~~~~~~~^~~~
sculpture.cpp: In function 'bool solveBitset(long long int)':
sculpture.cpp:71:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ((E[i][k] | q) == q)
~~~~~~~~~~~~~~^~~~
sculpture.cpp: At global scope:
sculpture.cpp:117:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
888 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
4 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
888 KB |
Output is correct |
5 |
Correct |
5 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
912 KB |
Output is correct |
11 |
Correct |
5 ms |
1016 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
4 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
4 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
940 KB |
Output is correct |
19 |
Correct |
5 ms |
888 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
888 KB |
Output is correct |
22 |
Correct |
5 ms |
888 KB |
Output is correct |
23 |
Correct |
5 ms |
888 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
5 ms |
888 KB |
Output is correct |
26 |
Correct |
5 ms |
888 KB |
Output is correct |
27 |
Correct |
4 ms |
888 KB |
Output is correct |
28 |
Correct |
5 ms |
888 KB |
Output is correct |
29 |
Correct |
5 ms |
1016 KB |
Output is correct |
30 |
Correct |
5 ms |
888 KB |
Output is correct |
31 |
Correct |
5 ms |
888 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
888 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
36 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
892 KB |
Output is correct |
2 |
Correct |
5 ms |
932 KB |
Output is correct |
3 |
Correct |
5 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
888 KB |
Output is correct |
5 |
Correct |
5 ms |
936 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
1016 KB |
Output is correct |
11 |
Correct |
5 ms |
1016 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
936 KB |
Output is correct |
19 |
Correct |
5 ms |
888 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
888 KB |
Output is correct |
22 |
Correct |
5 ms |
1016 KB |
Output is correct |
23 |
Correct |
5 ms |
1016 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
5 ms |
1016 KB |
Output is correct |
26 |
Correct |
5 ms |
1016 KB |
Output is correct |
27 |
Correct |
5 ms |
888 KB |
Output is correct |
28 |
Correct |
5 ms |
916 KB |
Output is correct |
29 |
Correct |
6 ms |
1016 KB |
Output is correct |
30 |
Correct |
7 ms |
1016 KB |
Output is correct |
31 |
Correct |
8 ms |
1144 KB |
Output is correct |
32 |
Correct |
8 ms |
1144 KB |
Output is correct |
33 |
Correct |
8 ms |
1144 KB |
Output is correct |
34 |
Correct |
8 ms |
1144 KB |
Output is correct |
35 |
Correct |
7 ms |
1144 KB |
Output is correct |
36 |
Correct |
7 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
888 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
4 ms |
888 KB |
Output is correct |
4 |
Correct |
4 ms |
888 KB |
Output is correct |
5 |
Correct |
5 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
904 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
888 KB |
Output is correct |
11 |
Correct |
5 ms |
888 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
904 KB |
Output is correct |
15 |
Correct |
6 ms |
1020 KB |
Output is correct |
16 |
Correct |
6 ms |
1016 KB |
Output is correct |
17 |
Correct |
7 ms |
1072 KB |
Output is correct |
18 |
Correct |
7 ms |
1024 KB |
Output is correct |
19 |
Correct |
7 ms |
1020 KB |
Output is correct |
20 |
Correct |
8 ms |
1144 KB |
Output is correct |
21 |
Correct |
8 ms |
1020 KB |
Output is correct |
22 |
Correct |
8 ms |
1016 KB |
Output is correct |
23 |
Correct |
7 ms |
1016 KB |
Output is correct |
24 |
Correct |
8 ms |
1060 KB |
Output is correct |
25 |
Correct |
9 ms |
1144 KB |
Output is correct |
26 |
Correct |
11 ms |
1272 KB |
Output is correct |
27 |
Correct |
13 ms |
1272 KB |
Output is correct |
28 |
Correct |
15 ms |
1272 KB |
Output is correct |
29 |
Correct |
18 ms |
1272 KB |
Output is correct |
30 |
Correct |
16 ms |
1272 KB |
Output is correct |
31 |
Correct |
15 ms |
1272 KB |
Output is correct |
32 |
Correct |
15 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1016 KB |
Output is correct |
2 |
Correct |
5 ms |
892 KB |
Output is correct |
3 |
Correct |
5 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
924 KB |
Output is correct |
5 |
Correct |
5 ms |
892 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
1016 KB |
Output is correct |
9 |
Correct |
6 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
1016 KB |
Output is correct |
11 |
Correct |
5 ms |
1016 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
888 KB |
Output is correct |
15 |
Correct |
5 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
888 KB |
Output is correct |
19 |
Correct |
5 ms |
884 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
6 ms |
888 KB |
Output is correct |
22 |
Correct |
6 ms |
1016 KB |
Output is correct |
23 |
Correct |
5 ms |
888 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
888 KB |
Output is correct |
26 |
Correct |
5 ms |
888 KB |
Output is correct |
27 |
Correct |
4 ms |
888 KB |
Output is correct |
28 |
Correct |
4 ms |
888 KB |
Output is correct |
29 |
Correct |
5 ms |
888 KB |
Output is correct |
30 |
Correct |
5 ms |
1016 KB |
Output is correct |
31 |
Correct |
5 ms |
1016 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
888 KB |
Output is correct |
35 |
Correct |
5 ms |
1016 KB |
Output is correct |
36 |
Correct |
5 ms |
1016 KB |
Output is correct |
37 |
Correct |
5 ms |
892 KB |
Output is correct |
38 |
Correct |
5 ms |
888 KB |
Output is correct |
39 |
Correct |
7 ms |
1020 KB |
Output is correct |
40 |
Correct |
7 ms |
1016 KB |
Output is correct |
41 |
Correct |
8 ms |
1144 KB |
Output is correct |
42 |
Correct |
8 ms |
1144 KB |
Output is correct |
43 |
Correct |
8 ms |
1144 KB |
Output is correct |
44 |
Correct |
9 ms |
1144 KB |
Output is correct |
45 |
Correct |
8 ms |
1144 KB |
Output is correct |
46 |
Correct |
8 ms |
1016 KB |
Output is correct |
47 |
Correct |
8 ms |
1144 KB |
Output is correct |
48 |
Correct |
10 ms |
1144 KB |
Output is correct |
49 |
Correct |
12 ms |
1272 KB |
Output is correct |
50 |
Correct |
16 ms |
1400 KB |
Output is correct |
51 |
Correct |
15 ms |
1272 KB |
Output is correct |
52 |
Correct |
15 ms |
1272 KB |
Output is correct |
53 |
Correct |
19 ms |
1272 KB |
Output is correct |
54 |
Correct |
15 ms |
1272 KB |
Output is correct |
55 |
Correct |
15 ms |
1272 KB |
Output is correct |
56 |
Correct |
6 ms |
1144 KB |
Output is correct |
57 |
Correct |
7 ms |
1144 KB |
Output is correct |
58 |
Correct |
8 ms |
1272 KB |
Output is correct |
59 |
Correct |
8 ms |
1272 KB |
Output is correct |
60 |
Correct |
8 ms |
1272 KB |
Output is correct |
61 |
Correct |
9 ms |
1276 KB |
Output is correct |
62 |
Correct |
10 ms |
1272 KB |
Output is correct |
63 |
Correct |
10 ms |
1276 KB |
Output is correct |
64 |
Correct |
14 ms |
1400 KB |
Output is correct |
65 |
Correct |
5 ms |
1016 KB |
Output is correct |
66 |
Correct |
7 ms |
1144 KB |
Output is correct |
67 |
Correct |
7 ms |
1272 KB |
Output is correct |
68 |
Correct |
8 ms |
1272 KB |
Output is correct |
69 |
Correct |
8 ms |
1272 KB |
Output is correct |
70 |
Correct |
9 ms |
1272 KB |
Output is correct |
71 |
Correct |
9 ms |
1272 KB |
Output is correct |
72 |
Correct |
10 ms |
1268 KB |
Output is correct |
73 |
Correct |
9 ms |
1272 KB |
Output is correct |
74 |
Correct |
10 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
888 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
5 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
888 KB |
Output is correct |
5 |
Correct |
4 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
892 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
988 KB |
Output is correct |
9 |
Correct |
5 ms |
932 KB |
Output is correct |
10 |
Correct |
5 ms |
988 KB |
Output is correct |
11 |
Correct |
5 ms |
988 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
892 KB |
Output is correct |
14 |
Correct |
5 ms |
892 KB |
Output is correct |
15 |
Correct |
5 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
884 KB |
Output is correct |
19 |
Correct |
5 ms |
940 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
888 KB |
Output is correct |
22 |
Correct |
5 ms |
888 KB |
Output is correct |
23 |
Correct |
5 ms |
888 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
5 ms |
888 KB |
Output is correct |
26 |
Correct |
7 ms |
1016 KB |
Output is correct |
27 |
Correct |
7 ms |
1016 KB |
Output is correct |
28 |
Correct |
7 ms |
1016 KB |
Output is correct |
29 |
Correct |
8 ms |
1016 KB |
Output is correct |
30 |
Correct |
7 ms |
1016 KB |
Output is correct |
31 |
Correct |
7 ms |
1016 KB |
Output is correct |
32 |
Correct |
7 ms |
1016 KB |
Output is correct |
33 |
Correct |
8 ms |
1144 KB |
Output is correct |
34 |
Correct |
7 ms |
1036 KB |
Output is correct |
35 |
Correct |
9 ms |
1144 KB |
Output is correct |
36 |
Correct |
11 ms |
1148 KB |
Output is correct |
37 |
Correct |
30 ms |
1320 KB |
Output is correct |
38 |
Correct |
15 ms |
1272 KB |
Output is correct |
39 |
Correct |
16 ms |
1272 KB |
Output is correct |
40 |
Correct |
16 ms |
1332 KB |
Output is correct |
41 |
Correct |
16 ms |
1272 KB |
Output is correct |
42 |
Correct |
19 ms |
1272 KB |
Output is correct |
43 |
Correct |
6 ms |
1016 KB |
Output is correct |
44 |
Correct |
7 ms |
1144 KB |
Output is correct |
45 |
Correct |
8 ms |
1272 KB |
Output is correct |
46 |
Correct |
9 ms |
1276 KB |
Output is correct |
47 |
Correct |
9 ms |
1272 KB |
Output is correct |
48 |
Correct |
9 ms |
1272 KB |
Output is correct |
49 |
Correct |
9 ms |
1276 KB |
Output is correct |
50 |
Correct |
10 ms |
1272 KB |
Output is correct |
51 |
Correct |
9 ms |
1272 KB |
Output is correct |
52 |
Correct |
95 ms |
4472 KB |
Output is correct |
53 |
Correct |
141 ms |
6008 KB |
Output is correct |
54 |
Correct |
250 ms |
8824 KB |
Output is correct |
55 |
Correct |
245 ms |
8824 KB |
Output is correct |
56 |
Correct |
862 ms |
23544 KB |
Output is correct |
57 |
Correct |
850 ms |
23624 KB |
Output is correct |
58 |
Correct |
760 ms |
23544 KB |
Output is correct |
59 |
Correct |
740 ms |
23548 KB |
Output is correct |
60 |
Correct |
908 ms |
23628 KB |
Output is correct |
61 |
Correct |
10 ms |
1272 KB |
Output is correct |
62 |
Correct |
146 ms |
6100 KB |
Output is correct |
63 |
Correct |
252 ms |
8952 KB |
Output is correct |
64 |
Correct |
238 ms |
8824 KB |
Output is correct |
65 |
Correct |
423 ms |
14368 KB |
Output is correct |
66 |
Correct |
649 ms |
19644 KB |
Output is correct |
67 |
Correct |
871 ms |
23544 KB |
Output is correct |
68 |
Correct |
896 ms |
23660 KB |
Output is correct |
69 |
Correct |
801 ms |
23664 KB |
Output is correct |