QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117080#6668. Trokutihos_lyric#Compile Error//C++147.1kb2023-06-30 12:50:502024-05-31 18:41:03

Judging History

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

  • [2024-05-31 18:41:03]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 12:50:50]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


// [0, 2^32)
unsigned xrand() {
  static unsigned x = 314159265, y = 358979323, z = 846264338, w = 327950288;
  unsigned t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
}

// [a, b]
int xrand(int a, int b) { return a + xrand() % (b - a + 1); }


constexpr int N = 100;

#ifdef LOCAL
int secret[N][N];
int Q;
#endif

int Ask(int u, int v, int w) {
  assert(0 <= u); assert(u < N);
  assert(0 <= v); assert(v < N);
  assert(0 <= w); assert(w < N);
  assert(u != v); assert(v != w); assert(w != u);
  int s;
#ifdef LOCAL
  ++Q;
  s = secret[u][v] + secret[v][w] + secret[w][u];
#else
  printf("? %d %d %d\n", u + 1, v + 1, w + 1);
  fflush(stdout);
  scanf("%d", &s);
#endif
  return s;
}

int A[N][N];
void Answer() {
#ifdef LOCAL
  for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) {
    assert(secret[u][v] == A[u][v]);
  }
  cerr << "Accepted: Q = " << Q << endl;
#else
  puts("!");
  for (int u = 0; u < N; ++u) {
    for (int v = 0; v < N; ++v) {
      printf("%d", A[u][v]);
    }
    puts("");
  }
  fflush(stdout);
#endif
}


map<vector<int>, vector<int>> psss[6];
void small() {
  for (int n = 3; n <= 5; ++n) {
    const int m = n * (n - 1) / 2;
    for (int p = 0; p < 1 << m; ++p) {
      int a[5][5] = {};
      {
        int pos = 0;
        for (int u = 0; u < n; ++u) for (int v = u + 1; v < n; ++v) {
          a[u][v] = a[v][u] = p >> pos & 1;
          ++pos;
        }
      }
      vector<int> fs;
      for (int u = 0; u < n; ++u) for (int v = u + 1; v < n; ++v) for (int w = v + 1; w < n; ++w) {
        fs.push_back(a[u][v] + a[v][w] + a[w][u]);
      }
      psss[n][fs].push_back(p);
    }
#ifdef LOCAL
    for (const auto &kv : psss[n]) if (kv.second.size() >= 2) {
      cerr << kv.first;
      for (const int p : kv.second) {
        cerr << " ";
        for (int i = 0; i < m; ++i) cerr << ((p >> i) & 1);
      }
      cerr << endl;
    }
#endif
    if (n == 4) {
      for (const auto &kv : psss[n]) {
        for (const int p0 : kv.second) for (const int p1 : kv.second) if (p0 != p1) {
          assert(__builtin_popcount(p0 ^ p1) >= 4);
        }
      }
    }
  }
}

void ae(int u, int v, int c) {
  assert(0 <= u); assert(u < N);
  assert(0 <= v); assert(v < N);
  assert(c == 0 || c == 1);
  if (!~A[u][v]) A[u][v] = c;
  if (!~A[v][u]) A[v][u] = c;
  assert(A[u][v] == c);
  assert(A[v][u] == c);
}

void determine(int n, const int us[]) {
  assert(3 <= n); assert(n <= 5);
  vector<int> fs;
  for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) for (int k = j + 1; k < n; ++k) {
    const int u = us[i], v = us[j], w = us[k];
    int f;
    if (~A[u][v] && ~A[v][w] && ~A[w][u]) {
      f = A[u][v] + A[v][w] + A[w][u];
    } else {
      f = Ask(u, v, w);
    }
    fs.push_back(f);
  }
  auto it = psss[n].find(fs);
  assert(it != psss[n].end());
  {
    int pos = 0;
    for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) {
      bool ok = true;
      int c = -1;
      for (const int p : it->second) {
        if (!~c) c = p >> pos & 1;
        ok = ok && (c == (p >> pos & 1));
      }
      if (ok) {
        ae(us[i], us[j], c);
      }
      ++pos;
    }
  }
}

