QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460135#8830. Breaking Badhos_lyricWA 0ms3968kbC++146.5kb2024-07-01 03:06:062024-07-01 03:06:06

Judging History

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

  • [2024-07-01 03:06:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3968kb
  • [2024-07-01 03:06:06]
  • 提交

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 <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr int MO = 5;
using Mint = ModInt<MO>;


int rot(int f, Mint a) {
  return (f<<a.x & ((1<<MO) - 1)) | (f>>(MO-a.x));
}

int N;
Mint A[1010][1010];

int main() {
  for (; ~scanf("%d", &N); ) {
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
      scanf("%u", &A[i][j].x);
    }
    
    int h = 0;
    for (; h < 2 * (MO - 1) && h < N; ) {
      for (int i = h + 1; i < N; ++i) for (int j = h + 1; j < N; ++j) {
        if (A[h][h] - A[h][j] - A[i][h] + A[i][j]) {
          for (int k = 0; k < N; ++k) swap(A[h + 1][k], A[j][k]);
          for (int k = 0; k < N; ++k) swap(A[k][h + 1], A[k][j]);
          h += 2;
          goto found;
        }
      }
      break;
     found:{}
    }
    
    Mint off = 0;
    string ans(MO, 'N');
    if (h >= 2 * (MO - 1)) {
      // (MO - 1) elements to adjust (MO: prime)
      ans.assign(MO, 'Y');
    } else {
      if (h < N) {
        for (int i = h; i < N; ++i) {
          const Mint t = A[i][h];
          off += t;
          for (int j = 0; j < N; ++j) A[i][j] -= t;
        }
        for (int j = h; j < N; ++j) {
          const Mint t = A[h][j];
          off += t;
          for (int i = 0; i < N; ++i) A[i][j] -= t;
        }
      }
// cerr<<"off = "<<off<<", h = "<<h<<endl;for(int i=0;i<N;++i){cerr<<"A["<<i<<"] = ";pv(A[i],A[i]+N);}
      for (int i = h; i < N; ++i) for (int j = h; j < N; ++j) {
        assert(!A[i][j]);
      }
      
      // A[h, N)[0, h)
      vector<int> fs(1<<h, 0);
      fs[0] |= 1<<0;
      for (int i = h; i < N; ++i) {
        for (int p = 1<<h; --p >= 0; ) {
          for (int j = 0; j < h; ++j) if (!(p & 1<<j)) {
            fs[p | 1<<j] |= rot(fs[p], A[i][j]);
          }
        }
      }
      // A[0, h)[h, N)
      vector<int> gs(1<<h, 0);
      gs[0] |= 1<<0;
      for (int j = h; j < N; ++j) {
        for (int p = 1<<h; --p >= 0; ) {
          for (int i = 0; i < h; ++i) if (!(p & 1<<i)) {
            gs[p | 1<<i] |= rot(gs[p], A[i][j]);
          }
        }
      }
      // A[0, h)[0, h)
      vector<vector<int>> dp(1<<h, vector<int>(1<<h, 0));
      dp[0][0] |= 1<<0;
      for (int i = 0; i < h; ++i) {
        for (int p = 1<<h; --p >= 0; ) for (int q = 1<<h; --q >= 0; ) {
          for (int j = 0; j < h; ++j) if (!(p & 1<<i) && !(q & 1<<j)) {
            dp[p | 1<<i][q | 1<<j] |= rot(dp[p][q], A[i][j]);
          }
        }
      }
      for (int p = 1<<h; --p >= 0; ) for (int q = 1<<h; --q >= 0; ) {
        for (int x = 0; x < MO; ++x) if (fs[(1<<h) - 1 - p] & 1<<x)
        for (int y = 0; y < MO; ++y) if (gs[(1<<h) - 1 - q] & 1<<y)
        for (int z = 0; z < MO; ++z) if (dp[p][q] & 1<<z)
        {
          ans[(off + x + y + z).x] = 'Y';
        }
      }
    }
    puts(ans.c_str());
  }
  return 0;
}

詳細信息

Test #1:

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

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

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

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

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

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

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

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

NYYYY

result:

wrong answer 1st words differ - expected: 'NYNNY', found: 'NYYYY'