QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#847943 | #4234. Tic Tac Toe Counting | mon_de2738# | WA | 13ms | 3792kb | C++17 | 3.0kb | 2025-01-08 13:48:13 | 2025-01-08 13:48:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull=unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
//#define uniq(v) v.resize()
template<typename T, typename S>
istream& operator>>(istream& in, pair<T,S>& p){
in >> p.fi >> p.se;
return in;
}
template<typename T, typename S>
ostream& operator<<(ostream& out, pair<T,S>& p){
out << p.fi << ' ' << p.se;
return out;
}
const int maxn=300055, mx=20055;
const int mod=1e9+7, mod2=998244353;
const int inf=2e9;
const ll infl=1LL<<62;
using tpl=tuple<int,int,int>;
int n,m,k;
pii st[mx];
pii operator+(pii a, pii b){
return {a.fi+b.fi, a.se+b.se};
}
int brd[2][4][4]; // 1 x 2 o
bool chk(int x){
for(int i=1;i<=3;i++){
bool f=1;
for(int j=1;j<=3;j++) f&=(brd[0][i][j]==x);
if(f) return true;
}
for(int j=1;j<=3;j++){
bool f=1;
for(int i=1;i<=3;i++) f&=(brd[0][i][j]==x);
if(f) return true;
}
bool f=1;
for(int i=1;i<=3;i++){
f&=(brd[0][i][i]==x);
}
if(f) return true;
f=1;
for(int i=1;i<=3;i++){
f&=(brd[0][i][4-i]==x);
}
if(f) return true;
return false;
}
void mk(int x){
int xx=x;
int cnt[4]={0,};
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
brd[0][i][j]=x%3;
cnt[x%3]++;
x/=3;
}
}
x=xx;
bool f1=chk(1);
bool f2=chk(2);
if(f1&&f2 || cnt[1]-cnt[2]<0 || cnt[1]-cnt[2]>1){
st[x]={-1,-1};
return;
}
if(f1){
if(cnt[1]-cnt[2]==0){
st[x]={-1,-1};
return;
}
st[x]={1,0};
}
if(f2) {
if(cnt[1]-cnt[2]==1){
st[x]={-1,-1};
}
st[x]={0,1};
}
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
if(brd[0][i][j]==0) continue;
int r=1;
for(int k=1;k<=3*(i-1)+j-1;k++) r*=3;
int nx=x/(r*3)*r*3+x%r;
st[nx]=st[nx]+st[x];
}
}
}
string s;
int cvrt(){
int res=0;
for(int i=8;i>=0;i--){
res*=3;
if(s[i]=='X') res+=1;
else if(s[i]=='O') res+=2;
}
return res;
}
void solve(int tc){
int a=1;
for(int i=0;i<9;i++) a*=3;
while(--a) mk(a);
cin >> tc;
while(tc--){
cin >> s;
cout << st[cvrt()] << endl;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#else
fastio;
#endif
int tc=1;
// cin >> tc;
for(int i=1;i<=tc;i++) solve(i);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3792kb
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: 0
Accepted
time: 12ms
memory: 3772kb
input:
100000 ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......
output:
131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 1...
result:
ok 100000 lines
Test #3:
score: -100
Wrong Answer
time: 13ms
memory: 3776kb
input:
100000 ......... X........ O........ .X....... XX....... OX....... .O....... XO....... OO....... ..X...... X.X...... O.X...... .XX...... XXX...... OXX...... .OX...... XOX...... OOX...... ..O...... X.O...... O.O...... .XO...... XXO...... OXO...... .OO...... XOO...... OOO...... ...X..... X..X..... O.....
output:
131184 77904 14652 7896 -1 -1 14232 10176 -1 -1 1798 1276 -1 -1 2048 756 -1 -1 14652 7896 -1 -1 1832 1132 -1 -1 -1 -1 220 248 2048 756 268 144 -1 -1 -1 -1 1832 1132 -1 -1 1798 1276 220 248 -1 -1 -1 -1 -1 -1 -1 -1 14232 10176 -1 -1 1798 1276 -1 -1 -1 -1 264 188 1868 1080 239 126 -1 -1 -1 -1 -1 -1 312...
result:
wrong answer 1851st lines differ - expected: '-1 -1', found: '0 1'