Submission #725866

# Submission time Handle Problem Language Result Execution time Memory
725866 2023-04-18T08:03:12 Z pragmatist Koala Game (APIO17_koala) C++17
88 / 100
61 ms 444 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 = 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 208 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 13 ms 316 KB Output is correct
2 Correct 16 ms 316 KB Output is correct
3 Correct 15 ms 208 KB Output is correct
4 Correct 12 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 444 KB Output is correct
2 Correct 61 ms 320 KB Output is correct
3 Correct 48 ms 316 KB Output is correct
4 Correct 55 ms 328 KB Output is correct
5 Correct 51 ms 324 KB Output is correct
6 Correct 49 ms 444 KB Output is correct
7 Correct 47 ms 208 KB Output is correct
8 Correct 52 ms 336 KB Output is correct
9 Correct 50 ms 324 KB Output is correct
10 Correct 46 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 208 KB Output is correct
2 Correct 29 ms 296 KB Output is correct
3 Correct 28 ms 208 KB Output is correct
4 Correct 26 ms 208 KB Output is correct
5 Correct 28 ms 208 KB Output is correct
6 Correct 29 ms 208 KB Output is correct
7 Correct 28 ms 208 KB Output is correct
8 Correct 26 ms 320 KB Output is correct
9 Correct 27 ms 208 KB Output is correct
10 Correct 26 ms 312 KB Output is correct
11 Correct 27 ms 208 KB Output is correct
12 Correct 16 ms 312 KB Output is correct
13 Correct 31 ms 296 KB Output is correct
14 Correct 27 ms 208 KB Output is correct
15 Correct 26 ms 208 KB Output is correct
16 Correct 23 ms 316 KB Output is correct
17 Correct 24 ms 316 KB Output is correct
18 Correct 24 ms 296 KB Output is correct
19 Correct 24 ms 208 KB Output is correct
20 Correct 25 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 7 ms 208 KB Output is partially correct
2 Partially correct 7 ms 328 KB Output is partially correct
3 Partially correct 7 ms 208 KB Output is partially correct
4 Partially correct 7 ms 328 KB Output is partially correct
5 Partially correct 7 ms 208 KB Output is partially correct
6 Partially correct 7 ms 208 KB Output is partially correct
7 Partially correct 8 ms 328 KB Output is partially correct
8 Partially correct 7 ms 328 KB Output is partially correct
9 Partially correct 7 ms 208 KB Output is partially correct
10 Partially correct 6 ms 208 KB Output is partially correct
11 Partially correct 7 ms 328 KB Output is partially correct
12 Partially correct 5 ms 324 KB Output is partially correct
13 Partially correct 7 ms 208 KB Output is partially correct
14 Partially correct 7 ms 208 KB Output is partially correct
15 Partially correct 6 ms 208 KB Output is partially correct
16 Partially correct 7 ms 208 KB Output is partially correct
17 Partially correct 7 ms 208 KB Output is partially correct
18 Partially correct 6 ms 208 KB Output is partially correct
19 Partially correct 6 ms 208 KB Output is partially correct
20 Partially correct 7 ms 332 KB Output is partially correct
21 Partially correct 6 ms 336 KB Output is partially correct
22 Partially correct 7 ms 208 KB Output is partially correct
23 Partially correct 7 ms 208 KB Output is partially correct
24 Partially correct 6 ms 208 KB Output is partially correct
25 Partially correct 9 ms 332 KB Output is partially correct
26 Partially correct 7 ms 208 KB Output is partially correct
27 Partially correct 6 ms 208 KB Output is partially correct
28 Partially correct 6 ms 336 KB Output is partially correct
29 Partially correct 8 ms 208 KB Output is partially correct
30 Partially correct 8 ms 336 KB Output is partially correct
31 Partially correct 7 ms 332 KB Output is partially correct
32 Partially correct 7 ms 316 KB Output is partially correct
33 Partially correct 7 ms 336 KB Output is partially correct
34 Partially correct 7 ms 208 KB Output is partially correct
35 Partially correct 7 ms 208 KB Output is partially correct
36 Partially correct 7 ms 208 KB Output is partially correct
37 Partially correct 7 ms 208 KB Output is partially correct
38 Partially correct 9 ms 208 KB Output is partially correct
39 Partially correct 7 ms 208 KB Output is partially correct
40 Partially correct 6 ms 336 KB Output is partially correct