Submission #725865

# Submission time Handle Problem Language Result Execution time Memory
725865 2023-04-18T08:02:26 Z pragmatist Koala Game (APIO17_koala) C++17
100 / 100
63 ms 356 KB
#include "koala.h"        
#include <bits/stdc++.h>

#define sz(v) (int)v.size()
#define pb push_back

using namespace std;      

int minValue(int N, int W) {
    // TODO: Implement Subtask 1 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    int n = N;
    int a[n], b[n];
    memset(a, 0, sizeof(a));
    a[0] = 1;
    playRound(a, b);    
    for(int i = 0; i < n; ++i) {
    	if(b[i] == 0) {
    		return i;
    	}
    }
    return 0;
}

int maxValue(int N, int W) {
    // TODO: Implement Subtask 2 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    int n = N, a[n], b[n];
   	vector<int> v;
   	for(int i = 0; i < n; ++i) {
   		v.pb(i);
   	}
   	while(sz(v) > 1) {
		int t = W / sz(v);
		bool used[n];
		memset(used, 0, sizeof(used));
		for(auto x : v) used[x] = 1;
		for(int i = 0; i < n; ++i) {
			if(!used[i]) {
				a[i] = 0;
			} else {
				a[i] = t;
			}
		}
		playRound(a, b);
		vector<int> to;
		for(int i = 0; i < n; ++i) {
			if(b[i] > t) {
				to.pb(i);
			}
		}
		v = to;		   		
   	}
    return v[0];
}

bool cmp(int i, int j, int n, int W) {
	int a[n], b[n];
	int l = 1, r = min(9, W / 2), ans = -1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		memset(a, 0, sizeof(a));	
		a[i] = a[j] = mid;
		playRound(a, b);   
		if(a[i] >= b[i] && a[j] >= b[j]) {
			r = mid - 1;
			continue;
		}
		bool c = (a[i] < b[i]), d = (a[j] < b[j]);
		if(c && d) {
			l = mid + 1;  
			continue;
		}
		ans = (c < d);
		break;
	}
	assert(ans != -1);
	return ans;	
}

int greaterValue(int N, int W) {
    // TODO: Implement Subtask 3 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    return cmp(0, 1, N, W);
}

bool comp(int i, int j, int n) {
	int a[n], b[n];
	memset(a, 0, sizeof(a));
	a[i] = a[j] = n;
	playRound(a, b);
	assert((b[i] > a[i]) || (b[j] > a[j]));
	if(b[i] < a[i]) {
		return 1;
	}
	return 0;
}

void calc(int l, int r, vector<int> &v, vector<int> &temp, int n, int w) {
	if(l == r) {
		return;
	}	
	int mid = (l + r) >> 1;
	calc(l, mid, v, temp, n, w);
	calc(mid + 1, r, v, temp, n, w);
	int timer = l, i = l, j = mid + 1;
	while(i <= mid && j <= r) {
		if((w == 2 * n ? comp(v[i], v[j], sz(v)) : cmp(v[i], v[j], n, w))) {
			temp[timer++] = v[i++];
			continue;
		}
		temp[timer++] = v[j++];
	} 
	for(int k = i; k <= mid; ++k) temp[timer++] = v[k];
	for(int k = j; k <= r; ++k) temp[timer++] = v[k];
	for(int i = l; i <= r; ++i) v[i] = temp[i];	
}

int timer;