constexpr int R = 0;
vector<int> U;
int counter;
void rec(int l, int r) {
  if (r - l >= 3) {
    // for (int i = l; i < r; ++i) swap(U[xrand(l, i)], U[i]);
    const int mid = l + (r - l + 1) / 2;
    for (int i = 0; i < mid - l; ++i) for (int j = i + 1; j < mid - l; ++j) {
++counter;
      int u = U[l + i];
      int v = U[l + j];
      int w = U[mid + (i + j) % (r - mid)];
      // swap((xrand() % 2) ? u : v, v);
      // swap((xrand() % 3) ? ((xrand() % 2) ? u : v) : w, w);
      if (!~A[u][v] && !~A[v][w] && !~A[w][v]) {
        const int f = Ask(u, v, w);
        if (f == 0 || f == 3) {
          ae(u, v, f/3);
          ae(v, w, f/3);
          ae(w, u, f/3);
        } else {
          const int fuv = Ask(R, u, v);
          ae(u, v, fuv - A[R][u] - A[R][v]);
          if (f - A[u][v] == 0 || f - A[u][v] == 2) {
            ae(v, w, (f - A[u][v]) / 2);
            ae(w, u, (f - A[u][v]) / 2);
          } else {
            const int fvw = Ask(R, v, w);
            ae(v, w, fvw - A[R][v] - A[R][w]);
            ae(w, u, f - A[u][v] - A[v][w]);
          }
        }
      }
    }
    rec(mid, r);
  }
}

int main() {
#ifdef LOCAL
  for (int u = 0; u < N; ++u) {
    char buf[N + 1];
    scanf("%s", buf);
    for (int v = 0; v < N; ++v) {
      secret[u][v] = buf[v] - '0';
    }
  }
  for (int u = 0; u < N; ++u) {
    assert(secret[u][u] == 0);
  }
  for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) {
    assert(secret[u][v] == secret[v][u]);
  }
#endif
  
  small();
  
  for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) if (u != v) {
    A[u][v] = -1;
  }
  
  {
    vector<int> ss;
    for (int u = 0; u < N; ++u) if (R != u && !~A[R][u]) {
      ss.push_back(u);
    }
    const int ssLen = ss.size();
    for (int h = 0; h < ssLen; h += 4) {
      vector<int> used(N, 0);
      int us[5];
      fill(us, us + 5, -1);
      used[us[0] = R] = 1;
      for (int i = 1; i < 5; ++i) if (h + (i - 1) < ssLen) {
        used[us[i] = ss[h + (i - 1)]] = 1;
      }
      for (int i = 1; i < 5; ++i) if (!~us[i]) {
        for (int u = 0; u < N; ++u) if (!used[u]) {
          used[us[i] = u] = 1;
          break;
        }
        assert(~us[i]);
      }
// pv(us,us+5);
      determine(5, us);
    }
  }
cerr<<"Q = "<<Q<<endl;
  
  for (int u = 0; u < N; ++u) if (R != u) {
    U.push_back(u);
  }
  // for (int i = 0; i < N - 1; ++i) swap(U[xrand(0, i)], U[i]);
  rec(0, N - 1);
cerr<<"counter = "<<counter<<endl;
  
  for (int u = 0; u < N; ++u) for (int v = u + 1; v < N; ++v) if (!~A[u][v]) {
    const int res = Ask(R, u, v);
    ae(u, v, res - A[R][u] - A[R][v]);
  }
  
  Answer();
  return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:257:15: error: ‘Q’ was not declared in this scope
  257 | cerr<<"Q = "<<Q<<endl;
      |               ^
answer.code: In function ‘int Ask(int, int, int)’:
answer.code:65:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |   scanf("%d", &s);
      |   ~~~~~^~~~~~~~~~