답안 #1075383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075383 2024-08-26T04:55:01 Z Cyanberry 코알라 (APIO17_koala) C++14
11 / 100
21 ms 456 KB
#include <bits/stdc++.h>
using namespace std;

#include "koala.h"

int perm[] = {5, 3, 2, 1, 6, 4};

int minValue(int N, int W) {
    int play[100], result[100];
    for (int i = 0; i<100; ++i) {
        play[i] = 0;
    }
    play[0] = 1;
    playRound(play, result);
    for (int i = 0; i < 100; ++i) {
        if (result[i] <= play[i]) {
            return i;
        }
    }
    return 0;
}

int maxValue(int N, int W) {
    int play[N], result[N];
    for (int i = 0; i < N; ++i) {
        play[i] = 1;
    }
    playRound(play, result);
    int eep = 100;
    while (eep > 1)
    {
        eep = 0;
        for (int i = 0; i < N; ++i) {
            if (result[i] > 1) {
                play[i] += 1;
                ++eep;
            } else {
                play[i] = 0;
            }
        }
        playRound(play, result);
    }
    for (int i = 0; i < N; ++i) {
        if (play[i] > 0) {
            return i;
        }
    }
    return 0;
}

int greaterValue(int N, int W) {
    int play[N], result[N];
    for (int i = 0; i < N; ++i) {
        play[i] = 0;
    }
    play[0] = 4;
    play[1] = 4;
    playRound(play, result);
    if (result[0] != result[1]) {
        return result[1] > result[0];
    }
    if (result[0] > 0) {
        play[0] = 2;
        play[1] = 2;
        playRound(play, result);
        if (result[0] != result[1]) {
            return result[1] > result[0];
        }
        play[0] = 1;
        play[1] = 1;
        playRound(play, result);
        if (result[0] != result[1]) {
            return result[1] > result[0];
        }
    } else {
        play[0] = 8;
        play[1] = 8;
        playRound(play, result);
        if (result[0] != result[1]) {
            return result[1] > result[0];
        }
        play[0] = 6;
        play[1] = 6;
        playRound(play, result);
        if (result[0] != result[1]) {
            return result[1] > result[0];
        }
    }
    
    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 {
        vector<bool> done(N, false);
        int playFrom = 1;
        int play[N], result[N], comp[N];
        for (int i = 0; i<N; ++i) {
            play[i] = 1;
        }
        for (int i = 0; i < N; ++i) {
            P[i] = 0;
        }
        playRound(play, result);
        bool isUpper[N];
        vector<int> upper, lower;
        for (int i = 0; i < N; ++i) {
            if (result[i] < play[i]) {
                isUpper[i] = false;
                lower.push_back(i);
            } else {
                isUpper[i] = true;
                upper.push_back(i);
            }
        }
        int lowerIndex = 1, upperIndex = N/2 + 1;
        for (int i = 0; i<N; ++i) {
            play[i] = 0;
        }
        play[upper[0]] = 1;
        for (int i = 0; i < N/2; ++i) {
            playRound(play, result);
            for (int j = 0; j < N; ++j) {
                comp[j] = play[j];
            }
            for (int j = 0; j < N; ++j) {
                if (P[j] > 0) continue;
                if (result[j] <= comp[j]) {
                    if (isUpper[j]) {
                        P[j] = upperIndex;
                        ++upperIndex;
                        if (play[j] > 0) {
                            if (playFrom >= upper.size()) break;
                            while(P[upper[playFrom]] > 0) {
                                ++playFrom;
                                if (playFrom >= upper.size()) break;
                                //cout<<P[upper[playFrom]]<<'\n';
                            }
                            ++play[upper[playFrom]];
                            ++playFrom;
                        }
                        play[j] = 0;
                    } else {
                        P[j] = lowerIndex;
                        ++lowerIndex;
                        if (playFrom >= upper.size()) break;
                        while(P[upper[playFrom]] > 0) {
                            ++playFrom;
                            if (playFrom >= upper.size()) break;
                            //cout<<P[upper[playFrom]]<<'\n';
                        }
                        ++play[upper[playFrom]];
                        ++playFrom;
                    }
                }
            }
        }
        while (lowerIndex < N/2)
        {
            cout<<lowerIndex<<'\n';
            for (int i = 0; i < N; ++i) {
                if (P[i] == 1 || P[i] == lowerIndex - 1 || (P[i] == 0 && isUpper[i])) {
                    play[i] = 0;
                } else {
                    play[i] = 1;
                }
            }
            
            playRound(play, result);
            for (int j = 0; j < N; ++j) {
                if (P[j] > 0) continue;
                if (result[j] <= comp[j]) {
                    P[j] = lowerIndex;
                    ++lowerIndex;
                    if (playFrom >= upper.size()) break;
                    while(P[upper[playFrom]] > 0) {
                        ++playFrom;
                        if (playFrom >= upper.size()) break;
                        //cout<<P[upper[playFrom]]<<'\n';
                    }
                    ++play[upper[playFrom]];
                    ++playFrom;
                }
            }
        }
        for (int i = 0; i < lower.size(); ++i) {
            if (P[lower[i]] == 0) {
                P[lower[i]] = lowerIndex;
            }
        }
        for (int i = 0; i<N; ++i) {
            play[i] = 0;
            if (i >= upperIndex) {
                play[i] = 2;
            }
        }
        playRound(play, result);
        bool isUpper1[N];
        vector<int> upper1, lower1;
        for (int i = 0; i < N; ++i) {
            if (result[i] < play[i]) {
                isUpper1[i] = false;
                lower1.push_back(i);
            } else {
                isUpper1[i] = true;
                upper1.push_back(i);
            }
        }
        for (int i = 0; i < N; ++i) {
            if (P[i] > 0) play[i] = 1;
        }
        int upperIndex1 = N - upper1.size() + 1, lowerIndex1 = upperIndex;
        playFrom = 0;
        for (int i = upperIndex; i < upperIndex + lower1.size(); ++i) {
            playRound(play, result);
            for (int j = 0; j < N; ++j) {
                comp[j] = play[j];
            }
            for (int j = 0; j < N; ++j) {
                if (P[j] > 0) continue;
                if (result[j] <= comp[j]) {
                    if (isUpper1[j]) {
                        P[j] = upperIndex1;
                        ++upperIndex1;
                        if (play[j] > 0) {
                            if (playFrom >= upper1.size()) break;
                            while(P[upper[playFrom]] > 0) {
                                ++playFrom;
                                if (playFrom >= upper1.size()) break;
                                //cout<<P[upper[playFrom]]<<'\n';
                            }
                            ++play[upper1[playFrom]];
                            ++playFrom;
                        }
                        play[j] = 0;
                    } else {
                        P[j] = lowerIndex1;
                        ++lowerIndex1;
                        if (playFrom >= upper1.size()) break;
                        while(P[upper1[playFrom]] > 0) {
                            ++playFrom;
                            if (playFrom >= upper1.size()) break;
                            //cout<<P[upper[playFrom]]<<'\n';
                        }
                        ++play[upper1[playFrom]];
                        ++playFrom;
                    }
                }
            }
        }
        while (lowerIndex1 < N - upper1.size())
        {
            for (int i = 0; i < N; ++i) {
                if (P[i] == 1 || P[i] == lowerIndex1 - 1 || (P[i] == 0 && isUpper1[i])) {
                    play[i] = 0;
                } else {
                    play[i] = 1;
                }
            }
            
            playRound(play, result);
            for (int j = 0; j < N; ++j) {
                if (P[j] > 0) continue;
                if (result[j] <= comp[j]) {
                    P[j] = lowerIndex1;
                    ++lowerIndex1;
                    if (playFrom >= upper1.size()) break;
                    while(P[upper[playFrom]] > 0) {
                        ++playFrom;
                        if (playFrom >= upper1.size()) break;
                        //cout<<P[upper[playFrom]]<<'\n';
                    }
                    ++play[upper1[playFrom]];
                    ++playFrom;
                }
            }
        }
        for (int i = 0; i < lower.size(); ++i) {
            if (P[lower[i]] == 0) {
                P[lower[i]] = lowerIndex1;
            }
        }
        int lim = N, rem = 100;
        while (lim > upperIndex1) {
            rem = 100;
            int stones = lim / (lim - upperIndex1);
            for (int i = 0; i < N; ++i) {
                play[i] = 0;
            }
            for (int i = upperIndex1; i < lim; ++i) {
                play[i] = stones;
                rem -= stones;
            }
            rem /= (N + 1) - lim;
            for (int i = lim; i < N; ++i) {
                play[i] = rem;
            }
            playRound(play, result);
            for (int i = upperIndex1; i < N; ++i) {
                if (result[i] > play[i]) {
                    P[i] = lim;
                    --lim;
                }
            }
        }
        
        for (int i = 0; i < N; ++i) {
            cout<<i;
            if (P[i] == 0) P[i] = N;
        }
        for (int i = 0; i < N; i++) {
            cout<<P[i]<<' ';
        }
        printf("\n");
    }
}

