QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85765#5664. Printing Stickershos_lyricCompile Error//C++148.1kb2023-03-08 14:09:222023-03-08 14:09:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 14:09:26]
  • 评测
  • [2023-03-08 14:09:22]
  • 提交

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


template <class Flow> struct MaxFlow {
  // Watch out when using types other than int and long long.
  static constexpr Flow FLOW_EPS = 1e-10L;
  static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
  
  int n, m;
  vector<int> ptr, nxt, zu;
  vector<Flow> capa;

  explicit MaxFlow(int n_) : n(n_), m(0), ptr(n_, -1) {}
  void ae(int u, int v, Flow w0, Flow w1 = 0) {
    assert(0 <= u); assert(u < n);
    assert(0 <= v); assert(v < n);
    assert(0 <= w0);
    assert(0 <= w1);
    nxt.push_back(ptr[u]); zu.push_back(v); capa.push_back(w0); ptr[u] = m++;
    nxt.push_back(ptr[v]); zu.push_back(u); capa.push_back(w1); ptr[v] = m++;
  }

  vector<int> see, lev, que;

  Flow augment(int u, int t, Flow limFlow) {
    if (u == t) return limFlow;
    for (int &i = see[u]; ~i; i = nxt[i]) if (capa[i] > FLOW_EPS) {
      const int v = zu[i];
      if (lev[u] < lev[v]) {
        const Flow f = augment(v, t, min(limFlow, capa[i]));
        if (f > FLOW_EPS) { capa[i] -= f; capa[i ^ 1] += f; return f; }
      }
    }
    return 0;
  }
  bool bfs(int s, int t) {
    for (int u = 0; u < n; ++u) { see[u] = ptr[u]; lev[u] = -1; }
    auto head = que.begin(), tail = que.begin();
    for (lev[*tail++ = s] = 0; head != tail; ) {
      const int u = *head++;
      for (int i = ptr[u]; ~i; i = nxt[i]) if (capa[i] > FLOW_EPS) {
        const int v = zu[i];
        if (!~lev[v]) {
          lev[*tail++ = v] = lev[u] + 1;
          if (v == t) return true;
        }
      }
    }
    return false;
  }
  Flow run(int s, int t, Flow limFlow = FLOW_INF) {
    see.resize(n); lev.resize(n); que.resize(n);
    Flow flow = 0;
    for (; flow + FLOW_EPS < limFlow && bfs(s, t); ) {
      for (Flow f; (f = augment(s, t, limFlow - flow)) > FLOW_EPS; flow += f) {}
    }
    return flow;
  }
};

////////////////////////////////////////////////////////////////////////////////


vector<int> uf;
int root(int u) {
  return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


constexpr int INF = 1001001001 / 2;

char buf[20010];

int M, N, H, V;
vector<string> A, B;
vector<vector<int>> D;

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d%d%d", &M, &N, &H, &V);
    A.resize(M);
    for (int x = 0; x < M; ++x) {
      scanf("%s", buf);
      A[x] = buf;
    }
    B.resize(M);
    for (int x = 0; x < M; ++x) {
      scanf("%s", buf);
      B[x] = buf;
    }
    D.assign(M, vector<int>(N));
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      scanf("%d", &D[x][y]);
    }
    
    const int NUM_VERTS = M * (2 * N) + 1;
    const int snk = M * (2 * N);
    uf.assign(NUM_VERTS, -1);
    
    vector<vector<vector<int>>> usss(M + 1, vector<vector<int>>(N + 1));
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      const int u = x * (2 * N) + 2 * y + 0;
      const int v = x * (2 * N) + 2 * y + 1;
      const bool bu = (B[x][2 * y + 0] == '#');
      const bool bv = (B[x][2 * y + 1] == '#');
      if (A[x][y] == '/') {
        if (bu) {
          usss[x + 0][y + 0].push_back(u);
          usss[x + 0][y + 1].push_back(u);
          usss[x + 1][y + 0].push_back(u);
        }
        if (bv) {
          usss[x + 0][y + 1].push_back(v);
          usss[x + 1][y + 0].push_back(v);
          usss[x + 1][y + 1].push_back(v);
        }
      } else {
        if (bu) {
          usss[x + 0][y + 0].push_back(u);
          usss[x + 1][y + 0].push_back(u);
          usss[x + 1][y + 1].push_back(u);
        }
        if (bv) {
          usss[x + 0][y + 0].push_back(v);
          usss[x + 0][y + 1].push_back(v);
          usss[x + 1][y + 1].push_back(v);
        }
      }
    }
    for (int x = 0; x <= M; ++x) for (int y = 0; y <= N; ++y) if (!usss[x][y].empty()) {
      const int u = usss[x][y][0];
      for (const int v : usss[x][y]) {
        connect(u, v);
      }
    }
    
    vector<int> rs;
    for (int x = 0; x < M; ++x) for (int z = 0; z < 2 * N; ++z) if (B[x][z] == '#') {
      const int u = x * (2 * N) + z;
      if (uf[u] < 0) {
// cerr<<"comp "<<u<<" "<<-uf[u]<<endl;
        rs.push_back(u);
      }
    }
    
