QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#224845#7179. Fischer's Chess Guessing Gamesofija6TL 88ms47936kbC++172.8kb2023-10-23 15:47:402023-10-23 15:47:40

Judging History

你现在查看的是最新测评结果

  • [2023-10-23 15:47:40]
  • 评测
  • 测评结果:TL
  • 用时:88ms
  • 内存:47936kb
  • [2023-10-23 15:47:40]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
using namespace std;
vector<string> v;
vector<pair<string,ll> > S;
void Create(string s,ll b,ll p,ll k,ll n,ll q,ll r)
{
    if ((ll)s.size()==8)
    {
        v.push_back(s);
        return;
    }
    string c=s;
    if (!b || (b==1 && p!=s.size()%2))
    {
        c+='B';
        Create(c,b+1,s.size()%2,k,n,q,r);
        c=s;
    }
    if (!k && r==1)
    {
        c+='K';
        Create(c,b,p,k+1,n,q,r);
        c=s;
    }
    if (n!=2)
    {
        c+='N';
        Create(c,b,p,k,n+1,q,r);
        c=s;
    }
    if (!q)
    {
        c+='Q';
        Create(c,b,p,k,n,q+1,r);
        c=s;
    }
    if (!r || (r==1 && k==1))
    {
        c+='R';
        Create(c,b,p,k,n,q,r+1);
    }
    return;
}
map<string,vector<string> > c[10];
bool Check(string x)
{
    for (auto i : S)
    {
        ll diff=0;
        for (ll j=0;j<8;j++)
            diff+=(i.first[j]!=x[j]);
        if (diff!=i.second)
            return false;
    }
    return true;
}
set<string> cor;
map<string,ll> cnt[10];
string Get_Min()
{
    ll maxx=INT_MAX;
    string ans;
    set<string> ss;
    for (auto i : S)
    {
        for (auto j : cor)
        {
            ll d=0;
            for (ll p=0;p<8;p++)
                d+=(i.first[p]!=j[p]);
            if (d==i.second)
                continue;
            ss.insert(j);
        }
    }
    for (auto i : ss)
        cor.erase(i);
    for (auto i : ss)
    {
        for (auto l : cor)
        {
            ll p=0;
            for (ll j=0;j<8;j++)
                p+=(l[j]!=i[j]);
            cnt[p][l]--;
        }
    }
    for (auto i : cor)
    {
        ll cur=0;
        for (ll j=0;j<9;j++)
            cur=max(cur,cnt[j][i]);
        if (cur<maxx && Check(i))
        {
            maxx=cur;
            ans=i;
        }
    }
    return ans;
}
int main()
{
    string s="";
    Create(s,0,0,0,0,0,0);
    for (auto i : v)
    {
        for (auto j : v)
        {
            ll cnt=0;
            for (ll p=0;p<8;p++)
                cnt+=(i[p]!=j[p]);
            c[cnt][i].push_back(j);
        }
    }
    string x="";
    ll n,a;
    while (true)
    {
        if (x=="")
            cin >> x;
        cin >> n;
        S.clear();
        for (auto i : v)
        {
            for (ll j=0;j<9;j++)
                cnt[j][i]=c[j][i].size();
            cor.insert(i);
        }
        s=Get_Min();
        while (true)
        {
            cout << s << "\n";
            cin >> a;
            a=8-a;
            if (!a)
            {
                cin >> x;
                if (x=="END")
                    return 0;
                break;
            }
            S.push_back({s,a});
            s=Get_Min();
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 88ms
memory: 47936kb

input:

GAME 1
1
2
2
1
2
8
END

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 6 (1 test case)

Test #2:

score: -100
Time Limit Exceeded

input:

GAME 1
1
2
2
1
2
8
GAME 2
2
1
0
1
2
8
GAME 3
1
2
2
0
3
8
GAME 4
1
2
1
1
3
8
GAME 5
2
2
0
3
0
8
GAME 6
2
1
2
1
3
8
GAME 7
0
2
3
4
3
8
GAME 8
1
2
1
0
3
8
GAME 9
0
3
1
2
8
GAME 10
0
3
3
3
8
GAME 11
0
5
3
2
8
GAME 12
1
1
1
4
8
GAME 13
1
2
2
3
4
8
GAME 14
0
4
3
4
8
GAME 15
1
2
1
0
1
8
GAME 16
1
1
3
2
2
8...

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NBNRBKRQ
BQNBRNKR
RKRBBNQN
NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
RBKNBQNR
RKRBBNNQ
NRBBNKQR
BNRKQBNR
RNBQKRNB
BBNQRNKR
QBRKNRBN
RKRBQNBN
NRBBNKQR
RBBNKQNR
NBNQBRKR
BRKBRQNN
QRBKRNNB
RKRBNQBN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NRK...

result: