QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399227#1197. Draw in Straight Lineshos_lyricCompile Error//C++145.5kb2024-04-26 07:47:502024-04-26 07:47:50

Judging History

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

  • [2024-04-26 07:47:50]
  • 评测
  • [2024-04-26 07:47: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 <random>
#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; }
#define COLOR(s) ("\x1b[" s "m")


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

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


/*
  '#'
   tate\yoko  no black white
     no        C         INF
  black                     
  white      INF   INF   INF
  
  '.'
   tate\yoko  no black white
     no              C      
  black        C   INF      
  white                     
  
  tate: 1 <== (not black) <== white <== 0
  yoko: 1 <== (not white) <== black <== 0
*/

constexpr int INF = 1001001001;

int M, N, A, B, C;
char S[110][110];

enum { TATE_NOT_BLACK, TATE_WHITE, YOKO_NOT_WHITE, YOKO_BLACK, Z };
int id(int x, int y, int z) {
  return (x * N + y) * Z + z;
}

int main() {
  for (; ~scanf("%d%d%d%d%d", &M, &N, &A, &B, &C); ) {
    for (int x = 0; x < M; ++x) {
      scanf("%s", S[x]);
    }
    
    MaxFlow<int> mf(M * N * Z + 2);
    const int tru = M * N * Z + 0;
    const int fal = M * N * Z + 1;
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      mf.ae(id(x, y, TATE_WHITE), id(x, y, TATE_NOT_BLACK), INF);
      mf.ae(id(x, y, YOKO_BLACK), id(x, y, YOKO_NOT_WHITE), INF);
      mf.ae(tru, id(x, y, TATE_NOT_BLACK), A);
      mf.ae(id(x, y, TATE_WHITE), fal, A);
      mf.ae(tru, id(x, y, YOKO_NOT_WHITE), A);
      mf.ae(id(x, y, YOKO_BLACK), fal, A);
      if (S[x][y] == '#') {
        mf.ae(id(x, y, TATE_NOT_BLACK), id(x, y, YOKO_BLACK), C);
        mf.ae(id(x, y, TATE_WHITE), fal, INF);
        mf.ae(tru, id(x, y, YOKO_WHITE), INF);
      } else if (S[x][y] == '.') {
        mf.ae(id(x, y, YOKO_NOT_WHITE), id(x, y, TATE_NOT_BLACK), C);
        mf.ae(id(x, y, YOKO_BLACK), id(x, y, TATE_WHITE), C);
        mf.ae(id(x, y, YOKO_BLACK), id(x, y, TATE_NOT_BLACK), INF);
      } else {
        assert(false);
      }
    }
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      /*
        (x - 1, y, TATE_NOT_BLACK) && (x, y, TATE_BLACK): +B
        (x - 1, y, TATE_NOT_WHITE) && (x, y, TATE_WHITE): +B
        (x, y - 1, YOKO_NOT_BLACK) && (x, y, YOKO_BLACK): +B
        (x, y - 1, YOKO_NOT_WHITE) && (x, y, YOKO_WHITE): +B
      */
      mf.ae((x == 0) ? tru : id(x - 1, y, TATE_NOT_BLACK), id(x, y, TATE_NOT_BLACK), B);
      mf.ae(id(x, y, TATE_WHITE), (x == 0) ? fal : id(x - 1, y, TATE_WHITE), B);
      mf.ae(id(x, y, YOKO_BLACK), (y == 0) ? fal : id(x, y - 1, YOKO_BLACK), B);
      mf.ae((y == 0) ? tru : id(x, y - 1, YOKO_NOT_WHITE), id(x, y, YOKO_NOT_WHITE), B);
    }
    const int ans = mf.run(tru, fal);
    printf("%d\n", ans);
  }
  return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:144:29: error: ‘YOKO_WHITE’ was not declared in this scope; did you mean ‘YOKO_NOT_WHITE’?
  144 |         mf.ae(tru, id(x, y, YOKO_WHITE), INF);
      |                             ^~~~~~~~~~
      |                             YOKO_NOT_WHITE
answer.code:128:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  128 |       scanf("%s", S[x]);
      |       ~~~~~^~~~~~~~~~~~