이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "combo.h"
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
using namespace std;
string guess_sequence(int N)
{
vector<char> buttons = {'A', 'B', 'X', 'Y'};
string S;
for (int i = 0; i < 3; i++)
{
string p = S + buttons[i];
if (press(p) == 1)
{
S = p;
buttons.erase(find(ALL(buttons), buttons[i]));
break;
}
}
if (S.size() == 0)
S += 'Y';
vector<string> all = {S};
vector<int> isKnown(5 * N); // 0: not known, 1: = button[0], -1: !button[1]
while (S.size() < N)
{
// int newTotal = all.size() * 3;
// int halfTotal = (newTotal + 1) / 2;
// int newSize = all[0].size() + 1;
auto oldAll(all);
while (all[0].size() * (all.size() + 1) / 2 <= 4 * N)
{
oldAll = vector<string>(all);
// cerr << "newTotal: " << newTotal << endl;
// cerr << "halfTotal: " << halfTotal << endl;
// cerr << "newSize: " << newSize << endl;
if (all[0].size() > N)
break;
// cerr << halfTotal * newSize << " < " << 4 * N << endl;
int s = all.size();
for (int i = 0; i < s; i++)
{
if (isKnown[all[0].size()] == 0)
{
all.push_back(all[i] + buttons[1]);
all.push_back(all[i] + buttons[2]);
all[i] += buttons[0];
}
else if (isKnown[all[0].size()] == 1)
{
all[i] += buttons[0];
}
else
{
all.push_back(all[i] + buttons[2]);
all[i] += buttons[1];
}
}
if (all[0].size() > N)
break;
// newTotal = all.size() * 3;
// halfTotal = (newTotal + 1) / 2;
// newSize = all[0].size() + 1;
}
all = vector<string>(oldAll);
int k = (all.size() + 1) / 2;
string p;
p.reserve(4 * N);
vector<string> guesses(all.begin(), all.begin() + k);
int l = k * all[0].size();
// resterende ruimte opvullen met random junk
int index = 0;
while (l < 4 * N)
{
string add{buttons[0]};
guesses[index] += add;
l++;
index++;
index %= k;
}
for (int i = 0; i < k; i++)
{
if (i >= guesses.size())
{
cout << "this shouldn't happen!";
break;
}
p += guesses[i];
}
int res = press(p);
if (res >= all[0].size())
{
all.erase(all.begin() + k, all.end());
if (res > all[0].size())
{
for (int i = all[0].size(); i < res; i++)
{
isKnown[i] = 1;
}
}
else
{
isKnown[all[0].size()] = -1;
}
}
else
{
if (res > S.size())
{
string common = guesses[0];
for (int i = 1; i < guesses.size(); i++)
{
for (int ix = 0; ix < std::min(common.size(), guesses[i].size()); ix++)
{
if (common[ix] != guesses[i][ix])
{
common.erase(common.begin() + ix, common.end());
break;
}
}
}
all.erase(all.begin(), all.begin() + k);
for (int i = 0; i < all.size(); i++)
{
for (int ix = 0; ix < std::min(common.size(), all[i].size()); ix++)
{
if (common[ix] != all[i][ix])
{
all.erase(all.begin() + i);
i--;
break;
}
}
}
}
else
all.erase(all.begin(), all.begin() + k);
}
S = all[0];
for (int i = 1; i < all.size(); i++)
{
for (int ix = 0; ix < std::min(S.size(), all[i].size()); ix++)
{
if (S[ix] != all[i][ix])
{
S.erase(S.begin() + ix, S.end());
break;
}
}
}
// cerr << "Done?!" << endl;
}
return S;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:24:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | while (S.size() < N)
| ~~~~~~~~~^~~
combo.cpp:30:53: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | while (all[0].size() * (all.size() + 1) / 2 <= 4 * N)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
combo.cpp:36:31: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if (all[0].size() > N)
| ~~~~~~~~~~~~~~^~~
combo.cpp:58:31: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | if (all[0].size() > N)
| ~~~~~~~~~~~~~~^~~
combo.cpp:83:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if (i >= guesses.size())
| ~~^~~~~~~~~~~~~~~~~
combo.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | if (res >= all[0].size())
| ~~~~^~~~~~~~~~~~~~~~
combo.cpp:94:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | if (res > all[0].size())
| ~~~~^~~~~~~~~~~~~~~
combo.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | if (res > S.size())
| ~~~~^~~~~~~~~~
combo.cpp:111:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for (int i = 1; i < guesses.size(); i++)
| ~~^~~~~~~~~~~~~~~~
combo.cpp:113:41: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
113 | for (int ix = 0; ix < std::min(common.size(), guesses[i].size()); ix++)
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
combo.cpp:123:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for (int i = 0; i < all.size(); i++)
| ~~^~~~~~~~~~~~
combo.cpp:125:41: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
125 | for (int ix = 0; ix < std::min(common.size(), all[i].size()); ix++)
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
combo.cpp:140:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for (int i = 1; i < all.size(); i++)
| ~~^~~~~~~~~~~~
combo.cpp:142:33: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
142 | for (int ix = 0; ix < std::min(S.size(), all[i].size()); ix++)
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |