Submission #397859

# Submission time Handle Problem Language Result Execution time Memory
397859 2021-05-03T09:52:14 Z juggernaut Bali Sculptures (APIO15_sculpture) C++17
100 / 100
94 ms 460 KB
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define tut(x) array<int, x> 
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii; 
typedef vector<int> vii;
typedef vector<pii> vpii;
 
template<class T> bool umin(T& a, const T& b) { return a > b? a = b, true:false; }
template<class T> bool umax(T& a, const T& b) { return a < b? a = b, true:false; }
void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);  
	freopen((s+".out").c_str(),"w",stdout); }
//template<class T> tree<T, 
//less<T>, null_type, rb_tree_tag, 
//tree_order_statistics_node_update> ordered_set;
 
const int N = 2e3+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
const int B = 500;
 
#define MULTI 0
int n, m, ans, q, k, res, a[N];
int b, dp[N], pref[N], num;
bool check(int a, int b) { return (((a>>b) | num) == num); }
 
/*
 
6 1 3
8 1 2 1 5 4
 
*/
 
void solve(int t_case){
	cin>>n;
	if(n <= 100){
		int l, r; cin>>l>>r;
		vv<vii> dp(105, vii(105, 0));
		for(int i=1;i<=n;i++) cin>>a[i], pref[i] = pref[i-1] + a[i];
		for(int b=45;b>=0;b--){
			for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j] = 0;
			dp[0][0] = 1;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int l=0;l<i;l++){
						if(check(pref[i] - pref[l], b)) dp[i][j] |= dp[l][j-1];
					}
				}
			} 
			
			bool ok = 1;
			for(int i=l;i<=r;i++) if(dp[n][i]) ok = 0;
			if(ok) num += 1;
			num<<=1;
		} num>>=1; cout<<num<<"\n";
	} else {
		cin>>b, assert(b == 1), cin>>b;
		for(int i=1;i<=n;i++) cin>>a[i], pref[i] = pref[i-1] + a[i];
		num = 0;
		for(int bit=45;bit>=0;bit--){
			for(int i=1;i<=n;i++) dp[i] = mod;
			for(int i=1;i<=n;i++){
				//if(check(pref[i], bit)) dp[i] = 1;
				for(int j=0;j<i;j++) if(check(pref[i] - pref[j], bit)) umin(dp[i], dp[j] + 1);
			} 
			if(dp[n] > b) num += 1;
			num <<= 1; 
		} num >>=1; cout<<num<<"\n";\
	}
}
 
signed main(){ 
	NeedForSpeed
	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	} return 0;
}

Compilation message

