QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#474558 | #5509. Kooky Tic-Tac-Toe | piratZnachor# | AC ✓ | 43ms | 3624kb | C++14 | 5.7kb | 2024-07-12 20:11:57 | 2024-07-12 20:11:57 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define INF 1000000000
#define INFl 1000000000000000000
#define all(x) x.begin(), x.end()
#define sajz(x) (int)x.size()
#define pb push_back
#define se second
#define fi first
#define yes puts("YES")
#define no puts("NO")
#define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));}
using namespace std;
//using namespace __gnu_pbds;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef multiset<int> msi;
typedef long double ld;
//typedef cc_hash_table<int, int, hash<int>> ht;
const int N = 6;
int a[N][N];
int ox[4] = {-1, -1, 0, 1};
int oy[4] = {0, 1, 1, 1};
bool in(int x, int y, int n) {
return x >= 0 && x < n && y >= 0 && y < n;
}
bool winning(int player, int n, int k) {
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
for (int d = 0; d < 4; d ++) {
int cnt = 0, x = i, y = j;
while (in(x, y, n) && a[x][y] == player) {
cnt ++;
x += ox[d];
y += oy[d];
}
if (cnt >= k) return true;
}
}
}
return false;
}
int Count(int player, int n) {
int cnt = 0;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
if (a[i][j] == player) cnt ++;
}
}
return cnt;
}
void test_case() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
char z; cin >> z;
if (z == 'o') a[i][j] = 0;
else if (z == 'x') a[i][j] = 1;
else a[i][j] = 2;
}
}
vector<vector<pii>> pos(2);
for (int player = 0; player < 2; player ++) {
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
if (a[i][j] == player) pos[player].pb({i, j});
}
}
}
int c0 = Count(0, n), c1 = Count(1, n);
if (abs(c0 - c1) > 1) {
cout << "NIE\n";
return;
}
int blank = n * n - c0 - c1;
bool w0 = winning(0, n, k), w1 = winning(1, n, k);
if (w0 && w1) {
cout << "NIE\n";
return;
}
if ((w0 && c0 < c1) || (w1 && c1 < c0)) {
cout << "NIE\n";
return;
}
if (w0 || w1) {
pii special = {-1, -1};
for (int player = 0; player < 2; player ++) {
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
if (a[i][j] == player && winning(player, n, k)) {
a[i][j] = 2;
bool w = winning(player, n, k);
a[i][j] = player;
if (!w) {
special = {i, j};
break;
}
}
}
}
}
//cout << special.first << ' ' << special.second << '\n';
if (special.first == -1) {
cout << "NIE\n";
return;
}
cout << "TAK\n";
vi vec = {0, 1};
if (c1 > c0 || (c1 == c0 && a[special.first][special.second] == 0)) swap(vec[0], vec[1]);
while (pos[vec[0]].size() > 0) {
if (make_pair(pos[vec[0]].back().first, pos[vec[0]].back().second) == special) {
pos[vec[0]].pop_back();
continue;
}
//cout << vec[0] << ' ';
cout << pos[vec[0]].back().first+1 << ' ' << pos[vec[0]].back().second+1 << '\n';
pos[vec[0]].pop_back();
swap(vec[0], vec[1]);
}
cout << special.first+1 << ' ' << special.second+1 << '\n';
}
else {
if (blank) {
cout << "NIE\n";
return;
}
cout << "TAK\n";
vi vec = {0, 1};
if (c1 > c0) swap(vec[0], vec[1]);
while (pos[vec[0]].size() > 0) {
cout << pos[vec[0]].back().first+1 << ' ' << pos[vec[0]].back().second+1 << '\n';
pos[vec[0]].pop_back();
swap(vec[0], vec[1]);
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int z;
cin >> z;
while (z--) {
test_case();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
7 3 3 x.o xxx o.o 4 3 xx.x ...o ..o. .o.. 3 3 xoo oxx xoo 3 2 xoo oxx xoo 3 3 xox .o. xox 3 2 xo. ..x xo. 3 3 x.. .x. ..x
output:
TAK 2 3 3 3 2 2 3 1 1 1 1 3 2 1 TAK 1 4 3 3 1 2 2 4 1 1 4 2 TAK 3 3 3 1 3 2 2 3 2 1 2 2 1 3 1 1 1 2 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: 0
Accepted
time: 10ms
memory: 3624kb
input:
10000 3 3 x.o xxx o.o 3 3 xoo oxx xoo 3 2 xoo oxx xoo 3 3 xox .o. xox 3 2 xo. ..x xo. 3 2 oox .xo o.x 5 5 xxx.. xxo.x xoo.. xxxox .oooo 3 3 xxx .o. oo. 3 2 x.o xo. ..o 3 2 ..x xxo .o. 3 3 xxo o.. oxo 3 2 oox ..x ... 3 3 xxo ... .ox 3 3 .xo ... oox 3 3 .x. xo. o.o 3 2 o.. xxo .ox 3 2 x.x xoo x.o 3 2 ...
output:
TAK 2 3 3 3 2 2 3 1 1 1 1 3 2 1 TAK 3 3 3 1 3 2 2 3 2 1 2 2 1 3 1 1 1 2 NIE NIE NIE NIE NIE TAK 3 2 1 3 3 1 1 2 2 2 1 1 NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK 3 2 4 3 3 1 4 2 2 4 2 2 2 3 1 4 1 3 1 1 1 2 4 1 NIE NIE NIE NIE NIE TAK 4 4 4 3 4 1 4 2 3 4 3 2 3 3 2 2 3 1 1 4 ...
result:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 43ms
memory: 3604kb
input:
10000 6 4 x.xx.o xo.o.x ooox.o o..xo. ..xxxo o.oxx. 6 5 oooxxx oxoxxo xoooxo xoxxxx xooxox xoxxxx 6 3 o.x.x. oo.o.x xx.oo. .x.xx. ooxo.. .xxo.. 6 6 xoo..o o.xx.x oooooo xx.x.. o..xx. ...xxx 6 5 xooxoo ooxxoo xxooxx oxooxx oxoxxx xxoxoo 6 5 xoxxxo ooooxo ooxoxx oxxoox xxxxox ooooxo 6 5 o....o .ox.oo ...
output:
TAK 6 3 6 5 6 1 5 5 5 6 5 4 4 5 5 3 4 1 4 4 3 6 3 4 3 3 2 6 3 2 2 1 3 1 1 4 2 4 1 3 2 2 1 1 1 6 6 4 NIE TAK 6 3 6 4 6 2 5 4 4 5 5 2 4 4 5 1 4 2 3 5 3 2 3 4 3 1 2 4 2 6 2 2 1 5 2 1 1 3 1 1 5 3 NIE TAK 6 6 6 4 6 5 6 2 6 3 6 1 5 3 5 6 5 1 5 5 4 4 5 4 4 3 5 2 4 1 4 6 3 4 4 5 3 3 4 2 2 6 3 6 2 5 3 5 2 2 ...
result:
ok correct (10000 test cases)