제출 #229950

#제출 시각아이디문제언어결과실행 시간메모리
229950kartel콤보 (IOI18_combo)C++14
0 / 100
24 ms352 KiB
#include <bits/stdc++.h>
//#include "grader.cpp"
#include "combo.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

string guess_sequence(int n)
    {
        string s = "";
        int len;
        int I, x, X, i, k, p, j, L, l, mk[2][5] {0};
        srand(time(0));
        char c[4] = {'A', 'B', 'X', 'Y'};

        random_shuffle(c, c + 4);

        for (i = 0; i < 4; i++)
        {
            s = "";
            s += c[i];
            p = press(s);
            if (p == 1) break;
        }

        I = i;

        len = 2;
        x = 0;
        while (len <= n)
        {
            x ^= 1;
            for (i = 0; i < 4; i++) mk[x][i] = 0;
            j = rand() % 3 + 1;
            l = 0;
            while (l < 4 && j > 0)
            {
                if (l == I) {l++;continue;}
                if (!mk[x][l]) j--;
                if (j == 0) break;
                l++;
            }

//            for (i = 0; i < 4; i++) cerr << mk[x][i] << " ";
//            cerr << el;
//            cerr << len << " " << c[l] << " " << s << el;

            s += c[l];
            mk[x][l] = 1;

            p = press(s);

            if (p == s.size()) {len++;continue;}
            if (p == sz(s) - 2)
            {
                int y = x ^ 1;
                i = 0;
                while (i < 4)
                {
                    if (i == I) {i++;continue;}
                    if (!mk[y][i]) break;
                    i++;
                }
                s[sz(s) - 2] = c[i];
                 len++;
                continue;
            }

            s.erase(sz(s) - 1);


            j = rand() % 2 + 1;
            l = 0;
            while (l < 4 && j > 0)
            {
                if (I == l) {l++;continue;}
                if (!mk[x][l]) j--;
                if (j == 0) break;
                l++;
            }

            s += c[l];
            mk[x][l] = 1;

            len++;
        }

        if (len > 1)
        {
            p = press(s);

            if (p != sz(s))
            {
                int y = x;
                i = 0;
                while (i < 4)
                {
                    if (i == I) {i++;continue;}
                    if (!mk[y][i]) break;
                    i++;
                }
                s[sz(s) - 1] = c[i];
            }
        }
        cerr << s << el;
        return s;
    }

//int main()
//{
//    srand(time(0));
//    ios_base::sync_with_stdio(0);
//    iostream::sync_with_stdio(0);
//    ios::sync_with_stdio(0);
//    cin.tie(NULL);
//    cout.tie(NULL);
//
////    in("input.txt");
////    out("output.txt");
//
//
//}

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             if (p == s.size()) {len++;continue;}
      |                 ~~^~~~~~~~~~~
combo.cpp:30:19: warning: unused variable 'X' [-Wunused-variable]
   30 |         int I, x, X, i, k, p, j, L, l, mk[2][5] {0};
      |                   ^
combo.cpp:30:25: warning: unused variable 'k' [-Wunused-variable]
   30 |         int I, x, X, i, k, p, j, L, l, mk[2][5] {0};
      |                         ^
combo.cpp:30:34: warning: unused variable 'L' [-Wunused-variable]
   30 |         int I, x, X, i, k, p, j, L, l, mk[2][5] {0};
      |                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...