QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372647#2833. Hamiltonckiseki#WA 1ms3780kbC++201.6kb2024-03-31 17:04:232024-03-31 17:04:24

Judging History

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

  • [2024-03-31 17:04:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3780kb
  • [2024-03-31 17:04:23]
  • 提交

answer

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

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int n;
  while (cin >> n) {

    vector<string> s(n);
    // for (int i = 0; i < n; i++) {
    //   s[i] = string(n, '0');
    // }
    // for (int i = 0; i < n; i++) {
    //   for (int j = 0; j < i; j++)
    //     if (rand() % 2)
    //       s[i][j] = s[j][i] = '1';
    // }

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

    vector<int> p = {0, 1, 2};

    for (int i = 3; i < n; i++) {
      int cnt = 0;

      int pos = 0;
      for (int j = 0; j < i; j++)
        if (s[p[j]][p[(j+1)%i]] != s[p[(j+1)%i]][p[(j+2)%i]]) {
          pos = (j + 1) % i;
          ++cnt;
        }

      assert(cnt <= 2);
      if (s[i][p[pos]] == s[p[pos]][p[(pos + 1) % i]]) {
        p.insert(p.begin() + pos, i);
      } else {
        p.insert(p.begin() + (pos + 1) % i, i);
      }
    }

    for (int i = 0; i < n; i++) {
      cout << p[i] + 1 << (i+1==n ? '\n' : ' ');
    }

  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3780kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3
4 1 2 3

result:

ok 2 cases.

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3532kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

1 2 3
1 2 3
1 2 3
1 2 3

result:

wrong answer case #3: found 2 indices