vector<int> solve(vector<int> &v, int tl, int tr, int n, int W) {
	if(sz(v) <= 1 || tl > tr) {
		return v;
	}
	int c = min((int)sqrt(2 * tl), W / sz(v));
	int a[n], b[n];
	memset(a, 0, sizeof(a));
	for(auto x : v) {
		a[x] = c;
	}
	playRound(a, b);
	vector<int> l, r;
	for(auto x : v) {
		if(a[x] < b[x]) {
			r.pb(x);
		} else {
			l.pb(x);
		}
	}
	if(l.empty() || r.empty()) {
		vector<int> op = v;
		calc(0, sz(v) - 1, v, op, n, W);
		return v;		
	}
	l = solve(l, tl, tl + sz(l) - 1, n, W);
	r = solve(r, tl + sz(l), tr, n, W);
	for(auto x : r) {
		l.pb(x);
	}
	return l;
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        // TODO: Implement Subtask 4 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
        int n = N;    
        vector<int> v, p;
        for(int i = 1; i <= n; ++i) {
        	v.pb(i - 1);
    	}
    	p = v;
    	calc(0, n - 1, v, p, N, W); 
    	for(int i = 0; i < n; ++i) {
    		P[v[i]] = i + 1;
    	}
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
		int n = N, a[n], b[n];
		vector<int> v; 
		for(int t = 0; t < n; ++t) {
			v.pb(t);
		}
		v = solve(v, 1, n, n, W);
		for(int i = 0; i < n; ++i) {
    		P[v[i]] = i + 1;
    	}
    }
}

Compilation message

koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:175:14: warning: unused variable 'a' [-Wunused-variable]
  175 |   int n = N, a[n], b[n];
      |              ^
koala.cpp:175:20: warning: unused variable 'b' [-Wunused-variable]
  175 |   int n = N, a[n], b[n];
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 316 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 320 KB Output is correct
2 Correct 15 ms 208 KB Output is correct
3 Correct 15 ms 252 KB Output is correct
4 Correct 13 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 332 KB Output is correct
2 Correct 63 ms 324 KB Output is correct
3 Correct 57 ms 324 KB Output is correct
4 Correct 54 ms 328 KB Output is correct
5 Correct 52 ms 320 KB Output is correct
6 Correct 58 ms 308 KB Output is correct
7 Correct 50 ms 328 KB Output is correct
8 Correct 57 ms 320 KB Output is correct
9 Correct 55 ms 316 KB Output is correct
10 Correct 52 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 208 KB Output is correct
2 Correct 40 ms 208 KB Output is correct
3 Correct 39 ms 208 KB Output is correct
4 Correct 31 ms 208 KB Output is correct
5 Correct 27 ms 316 KB Output is correct
6 Correct 28 ms 208 KB Output is correct
7 Correct 30 ms 208 KB Output is correct
8 Correct 33 ms 208 KB Output is correct
9 Correct 30 ms 208 KB Output is correct
10 Correct 27 ms 208 KB Output is correct
11 Correct 29 ms 208 KB Output is correct
12 Correct 16 ms 316 KB Output is correct
13 Correct 30 ms 272 KB Output is correct
14 Correct 30 ms 208 KB Output is correct
15 Correct 27 ms 208 KB Output is correct
16 Correct 33 ms 208 KB Output is correct
17 Correct 33 ms 208 KB Output is correct
18 Correct 24 ms 208 KB Output is correct
19 Correct 29 ms 308 KB Output is correct
20 Correct 31 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 316 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 5 ms 312 KB Output is correct
6 Correct 3 ms 356 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 5 ms 320 KB Output is correct
10 Correct 6 ms 336 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 3 ms 336 KB Output is correct
17 Correct 3 ms 336 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 336 KB Output is correct
20 Correct 7 ms 332 KB Output is correct
21 Correct 3 ms 336 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 3 ms 336 KB Output is correct
24 Correct 5 ms 208 KB Output is correct
25 Correct 5 ms 336 KB Output is correct
26 Correct 3 ms 208 KB Output is correct
27 Correct 5 ms 336 KB Output is correct
28 Correct 3 ms 208 KB Output is correct
29 Correct 5 ms 208 KB Output is correct
30 Correct 4 ms 208 KB Output is correct
31 Correct 4 ms 328 KB Output is correct
32 Correct 4 ms 336 KB Output is correct
33 Correct 4 ms 336 KB Output is correct
34 Correct 3 ms 292 KB Output is correct
35 Correct 6 ms 208 KB Output is correct
36 Correct 3 ms 208 KB Output is correct
37 Correct 7 ms 208 KB Output is correct
38 Correct 3 ms 336 KB Output is correct
39 Correct 3 ms 324 KB Output is correct
40 Correct 3 ms 328 KB Output is correct