제출 #1192176

#제출 시각아이디문제언어결과실행 시간메모리
1192176ykilra콤보 (IOI18_combo)C++20
100 / 100
8 ms540 KiB
#include <string>
using namespace std;

int press(std::string p);

string guess_sequence(int N) {
    string p = "";
    int coin = 0;
    int ind = 0;
    int ind1 = 0, ind2 = 0;
    string l[4] = {"A", "B", "X", "Y"};
    string temp = "AB";
    int tc = press(temp);
    if (tc > coin) {
        temp = "A";
        int c = press(temp);
        if (c > coin) {
            p = "A";
            ind = 0; coin++;
        }
        else {
            p = "B";
            ind = 1; coin++;
        }
    }
    else {
        temp = "X";
        int c = press(temp);
        if (c > coin) {
            p = "X";
            ind = 2; coin++;
        }
        else {
            p = "Y";
            ind = 3; coin++;
        }
    }
    if (N == 1) return p;
    else if (N == 2) {
        int g = 0;
        for (int j = 0; j < 4; j++) {
            if (g == 2) {
                if (j != ind) {
                    p = p + l[j];
                    coin++;
                    break;
                }
                else {
                    p = p + l[j+1];
                    coin++;
                    break;
                }
            }
            if (j != ind){
                string temp = p + l[j];
                int tc = press(temp);
                if (tc > coin) {
                    p = temp;
                    coin = tc;
                    break;
                }
                g++;
            }
        }
        return p;
    }
    else {
        for (int i = 2; i < N; i++) {
            string temp = "";
            if (ind == 0) {
                temp += p + l[1];
                ind1 = 1;
            }
            else {
                temp += p + l[0];
                ind1 = 0;
            }
            if (ind == 2) {
                for (int j = 0; j < 4; j++) {
                    if (j != ind) temp += p + l[3] + l[j];
                    ind2 = 3;
                }
            }
            else {
                for (int j = 0; j < 4; j++) {
                    if (j != ind) temp += p + l[2] + l[j];
                    ind2 = 2;
                }
            }
            int tc = press(temp);
            if (tc == coin + 2) {
                p = p + l[ind2];
                coin++;
            }
            else if (tc == coin + 1) {
                p = p + l[ind1];
                coin++;
            }
            else if (tc == coin) {
                for (int j = 0; j < 4; j++) {
                    if (j != ind && j != ind1 && j != ind2) {
                        p = p + l[j];
                        break;
                    }
                }
                coin++;
            }
        }
        int g = 0;
        for (int j = 0; j < 4; j++) {
            if (g == 2) {
                if (j != ind) {
                    p = p + l[j];
                    coin++;
                    break;
                }
                else {
                    p = p + l[j+1];
                    coin++;
                    break;
                }
            }
            if (j != ind){
                string temp = p + l[j];
                int tc = press(temp);
                if (tc > coin) {
                    p = temp;
                    coin = tc;
                    break;
                }
                g++;
            }
        }
        return p;
    }
    return p;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...