QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510954#9170. Cycle Gameucup-team087#WA 0ms3944kbC++143.7kb2024-08-09 14:33:022024-08-09 14:33:04

Judging History

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

  • [2024-08-09 14:33:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3944kb
  • [2024-08-09 14:33:02]
  • 提交

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")


// rollback
vector<int> uf;
vector<pair<int, int>> his;
void init(int n) {
  uf.assign(n, -1);
  his.clear();
}
void update(int u, int p) {
  his.emplace_back(u, uf[u]);
  uf[u] = p;
}
int snapshot() {
  return his.size();
}
void rollback(int stamp) {
  for (; (int)his.size() > stamp; his.pop_back()) uf[his.back().first] = his.back().second;
}
int root(int u) {
  for (; ; u = uf[u]) {
    if (uf[u] < 0) {
      return 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);
  update(u, uf[u] + uf[v]);
  update(v, u);
  return true;
}


constexpr int DX[4] = {+1, 0, -1, 0};
constexpr int DY[4] = {0, +1, 0, -1};

int M, N, Q;
vector<int> X, Y;

int id(int x, int y) {
  return x * (N + 2) + y;
}

int main() {
  for (; ~scanf("%d%d%d", &M, &N, &Q); ) {
    X.resize(Q);
    Y.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d", &X[q], &Y[q]);
    }
    
    string ans(Q, '?');
    
    int n = 0, m = 0, c = 0, s2 = 0, s3 = 0;
    vector<vector<int>> on(M + 2, vector<int>(N + 2, 0));
    init((M + 2) * (N + 2));
    for (int q = 0; q < Q; ++q) {
      int n0 = n, m0 = m, c0 = c, s20 = s2, s30 = s3;
      const auto snap = snapshot();
      
      ++n;
      ++c;
      on[X[q]][Y[q]] = 1;
      for (int dir = 0; dir < 4; ++dir) {
        const int xx = X[q] + DX[dir];
        const int yy = Y[q] + DY[dir];
        if (on[xx][yy]) {
          ++m;
          if (connect(id(X[q], Y[q]), id(xx, yy))) {
            --c;
          }
        }
      }
      for (int x = X[q] - 1; x <= X[q]; ++x) for (int y = Y[q] - 1; y <= Y[q]; ++y) {
        bool ok = true;
        for (int xx = x; xx < x + 2; ++xx) for (int yy = y; yy < y + 2; ++yy) {
          ok = ok && on[xx][yy];
        }
        if (ok) ++s2;
      }
      for (int x = max(X[q] - 2, 0); x <= min(X[q], M - 1); ++x) for (int y = max(Y[q] - 2, 0); y <= min(Y[q], N - 1); ++y) {
        bool ok = true;
        for (int xx = x; xx < x + 3; ++xx) for (int yy = y; yy < y + 3; ++yy) {
          ok = ok && on[xx][yy];
        }
        if (ok) ++s3;
      }
// cerr<<n<<" "<<m<<" "<<c<<" "<<s2<<" "<<s3<<endl;
      if (c - n + m > s2 || s3 > 0) {
        ans[q] = '0';
        n = n0;
        m = m0;
        c = c0;
        s2 = s20;
        s3 = s30;
        rollback(snap);
      } else {
        ans[q] = '1';
      }
    }
    
    puts(ans.c_str());
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3704kb

input:

4 3 7
2 1
2 2
2 3
3 1
3 2
4 1
4 2

output:

1111111

result:

ok "1111111"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

3 3 8
1 1
1 2
1 3
2 3
3 3
3 2
3 1
2 1

output:

11111110

result:

ok "11111110"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

10 10 7
9 1
6 6
3 8
8 7
5 10
1 7
1 2

output:

1111111

result:

ok "1111111"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

9 10 50
1 9
1 6
2 3
3 1
7 4
9 4
1 3
2 5
9 2
7 9
5 6
8 10
9 5
5 5
4 10
9 7
5 9
3 2
4 5
1 1
4 7
3 6
2 8
4 3
8 6
5 10
4 8
5 4
7 2
9 6
4 2
7 8
5 2
3 5
9 1
6 1
1 5
9 9
5 8
6 3
8 8
8 4
7 7
7 1
3 7
2 2
3 10
6 9
8 3
7 6

output:

11111111111111111111111111111111111111111111111111

result:

ok "11111111111111111111111111111111111111111111111111"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

3 5 11
1 5
2 4
1 2
1 3
3 3
3 1
3 4
2 3
1 4
2 1
2 5

output:

11111111111

result:

ok "11111111111"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

7 9 12
7 3
2 3
6 2
2 2
4 2
2 8
5 7
4 4
6 8
2 7
7 2
1 9

output:

111111111111

result:

ok "111111111111"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1 4 1
1 2

output:

1

result:

ok "1"

Test #8:

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

input:

9 8 67
5 5
8 3
9 5
7 4
5 1
9 3
4 2
2 5
1 7
7 8
7 2
8 5
6 1
8 8
4 4
5 4
1 5
3 4
6 7
2 3
3 7
5 7
2 4
2 7
1 3
7 3
2 8
6 6
6 2
6 3
7 5
9 6
7 6
3 6
1 1
6 4
3 1
5 3
8 7
2 1
4 1
8 4
8 6
3 5
5 8
1 6
1 2
4 6
9 4
1 4
3 3
4 8
8 1
4 7
9 8
3 8
6 5
6 8
3 2
2 2
7 1
9 2
4 3
1 8
4 5
8 2
7 7

output:

1111111111111111111111111111111111111111111110010101101100101101000

result:

wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111110010101101000101101101', found: '111111111111111111111111111111...1111111110010101101100101101000'