Compilation message

koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:137:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |                             if (playFrom >= upper.size()) break;
      |                                 ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:140:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |                                 if (playFrom >= upper.size()) break;
      |                                     ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:150:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |                         if (playFrom >= upper.size()) break;
      |                             ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:153:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |                             if (playFrom >= upper.size()) break;
      |                                 ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:179:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  179 |                     if (playFrom >= upper.size()) break;
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:182:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  182 |                         if (playFrom >= upper.size()) break;
      |                             ~~~~~~~~~^~~~~~~~~~~~~~~
koala.cpp:190:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  190 |         for (int i = 0; i < lower.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~
koala.cpp:218:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  218 |         for (int i = upperIndex; i < upperIndex + lower1.size(); ++i) {
      |                                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:230:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  230 |                             if (playFrom >= upper1.size()) break;
      |                                 ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:233:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  233 |                                 if (playFrom >= upper1.size()) break;
      |                                     ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:243:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  243 |                         if (playFrom >= upper1.size()) break;
      |                             ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:246:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  246 |                             if (playFrom >= upper1.size()) break;
      |                                 ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:255:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  255 |         while (lowerIndex1 < N - upper1.size())
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
koala.cpp:271:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  271 |                     if (playFrom >= upper1.size()) break;
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:274:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  274 |                         if (playFrom >= upper1.size()) break;
      |                             ~~~~~~~~~^~~~~~~~~~~~~~~~
koala.cpp:282:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  282 |         for (int i = 0; i < lower.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 21 ms 344 KB Output is partially correct
2 Partially correct 21 ms 344 KB Output is partially correct
3 Partially correct 21 ms 456 KB Output is partially correct
4 Partially correct 20 ms 344 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -