QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626279 | #4234. Tic Tac Toe Counting | nickbelov# | WA | 5ms | 3900kb | C++20 | 3.9kb | 2024-10-10 02:02:30 | 2024-10-10 02:02:30 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
ostream_iterator<T> oit(const string &s = " "){ return ostream_iterator<T>(cout,s.c_str()); }
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
#define A(a) begin(a),end(a)
inline auto len = ranges::ssize;
struct chash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
typedef vector<ll> vll;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using B = array<array<char,3>,3>;
string BS(B b){
string s; for(auto &v : b) for(char c : v) s+=c;
return s;
}
map<B,pii> dp;
array<char,2> ca = {'X','O'};
auto find_lines = [](char w, B &g){
vector<set<pii>> lines;
for(int i : rep(3)){ //horizontal
set<pii> ln; bool good = true;
for(int j : rep(3)){
ln.insert({i,j});
good and_eq g[i][j]==w;
}
if(good) lines.push_back(ln);
}
for(int j : rep(3)){ //vertical
set<pii> ln; bool good = true;
for(int i : rep(3)){
ln.insert({i,j});
good and_eq g[i][j]==w;
}
if(good) lines.push_back(ln);
}
{ //diag1
set<pii> ln; bool good = true;
for(int i : rep(3))
good and_eq g[i][i]==w,ln.insert({i,i});
if(good) lines.push_back(ln);
}
{ //diag2
set<pii> ln; bool good = true;
for(int i : rep(3))
good and_eq g[i][3-i-1]==w,ln.insert({i,3-i-1});
if(good) lines.push_back(ln);
}
return lines;
};
function<pii(B,int turn)> rec = [](B state,int turn){
if(dp.contains(state)) return dp[state];
auto &here = dp[state]; here = {0,0};
auto res = find_lines(ca[turn^1],state);
if(not res.empty()){
if(turn==0) here.second++; //if its player 1s turn now, player 2 must have just won
else here.first++;
return here;
}
for(int i : rep(3)){
for(int j : rep(3)){
if(state[i][j]!='.') continue;
B nstate = state; nstate[i][j] = ca[turn];
auto [add1,add2] = rec(nstate,turn^1);
here.first+=add1,here.second+=add2;
}
}
return here;
};
void run()
{
B g {};
for(auto &v : g) for(auto &c : v) cin >> c;
int xc=0,oc=0; //wrong number of guys
{
for(auto &v : g) for(auto c : v)
xc+=c=='X',oc+=c=='O';
}
B blank{}; for(int i :rep (3)) for(int j : rep(3)) blank[i][j]='.';
rec(blank,0);
if(not dp.contains(g))
return void(cout << "-1\n");
auto ans = dp[g];
cout << ans.first << " " << ans.second << '\n';
}
int main()
{
//KING OF THE WORLD...... U.W.T.B
cin.tie(0);
ios_base::sync_with_stdio(false);
int t; cin>>t; while(t--) run();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 3900kb
input:
4 XX..O.... X...OX... OOOX.X.X. OOOXXX...
output:
191 194 232 200 0 1 -1
result:
wrong answer 4th lines differ - expected: '-1 -1', found: '-1'