// for(int x=0;x<M;++x){for(int z=0;z<2*N;++z)fprintf(stderr,"%3d ",root(x*(2*N)+z));cerr<<endl;}
    
    vector<pair<pair<int, int>, int>> edges;
    auto ae = [&](int x0, int z0, int x1, int z1, int c) -> void {
      const int u = root(x0 * (2 * N) + z0);
      const int v = root(x1 * (2 * N) + z1);
      const int cc = (B[x0][z0] != '#' && (x1 == M || B[x1][z1] != '#')) ? c : INF;
// cerr<<"ae "<<x0<<" "<<z0<<" "<<x1<<" "<<z1<<" "<<c<<endl;
// cerr<<"ae "<<u<<" "<<v<<" "<<c<<" "<<cc<<endl;
// if((x0==2&&z0==7)||(x1==2&&z1==7))cerr<<"ae "<<u<<" "<<v<<" "<<c<<" "<<cc<<endl;
// if(x1==M)cerr<<"ae "<<u<<" "<<v<<" "<<c<<" "<<cc<<endl;
      if (u != v) {
        edges.emplace_back(make_pair(
          // x0 * (2 * N) + z0,
          // x1 * (2 * N) + z1
          u, v
        ), cc);
      }
    };
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      if (x + 1 < M) {
        ae(
          x    , 2 * y + ((A[x    ][y] == '/') ? 1 : 0),
          x + 1, 2 * y + ((A[x + 1][y] == '/') ? 0 : 1),
          H
        );
      }
      if (y + 1 < N) {
        ae(
          x, 2 *  y      + 1,
          x, 2 * (y + 1) + 0,
          V
        );
      }
    }
    for (int y = 0; y < N; ++y) {
      ae(
        0, 2 * y + ((A[0][y] == '/') ? 0 : 1),
        M, 0,
        H
      );
      ae(
        M - 1, 2 * y + ((A[M - 1][y] == '/') ? 1 : 0),
        M, 0,
        H
      );
    }
    for (int x = 0; x < M; ++x) {
      ae(
        x, 2 * 0 + 0,
        M, 0,
        V
      );
      ae(
        x, 2 * (N - 1) + 1,
        M, 0,
        V
      );
    }
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      ae(
        x, 2 * y + 0,
        x, 2 * y + 1,
        D[x][y]
      );
    }
    
    vector<int> ans;
    for (const int r : rs) {
      MaxFlow<int> mf(NUM_VERTS);
      for (const auto &edge : edges) {
        mf.ae(edge.first.first, edge.first.second, edge.second, edge.second);
      }
      for (const int rr : rs) if (r != rr) {
        mf.ae(rr, snk, INF);
      }
      const int res = mf.run(r, snk);
/*
if(res>=INF){
 cerr<<"HELP"<<endl;
 for(int i=0;i<mf.m;++i)if(mf.capa[i^1]>=INF){
  cerr<<mf.zu[i^1]<<" "<<mf.zu[i]<<" "<<mf.capa[i^1]<<" "<<mf.capa[i]<<endl;
 }
}
//*/
      ans.push_back(res);
    }
    
    sort(ans.begin(), ans.end());
    const int ansLen = ans.size();
    printf("%d\n", ansLen);
    for (int h = 0; h < ansLen; ++h) {
      if (h) printf(" ");
      printf("%d", ans[h]);
    }
    puts("");
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

answer.code:38:41: error: ‘numeric_limits’ is not a member of ‘std’
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                         ^~~~~~~~~~~~~~
answer.code:38:60: error: expected primary-expression before ‘>’ token
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                            ^
answer.code:38:66: error: no matching function for call to ‘max()’
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                             ~~~~~^~
In file included from /usr/include/c++/11/algorithm:61,
                 from answer.code:7:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
answer.code:38:66: note:   candidate expects 2 arguments, 0 provided
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                             ~~~~~^~
In file included from /usr/include/c++/11/algorithm:61,
                 from answer.code:7:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
answer.code:38:66: note:   candidate expects 3 arguments, 0 provided
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                             ~~~~~^~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:7:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)’
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
answer.code:38:66: note:   candidate expects 1 argument, 0 provided
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                             ~~~~~^~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:7:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)’
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
answer.code:38:66: note:   candidate expects 2 arguments, 0 provided
   38 |   static constexpr Flow FLOW_INF = std::numeric_limits<Flow>::max();
      |                                                             ~~~~~^~
answer.code: In function ‘int main()’:
answer.code:120:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  120 |     scanf("%d%d%d%d", &M, &N, &H, &V);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:123:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  123 |       scanf("%s", buf);
      |       ~~~~~^~~~~~~~~~~
answer.code:128:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  128 |       scanf("%s", buf);
      |       ~~~~~^~~~~~~~~~~
answer.code:133:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  133 |       scanf("%d", &D[x][y]);
      |       ~~~~~^~~~~~~~~~~~~~~~