Submission #262908

# Submission time Handle Problem Language Result Execution time Memory
262908 2020-08-13T10:52:47 Z shayan_p Koala Game (APIO17_koala) C++14
47 / 100
174 ms 504 KB
// And you curse yourself for things you never done

#include<bits/stdc++.h>
#include "koala.h"

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 110, mod = 1e9 + 7, inf = 1e9 + 10;

int minValue(int N, int W) {
    int A[maxn], B[maxn];
    memset(A, 0, sizeof A);
    memset(B, 0, sizeof B);
    A[0] = 1;
    playRound(A, B);
    if(B[0] <= 1)
	return 0;
    int ans = 0;
    for(int i = 1; i < N; i++)
	if(B[i] == 0)
	    ans = i;
    return ans;
}

int maxValue(int N, int W) {
    int SM[maxn];
    vector<pii> v[maxn];
    int h[maxn];
    pii pr[maxn];

    memset(SM, 0, sizeof SM);
    memset(h, -1, sizeof h);
    for(int i = 0; i < maxn; i++)
	v[i].clear();
    
    for(int i = 1; i <= N; i++)
	SM[i] = SM[i-1] + i;

    auto f = [&](int n, int cost, int top, int lim){
		 assert(top <= n);
		 int sm = 0, bst = 0;
		 for(int i = 0; i <= top; i++){
		     if(i * cost > lim)
			 break;
		     bst = max(bst, sm + SM[n-top] - SM[max(int(0), n-top-(lim - i*cost))]);
		     sm+= n-i;
		 }
		 sm = 0;
		 int bstid = -1;
		 for(int i = 0; i <= top; i++){
		     if(i * cost > lim)
			 break;
		     int num = sm + SM[n-top] - SM[max(int(0), n-top-(lim - i*cost))];
		     if(num == bst){
			 if(bstid == -1)
			     bstid = i;
			 if(bstid != i)
			     return -1;
		     }
		     sm+= n-i;
		 }
		 return bstid;
	     };

    
    for(int top = 100; top >= 1; top--){
	for(int cost = 2; top * (cost-1) <= 100; cost++){
	    int x =  f(100, cost, top, 100);
	    if(x != -1)
		v[top].PB({x, cost});
	}
    }

    queue<int> q;
    h[N] = 0;
    q.push(N);
    while(sz(q)){
	int u = q.front();
	q.pop();
	for(pii p : v[u])
	    if(h[p.F] == -1)
		pr[p.F] = {u, p.S}, h[p.F] = h[u] + 1, q.push(p.F);
    }

    vector<pii> tdo;
    int tmp = 1;
    while(tmp != N){
	tdo.PB(pr[tmp]);
	tmp = pr[tmp].F;
    }
    reverse(tdo.begin(), tdo.end());

    vector<int> big;
    for(int i = 0; i < N; i++){
	big.PB(i);
    }

    int A[maxn], B[maxn];
    bool inside[maxn];
    for(pii p : tdo){
	memset(A, 0, sizeof A);
	memset(B, 0, sizeof B);
	memset(inside, 0, sizeof inside);
	for(int id : big)
	    A[id] = p.S-1, inside[id] = 1;
	playRound(A, B);
	big.clear();
	for(int i = 0; i < N; i++){
	    if(inside[i] && B[i] >= p.S)
		big.PB(i);
	}
    }
    assert(sz(big) == 1);
    return big[0];
}

bool comp(int a, int b){
    int A[maxn], B[maxn];
    for(int d : {1, 3, 5, 9}){
	memset(A, 0, sizeof A);
	memset(B, 0, sizeof B);
	A[a] = d, A[b] = d;
	playRound(A, B);
	bool X = B[a] > d, Y = B[b] > d;
	if(X ^ Y){
	    if(X)
		return 0;
	    else
		return 1;
	}
    }
    assert(0);
}

int greaterValue(int N, int W) {
    return comp(0, 1);
}

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.
    } else {
	int arr[maxn];
	iota(arr, arr+N, 0);
	sort(arr, arr + N, [](int a, int  b){ return comp(a, b); });
	for(int i = 0; i < N; i++)
	    P[arr[i]] = i + 1;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 384 KB Output is correct
2 Correct 27 ms 384 KB Output is correct
3 Correct 27 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 166 ms 384 KB Output is partially correct
2 Partially correct 155 ms 384 KB Output is partially correct
3 Partially correct 161 ms 384 KB Output is partially correct
4 Partially correct 174 ms 384 KB Output is partially correct
5 Partially correct 157 ms 384 KB Output is partially correct
6 Partially correct 155 ms 400 KB Output is partially correct
7 Partially correct 154 ms 504 KB Output is partially correct
8 Partially correct 154 ms 384 KB Output is partially correct
9 Partially correct 154 ms 384 KB Output is partially correct
10 Partially correct 154 ms 504 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 84 ms 384 KB Output is partially correct
2 Partially correct 130 ms 384 KB Output is partially correct
3 Partially correct 108 ms 376 KB Output is partially correct
4 Partially correct 110 ms 384 KB Output is partially correct
5 Partially correct 121 ms 384 KB Output is partially correct
6 Partially correct 123 ms 504 KB Output is partially correct
7 Partially correct 115 ms 384 KB Output is partially correct
8 Partially correct 111 ms 384 KB Output is partially correct
9 Partially correct 112 ms 384 KB Output is partially correct
10 Partially correct 110 ms 384 KB Output is partially correct
11 Partially correct 110 ms 504 KB Output is partially correct
12 Partially correct 72 ms 384 KB Output is partially correct
13 Partially correct 110 ms 384 KB Output is partially correct
14 Partially correct 106 ms 384 KB Output is partially correct
15 Partially correct 105 ms 504 KB Output is partially correct
16 Partially correct 112 ms 384 KB Output is partially correct
17 Partially correct 120 ms 384 KB Output is partially correct
18 Partially correct 139 ms 384 KB Output is partially correct
19 Partially correct 106 ms 380 KB Output is partially correct
20 Partially correct 108 ms 384 KB Output is partially correct
21 Partially correct 105 ms 504 KB Output is partially correct
22 Partially correct 117 ms 384 KB Output is partially correct
23 Partially correct 81 ms 504 KB Output is partially correct
24 Partially correct 117 ms 384 KB Output is partially correct
25 Partially correct 112 ms 384 KB Output is partially correct
26 Partially correct 118 ms 504 KB Output is partially correct
27 Partially correct 113 ms 380 KB Output is partially correct
28 Partially correct 123 ms 384 KB Output is partially correct
29 Partially correct 108 ms 380 KB Output is partially correct
30 Partially correct 110 ms 376 KB Output is partially correct
31 Partially correct 107 ms 384 KB Output is partially correct
32 Partially correct 108 ms 384 KB Output is partially correct
33 Partially correct 110 ms 504 KB Output is partially correct
34 Partially correct 96 ms 384 KB Output is partially correct
35 Partially correct 113 ms 504 KB Output is partially correct
36 Partially correct 102 ms 384 KB Output is partially correct
37 Partially correct 109 ms 384 KB Output is partially correct
38 Partially correct 105 ms 384 KB Output is partially correct
39 Partially correct 107 ms 504 KB Output is partially correct
40 Partially correct 113 ms 384 KB Output is partially correct