이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "combo.h"
#include<bits/stdc++.h>
#define fs first
#define sc second
#define pb push_back
#define all(x) x.begin()x.end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pi;
char c[5]={'A','B','X','Y'};
vi ava;
vector<pi> srt;
std::string guess_sequence(int N) {
srand(time(0));
int start=3;
for(int i=0;i<3;i++)
{
string s;
s+=c[i];
int val=press(s);
if(val)
{
start=i;
break;
}
}
string cur;
cur+=c[start];
for(int i=0;i<4;i++)
if(i!=start)
ava.pb(i);
srt.pb({ava[0],ava[1]});
srt.pb({ava[1],ava[2]});
srt.pb({ava[0],ava[2]});
while(cur.size()<N-1)
{
// cout<<"cur "<<cur<<endl;
int pos=abs(rand()%3);
// pos=0;
pi k=srt[pos];
int other;
for(int x:ava)
if(x!=k.fs and x!=k.sc)
other=x;
string ask;
///////////////////
ask+=cur;
ask+=c[k.fs];
ask+=c[k.fs];
///////////////////
ask+=cur;
ask+=c[k.sc];
ask+=c[k.sc];
///////////////////
ask+=cur;
ask+=c[k.fs];
ask+=c[k.sc];
///////////////////
ask+=cur;
ask+=c[k.sc];
ask+=c[k.fs];
///////////////////
int val=press(ask)-cur.size();
// cout<<ask<<' '<<val<<endl;
if(!val)
{
cur+=c[other];
continue;
}
if(val==1)
{
string nw;
nw=cur+c[k.fs];
if(press(nw)-cur.size())
cur+=c[k.fs];
else
cur+=c[k.sc];
cur+=c[other];
continue;
}
if(val==2)
{
ask="";
///////////////////
ask+=cur;
ask+=c[k.fs];
ask+=c[k.fs];
///////////////////
ask+=cur;
ask+=c[k.sc];
ask+=c[k.sc];
///////////////////
if(press(ask)-cur.size()>=2)
{
ask="";
///////////////////
ask+=cur;
ask+=c[k.fs];
ask+=c[k.fs];
///////////////////
if(press(ask)-cur.size()>=2)
{
cur+=c[k.fs];
cur+=c[k.fs];
}
else
{
cur+=c[k.sc];
cur+=c[k.sc];
}
}
else
{
ask="";
///////////////////
ask+=cur;
ask+=c[k.fs];
ask+=c[k.sc];
///////////////////
if(press(ask)-cur.size()>=2)
{
cur+=c[k.fs];
cur+=c[k.sc];
}
else
{
cur+=c[k.sc];
cur+=c[k.fs];
}
}
}
}
if(cur.size()<N)
{
string ask;
ask=cur+c[ava[0]];
if(press(ask)-cur.size()>0)
cur+=c[ava[0]];
ask=cur+c[ava[1]];
if(press(ask)-cur.size()>0)
cur+=c[ava[1]];
}
if(cur.size()<N)
cur+=c[ava[2]];
// cout<<cur<<endl;
return cur;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
45 | while(cur.size()<N-1)
| ~~~~~~~~~~^~~~
combo.cpp:163:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
163 | if(cur.size()<N)
| ~~~~~~~~~~^~
combo.cpp:175:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
175 | if(cur.size()<N)
| ~~~~~~~~~~^~
combo.cpp:86:25: warning: 'other' may be used uninitialized in this function [-Wmaybe-uninitialized]
86 | cur+=c[other];
| ~~~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |