QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#221825#5509. Kooky Tic-Tac-Toeucup-team859#WA 0ms3580kbC++233.7kb2023-10-21 14:46:142023-10-21 14:46:14

Judging History

你现在查看的是最新测评结果

  • [2023-10-21 14:46:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3580kb
  • [2023-10-21 14:46:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

void solve() {
  int n, m, k;
  cin >> n >> k;
  m = n;

  vector<string> s(n);
  for (int i = 0; i < n; ++i)
    cin >> s[i];

  int nx = 0, no = 0, lib = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'x')
        ++nx;
      else if (s[i][j] == 'o')
        ++no;
      else
        ++lib;
    }
  }

  auto check_win = [&]() {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i][j] == '.')
          continue;

        bool ok = true;
        for (int t = 1; t < k; ++t) {
          if (!(j + t < n && s[i][j] == s[i][j + t]))
            ok = false;
        }
        if (ok)
          return true;

        ok = true;
        for (int t = 1; t < k; ++t) {
          if (!(i + t < n && s[i][j] == s[i + t][j]))
            ok = false;
        
        }
        if (ok)
          return true;
        
        ok = true;
        for (int t = 1; t < k; ++t) {
          if (!(j + t < n && i + t < n && s[i][j] == s[i + t][j + t]))
            ok = false;
        }
        if (ok)
          return true;
        
        ok = true;
        for (int t = 1; t < k; ++t) {
          if (!(j - t >= 0 && i + t < n && s[i][j] == s[i + t][j - t]))
            ok = false;
        }
        if (ok)
          return true;
      }
    }

    return false;
  };

  if (no > nx) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (s[i][j] == 'o')
          s[i][j] = 'x';
        else
          s[i][j] = 'o';
      }
    }
    swap(no, nx);
  }

  if (no + 1 < nx || (!check_win() && lib > 0)) {
    cout << "NIE\n";
    return;
  }

  vector<pair<int, int>> ans;
  while (no > 0 && nx > 0) {
    char ch = 'x';
    bool found = false;
    if (no == nx)
      ch = 'o';

    for (int i = 0; i < n && !found; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i][j] == ch) {
          s[i][j] = '.';
          if (!check_win()) {
            found = true;
            ans.push_back({i, j});
            break;
          }
          s[i][j] = ch;
        }
      }
    }

    if (!found) {
      cout << "NIE\n";
      return;
    }

    if (no == nx)
      --no;
    else
      --nx;
  }

  cout << "TAK\n";
  for (auto it : ans)
    cout << it.first + 1 << " " << it.second + 1 << endl;
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

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 1
1 3
1 1
3 1
2 2
3 3
TAK
2 4
1 1
3 3
1 2
4 2
TAK
1 2
1 1
1 3
2 2
2 1
2 3
3 2
3 1
NIE
NIE
NIE
NIE

result:

wrong output format Expected integer, but "TAK" found (test case 1)