QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111691 | #5509. Kooky Tic-Tac-Toe | xaphoenix# | AC ✓ | 38ms | 3480kb | C++17 | 3.7kb | 2023-06-07 21:50:52 | 2023-06-07 21:50:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC ch[k][0]
#define RC ch[k][1]
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 100010;
const int M = 610000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const double eps = 1e-9;
int n, k, a[7][7], c[3];
vector<PII> p[3], ans;
bool yes = false;
int xi, xj;
vector<PII> dir;
bool check() {
repn(i, 1, n) {
repn(j, 1, n) {
if (a[i][j] == 0) continue;
repn(d, 0, 3) {
PII cur = mp(i, j);
int tp = a[i][j];
bool can = true;
rep(t, 1, k) {
cur.fi += dir[d].fi;
cur.se += dir[d].se;
if (cur.fi < 1 || cur.fi > n || cur.se < 1 || cur.se > n) {
can = false;
break;
}
if (a[cur.fi][cur.se] != tp) can = false;
}
if (can) {
return true;
}
}
}
}
return false;
}
void solve() {
cin >> n >> k;
yes = false;
ans.clear();
c[1] = 0; c[2] = 0;
p[1].clear(); p[2].clear();
string s;
repn(i, 1, n) {
cin >> s;
repn(j, 1, n) {
if (s[j - 1] == '.') a[i][j] = 0;
else if (s[j - 1] == 'x') {
a[i][j] = 1; c[1] ++;
p[1].pb(mp(i, j));
}
else {
a[i][j] = 2; c[2] ++;
p[2].pb(mp(i, j));
}
}
}
if (!check() && c[1] + c[2] == n * n) {
bool can = false;
if (c[1] == c[2]) {
can = true;
int tot = c[1], p1 = 0, p2 = 0;
repn(i, 1, tot) {
ans.pb(p[1][p1]); ans.pb(p[2][p2]);
p1 ++; p2 ++;
}
}
else if (c[1] + 1 == c[2]) {
can = true;
int tot = c[1], p1 = 0, p2 = 0;
repn(i, 1, tot) {
ans.pb(p[2][p2]); ans.pb(p[1][p1]);
p1 ++; p2 ++;
}
ans.pb(p[2][p2]);
}
else if (c[1] == c[2] + 1) {
can = true;
int tot = c[2], p1 = 0, p2 = 0;
repn(i, 1, tot) {
ans.pb(p[1][p1]); ans.pb(p[2][p2]);
p1 ++; p2 ++;
}
ans.pb(p[1][p1]);
}
if (! can) cout << "NIE\n";
else{
cout << "TAK\n";
for (auto x : ans) {
cout << x.fi << " " << x.se << "\n";
}
}
return;
}
if (!check()) {
cout << "NIE\n"; return;
}
repn(i, 1, n) {
repn(j, 1, n) {
int cur = a[i][j];
if (!cur) continue;
a[i][j] = 0;
bool can = check();
a[i][j] = cur;
if (!can) {
yes = true; xi = i; xj = j;
break;
}
}
if (yes) break;
}
if (!yes) {
cout << "NIE\n";
return;
}
int tp = a[xi][xj];
c[tp] --;
if (c[tp] == c[3 - tp]) {
int tot = c[tp], p1 = 0, p2 = 0;
repn(i, 1, tot) {
if (p[tp][p1].fi == xi && p[tp][p1].se == xj) p1 ++;
ans.pb(p[tp][p1]); ans.pb(p[3 - tp][p2]);
p1 ++; p2 ++;
}
ans.pb(mp(xi, xj));
cout << "TAK\n";
for (auto x : ans) {
cout << x.fi << " " << x.se << "\n";
}
}
else if (c[tp] + 1 == c[3 - tp]) {
int tot = c[tp], p1 = 0, p2 = 0;
repn(i, 1, tot) {
if (p[tp][p1].fi == xi && p[tp][p1].se == xj) p1 ++;
ans.pb(p[3 - tp][p2]); ans.pb(p[tp][p1]);
p1 ++; p2 ++;
}
ans.pb(p[3 - tp][p2]);
ans.pb(mp(xi, xj));
cout << "TAK\n";
for (auto x : ans) {
cout << x.fi << " " << x.se << "\n";
}
}
else cout << "NIE\n";
}
int main()
{
IO;
dir.pb(mp(1, 0)); dir.pb(mp(0, 1));
dir.pb(mp(1, 1)); dir.pb(mp(-1, 1));
int T;
cin >> T;
repn(i, 1, T) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3468kb
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 1 1 1 3 2 2 3 1 2 3 3 3 2 1 TAK 1 1 3 3 1 2 4 2 1 4 2 4 TAK 1 2 1 1 1 3 2 2 2 1 2 3 3 2 3 1 3 3 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: 0
Accepted
time: 15ms
memory: 3400kb
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 1 1 1 3 2 2 3 1 2 3 3 3 2 1 TAK 1 2 1 1 1 3 2 2 2 1 2 3 3 2 3 1 3 3 NIE NIE NIE NIE NIE TAK 2 2 1 2 3 1 1 3 3 2 1 1 NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK 1 2 1 1 1 3 1 4 2 3 2 2 2 4 4 2 3 1 4 3 3 2 4 1 NIE NIE NIE NIE NIE TAK 2 1 1 1 2 3 1 3 2 4 1 4 3 1 2 2 3 3 3 2 ...
result:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 38ms
memory: 3480kb
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 1 6 1 1 2 2 1 3 2 4 1 4 3 1 2 1 3 2 2 6 3 3 4 4 3 6 5 3 4 1 5 4 4 5 5 5 5 6 6 4 6 1 6 5 6 3 3 4 NIE TAK 1 3 1 1 1 5 2 1 2 6 2 2 3 1 2 4 3 2 3 4 4 2 3 5 4 4 5 1 4 5 5 2 6 2 5 4 6 3 6 4 5 3 NIE TAK 1 1 1 2 1 4 1 3 2 3 1 5 2 4 1 6 3 1 2 1 3 2 2 2 3 5 2 5 3 6 2 6 4 2 3 3 4 5 3 4 4 6 4 1 5 2 4 3 5 4 ...
result:
ok correct (10000 test cases)