QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#51217 | #4234. Tic Tac Toe Counting | Amalgadon# | WA | 379ms | 4056kb | C++17 | 1.1kb | 2022-10-01 14:30:31 | 2022-10-01 14:30:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
map<string,pair<int,int>> mp;
string s;
char check(string s)
{
if(s[0]==s[1]&&s[1]==s[2]) return s[0];
if(s[3]==s[4]&&s[4]==s[5]) return s[3];
if(s[6]==s[7]&&s[7]==s[8]) return s[6];
if(s[0]==s[3]&&s[3]==s[6]) return s[0];
if(s[1]==s[4]&&s[4]==s[7]) return s[1];
if(s[2]==s[5]&&s[5]==s[8]) return s[2];
if(s[0]==s[4]&&s[4]==s[8]) return s[0];
if(s[2]==s[4]&&s[4]==s[6]) return s[2];
return '.';
}
pair<int,int> dfs(string s, int now)
{
if(mp.count(s)) return mp[s];
char c=check(s);
if(c=='X') return mp[s]=make_pair(1,0);
if(c=='O') return mp[s]=make_pair(0,1);
pair<int,int> res(0,0);
for(int i=0;i<9;++i) if(s[i]=='.')
{
if(now) s[i]='X'; else s[i]='O';
pair<int,int> tmp=dfs(s,now^1);
res.first+=tmp.first, res.second+=tmp.second;
s[i]='.';
}
return mp[s]=res;
}
int main()
{
dfs(".........",1);
int T; cin>>T;
while(T--)
{
cin>>s;
if(!mp.count(s)) cout<<"-1 -1\n";
else cout<<mp[s].first<<" "<<mp[s].second<<"\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 3980kb
input:
4 XX..O.... X...OX... OOOX.X.X. OOOXXX...
output:
191 194 232 200 0 1 -1 -1
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 379ms
memory: 4056kb
input:
100000 ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......
output:
131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 131832 78192 1...
result:
wrong answer 1st lines differ - expected: '131184 77904', found: '131832 78192'