답안 #200343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200343 2020-02-06T11:08:49 Z dimash241 코알라 (APIO17_koala) C++17
37 / 100
79 ms 376 KB
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

void playRound(int *B, int *R);

int minValue(int N, int W) {
	int n = N;
    // TODO: Implement Subtask 1 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    int b[N], r[N];
    for (int i = 0; i < n; i++)
		b[i] = 0;
	b[0] = 1;
	playRound(b, r);
	for (int i = 0; i < N; i++)
		if (r[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;
    int u[N] = {};
    int b[N], r[N];
    for (int i = 0; i < N; i ++)
    	u[i] = 0;

	while (n > 1){
		int cost = min(12, W / n);
		for (int i = 0; i < N; i++){
			if (!u[i])
				b[i] = cost;
			else
				b[i] = 0;
		}
		playRound(b, r);
		for (int i = 0; i < N; i++)
			if (!u[i] && r[i] <= b[i])
				u[i] = 1;
		n = 0;
		for (int i = 0; i < N; i++)
			if (u[i] == 0)
				n ++;
	}
	for (int i = 0; i < N; i++)
		if (!u[i])
			return i;

	return 0;
}

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.
    int b[N], R[N];
    int n = N;
    int w = W;

    int l = 0, r = 14;
	while (r - l > 1) {
		int md = (l + r) >> 1;
		for (int i = 0; i < n; i++)
			b[i] = w / n - 1;

		b[0] = b[1] = md * (w / n);
		playRound(b, R);
		bool g1 = (R[0] > b[0]);
		bool g2 = (R[1] > b[1]);
		if (g1 == g2){
			if (g1 == 1) l = md;
			else r = md;
		}
		else return g2;
	}
	return 0;
}

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 {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}
/* 
static int N, W;
static int P[105];

static int maxQueries = 3200;
static int numQueries;

static void runGame(int F);
static void grader();

int main() {
    grader();
    return 0;
}

void playRound(int *B, int *R) {
    int i, j;

    int S = 0;
    for (i=0;i<N;++i) {
        if ( !(B[i] >= 0 && B[i] <= W) ) {
            printf("Invalid query.\n");
            exit(0);
        }
        S += B[i];
    }
    if (S > W) {
        printf("Invalid query.\n");
        exit(0);
    }

    numQueries++;
    if (numQueries > maxQueries) {
        printf("Too many queries.\n");
        exit(0);
    }

    int cache[2][205];
    int num[2][205];
    char taken[105][205];

    for (i=0;i<205;++i) {
        cache[1][i] = 0;
        num[1][i] = 0;
    }

    for (i=0;i<N;++i) {
        int v = B[i]+1;
        int ii = i&1;
        int o = ii^1;
        for (j=0;j<=W;++j) {
            cache[ii][j] = cache[o][j];
            num[ii][j] = num[o][j];
            taken[i][j] = 0;
        }
        for (j=W;j>=v;--j) {
            int h = cache[o][j-v] + P[i];
            int hn = num[o][j-v] + 1;
            if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
                cache[ii][j] = h;
                num[ii][j] = hn;
                taken[i][j] = 1;
            } else {
                taken[i][j] = 0;
            }
        }
    }

    int cur = W;
    for (i=N-1;i>=0;--i) {
        R[i] = taken[i][cur] ? (B[i] + 1) : 0;
        cur -= R[i];
    }
}

static void runGame(int F) {
    int i;

    scanf("%d %d",&N,&W);
    for (i=0;i<N;++i) {
        scanf("%d",&P[i]);
    }

    numQueries = 0;
    if (F == 1) {
        printf("%d\n", minValue(N, W));
    } else if (F == 2) {
        printf("%d\n", maxValue(N, W));
    } else if (F == 3) {
        printf("%d\n", greaterValue(N, W));
    } else if (F == 4) {
        int userP[105];
        allValues(N, W, userP);
        for (i=0;i<N;i++) {
            printf("%d ",userP[i]);
        }
        printf("\n");
    }
    printf("Made %d calls to playRound.\n", numQueries);
}

static void grader() {
    int i;

    int F, G;
    scanf("%d %d",&F,&G);

    for (i=0;i<G;i++) {
        runGame(F);
    }
}

// B...a*/

Compilation message

koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:66:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i < N; i ++)
     ^~~
koala.cpp:69:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  while (n > 1){
  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 248 KB Output is correct
2 Correct 10 ms 248 KB Output is correct
3 Correct 10 ms 248 KB Output is correct
4 Correct 10 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 248 KB Output is correct
2 Correct 22 ms 376 KB Output is correct
3 Correct 23 ms 376 KB Output is correct
4 Correct 22 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 248 KB Output is correct
2 Correct 76 ms 248 KB Output is correct
3 Correct 70 ms 252 KB Output is correct
4 Correct 67 ms 332 KB Output is correct
5 Correct 66 ms 248 KB Output is correct
6 Correct 66 ms 248 KB Output is correct
7 Correct 67 ms 352 KB Output is correct
8 Correct 70 ms 248 KB Output is correct
9 Correct 69 ms 248 KB Output is correct
10 Correct 79 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -