QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#101883#5448. 另一个欧拉数问题hos_lyric0 0ms0kbC++144.4kb2023-05-01 16:01:522023-05-01 16:01:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 16:01:55]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-05-01 16:01:52]
  • 提交

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 <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; }


namespace bm {
constexpr int LIM_N0 = 210;
constexpr int LIM_N1 = 210;
constexpr int LIM_M = 40010;
int n0, n1, m, as[LIM_M], bs[LIM_M];
int to[LIM_N0], fr[LIM_N1], tof;
int pt[LIM_N0 + 2], zu[LIM_M], used[LIM_N0], lev[LIM_N0], que[LIM_N0], *qb, *qe;
void init(int n0_, int n1_) {
  n0 = n0_; n1 = n1_; m = 0;
}
int ae(int u, int v) {
  as[m] = u; bs[m] = v; return m++;
}
int augment(int u) {
  used[u] = tof;
  for (int j = pt[u]; j < pt[u + 1]; ++j) {
    const int v = zu[j];
    const int w = fr[v];
    if (!~w || (used[w] != tof && lev[u] < lev[w] && augment(w))) {
      to[u] = v; fr[v] = u; return 1;
    }
  }
  return 0;
}
int run() {
  memset(pt, 0, (n0 + 2) * sizeof(int));
  for (int i = 0; i < m; ++i) ++pt[as[i] + 2];
  for (int u = 2; u <= n0; ++u) pt[u + 1] += pt[u];
  for (int i = 0; i < m; ++i) zu[pt[as[i] + 1]++] = bs[i];
  memset(to, ~0, n0 * sizeof(int));
  memset(fr, ~0, n1 * sizeof(int));
  memset(used, ~0, n0 * sizeof(int));
  for (tof = 0; ; ) {
    qb = qe = que; memset(lev, ~0, n0 * sizeof(int));
    for (int u = 0; u < n0; ++u) if (!~to[u]) lev[*qe++ = u] = 0;
    for (; qb != qe; ) {
      const int u = *qb++;
      for (int j = pt[u]; j < pt[u + 1]; ++j) {
        const int w = fr[zu[j]];
        if (~w && !~lev[w]) lev[*qe++ = w] = lev[u] + 1;
      }
    }
    int f = 0;
    for (int u = 0; u < n0; ++u) if (!~to[u]) f += augment(u);
    if (!f) return tof;
    tof += f;
  }
}

// s: true, t: false (s: reachable from unmatched left)
// vertex cover: (0: false, 0: true)
// independent set: (0: true, 1: false)
bool side0[LIM_N0], side1[LIM_N1];
void dfs(int u) {
  if (!side0[u]) {
    side0[u] = true;
    for (int j = pt[u]; j < pt[u + 1]; ++j) {
      const int v = zu[j];
      if (!side1[v]) {
        side1[v] = true;
        const int w = fr[v];
        if (~w) dfs(w);
      }
    }
  }
}
void minCut() {
  memset(side0, 0, n0 * sizeof(bool));
  memset(side1, 0, n1 * sizeof(bool));
  for (int u = 0; u < n0; ++u) if (!~to[u]) dfs(u);
}
}  // namespace bm


int N;
int A[210][210];

struct Op {
  int i0, j0, i1, j1;
};

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
      scanf("%d", &A[i][j]);
      --A[i][j];
    }
    
    vector<vector<int>> jss(N);
    vector<vector<int>> used(N, vector<int>(N, 0));
    for (int k = 0; k < N; ++k) {
      bm::init(N, N);
      for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) if (!used[i][j]) {
          bm::ae(i, A[i][j]);
        }
      }
      const int res = bm::run();
      assert(res == N);
      for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) if (!used[i][j]) {
          if (bm::to[i] == A[i][j]) {
            jss[i].push_back(j);
            used[i][j] = 1;
            break;
          }
        }
      }
    }
    
    printf("%d\n", N * (N - 1));
    for (int i0 = 0; i0 < N; ++i0) for (int i1 = i0 + 1; i1 < N; ++i1) {
      printf("%d %d %d %d\n", i0 + 1, jss[i0][i1] + 1, i1 + 1, jss[i1][i0] + 1);
    }
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

584 1985 1017 186
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

1 199913 100055 1
1

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

2 199984 99989 1
1 1

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%