QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#27927 | #2617. Browsing the Collection | Geothermal | WA | 2ms | 3520kb | C++ | 2.7kb | 2022-04-11 10:08:53 | 2022-04-29 08:06:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(i, a) for (auto &i : a)
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(), x.end()
const char nl = '\n';
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M; cin >> N >> M;
int P = 1 << M;
vector<vi> graph(N*P);
bool used[M][N]; F0R(i, M) F0R(j, N) used[i][j] = false;
int A[N][M];
F0R(i, N) {
F0R(j, M) {
cin >> A[i][j];
A[i][j]--;
}
}
F0R(i, N) {
F0R(j, P) {
int r = -1, l = -1;
vpi rem;
FOR(x, i, i+N) {
int v = x%N;
bool ok = true;
F0R(k, M) {
if (j & (1 << k)) {
if (A[i][k] != A[v][k]) ok = false;
}
}
if (ok && v != i) {
if (r == -1) {
r = v;
}
l = v;
}
F0R(k, M) {
if ((j & (1 << k)) == 0) {
if (!used[k][A[v][k]]) {
F0R(l, M) {
if ((j & (1 << k)) && A[v][l] != A[i][l]) goto skip;
}
used[k][A[v][k]] = true;
rem.pb({k, A[v][k]});
graph[v*P+j+(1<<k)].pb(i*P+j);
skip:
;
}
}
}
}
trav(a, rem) used[a.f][a.s] = false;
if (r != -1) {
graph[r*P+j].pb(i*P+j);
}
if (l != -1) {
graph[l*P+j].pb(i*P+j);
}
F0R(k, M) {
if (j & (1 << k)) {
int nxt = j - (1 << k);
graph[i*P+nxt].pb(i*P+j);
}
}
}
}
cout << "DONE" << endl;
int dist[N*P];
int ans[N][N];
F0R(r, N) {
F0R(i, N*P) dist[i] = N*P+10;
queue<int> q;
F0R(i, P) {
dist[r*P+i] = 0;
q.push(r*P+i);
}
while (!q.empty()) {
int v = q.front(); q.pop();
trav(a, graph[v]) {
if (dist[a] > dist[v] + 1) {
dist[a] = dist[v] + 1;
q.push(a);
}
}
}
for (int x = 0; x < N*P; x += P) {
ans[x/P][r] = dist[x];
}
}
F0R(i, N) {
F0R(j, N) {
cout << ans[i][j] << " ";
}
cout << nl;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3520kb
input:
9 3 5 3 7 5 3 4 5 3 7 5 3 2 5 3 4 5 3 7 2 3 7 5 3 7 2 3 7
output:
DONE 0 1 2 1 2 3 1 2 1 1 0 1 1 2 2 1 3 2 2 1 0 1 1 2 1 3 2 3 2 1 0 1 1 1 3 2 3 2 2 1 0 1 1 3 2 3 1 2 1 1 0 1 2 2 2 1 3 1 2 1 0 1 2 2 1 3 1 2 2 1 0 1 1 1 3 1 2 3 2 1 0
result:
wrong output format Expected integer, but "DONE" found