sculpture.cpp: In function 'void usaco(std::string)':
sculpture.cpp:30:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   30 | void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:31:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   31 |  freopen((s+".out").c_str(),"w",stdout); }
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 5 ms 316 KB Output is correct
30 Correct 6 ms 332 KB Output is correct
31 Correct 10 ms 320 KB Output is correct
32 Correct 9 ms 332 KB Output is correct
33 Correct 10 ms 416 KB Output is correct
34 Correct 10 ms 332 KB Output is correct
35 Correct 9 ms 332 KB Output is correct
36 Correct 10 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 5 ms 412 KB Output is correct
17 Correct 7 ms 332 KB Output is correct
18 Correct 10 ms 412 KB Output is correct
19 Correct 10 ms 332 KB Output is correct
20 Correct 9 ms 416 KB Output is correct
21 Correct 9 ms 332 KB Output is correct
22 Correct 9 ms 320 KB Output is correct
23 Correct 10 ms 332 KB Output is correct
24 Correct 10 ms 416 KB Output is correct
25 Correct 20 ms 332 KB Output is correct
26 Correct 33 ms 332 KB Output is correct
27 Correct 53 ms 332 KB Output is correct
28 Correct 69 ms 452 KB Output is correct
29 Correct 67 ms 332 KB Output is correct
30 Correct 68 ms 396 KB Output is correct
31 Correct 68 ms 332 KB Output is correct
32 Correct 68 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 312 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 5 ms 360 KB Output is correct
40 Correct 7 ms 416 KB Output is correct
41 Correct 11 ms 416 KB Output is correct
42 Correct 10 ms 332 KB Output is correct
43 Correct 11 ms 332 KB Output is correct
44 Correct 10 ms 312 KB Output is correct
45 Correct 10 ms 416 KB Output is correct
46 Correct 10 ms 332 KB Output is correct
47 Correct 12 ms 416 KB Output is correct
48 Correct 21 ms 332 KB Output is correct
49 Correct 33 ms 332 KB Output is correct
50 Correct 52 ms 392 KB Output is correct
51 Correct 68 ms 332 KB Output is correct
52 Correct 67 ms 332 KB Output is correct
53 Correct 69 ms 332 KB Output is correct
54 Correct 78 ms 332 KB Output is correct
55 Correct 69 ms 332 KB Output is correct
56 Correct 8 ms 416 KB Output is correct
57 Correct 24 ms 332 KB Output is correct
58 Correct 38 ms 332 KB Output is correct
59 Correct 48 ms 332 KB Output is correct
60 Correct 50 ms 396 KB Output is correct
61 Correct 49 ms 332 KB Output is correct
62 Correct 52 ms 332 KB Output is correct
63 Correct 54 ms 332 KB Output is correct
64 Correct 54 ms 332 KB Output is correct
65 Correct 8 ms 420 KB Output is correct
66 Correct 15 ms 332 KB Output is correct
67 Correct 24 ms 416 KB Output is correct
68 Correct 37 ms 332 KB Output is correct
69 Correct 49 ms 324 KB Output is correct
70 Correct 50 ms 332 KB Output is correct
71 Correct 50 ms 332 KB Output is correct
72 Correct 58 ms 332 KB Output is correct
73 Correct 51 ms 332 KB Output is correct
74 Correct 51 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 5 ms 316 KB Output is correct
27 Correct 7 ms 416 KB Output is correct
28 Correct 9 ms 332 KB Output is correct
29 Correct 10 ms 332 KB Output is correct
30 Correct 10 ms 324 KB Output is correct
31 Correct 10 ms 424 KB Output is correct
32 Correct 10 ms 416 KB Output is correct
33 Correct 10 ms 420 KB Output is correct
34 Correct 10 ms 332 KB Output is correct
35 Correct 20 ms 416 KB Output is correct
36 Correct 33 ms 316 KB Output is correct
37 Correct 53 ms 332 KB Output is correct
38 Correct 69 ms 332 KB Output is correct
39 Correct 67 ms 392 KB Output is correct
40 Correct 70 ms 332 KB Output is correct
41 Correct 68 ms 396 KB Output is correct
42 Correct 67 ms 332 KB Output is correct
43 Correct 8 ms 332 KB Output is correct
44 Correct 24 ms 412 KB Output is correct
45 Correct 37 ms 452 KB Output is correct
46 Correct 51 ms 396 KB Output is correct
47 Correct 48 ms 332 KB Output is correct
48 Correct 49 ms 332 KB Output is correct
49 Correct 59 ms 392 KB Output is correct
50 Correct 56 ms 332 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 15 ms 352 KB Output is correct
53 Correct 13 ms 332 KB Output is correct
54 Correct 25 ms 332 KB Output is correct
55 Correct 26 ms 364 KB Output is correct
56 Correct 88 ms 460 KB Output is correct
57 Correct 85 ms 368 KB Output is correct
58 Correct 85 ms 452 KB Output is correct
59 Correct 87 ms 332 KB Output is correct
60 Correct 85 ms 332 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 15 ms 332 KB Output is correct
63 Correct 26 ms 348 KB Output is correct
64 Correct 23 ms 364 KB Output is correct
65 Correct 45 ms 360 KB Output is correct
66 Correct 65 ms 360 KB Output is correct
67 Correct 81 ms 332 KB Output is correct
68 Correct 94 ms 376 KB Output is correct
69 Correct 87 ms 376 KB Output is correct