QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#32667 | #2617. Browsing the Collection | Sorting# | WA | 3ms | 4168kb | C++20 | 3.0kb | 2022-05-22 22:34:17 | 2022-05-22 22:34:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 3;
const int M = 5 + 3;
const int T = 32 + 3;
const int STATES = 500 * 32 + 3;
int n, m;
int ans[N][N], a[N][M];
template<class T>
void check_min(T &a, T b){ a = (a < b) ? a : b; }
vector<int> adj[STATES];
bool check(int i, int state, int j){
for(int k = 0; k < 5; ++k){
if(state >> k & 1){
if(a[i][k] != a[j][k])
return false;
}
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j){
cin >> a[i][j];
--a[i][j];
}
for(int i = 0; i < n; ++i){
for(int state = 0; state < 32; ++state){
for(int j = 0; j < m; ++j){
if((state & (1 << j)))
adj[i * 32 + state].push_back(i * 32 + (state ^ (1 << j)));
}
static bool vis[T][N];
for(int j = 0; j < m; ++j)
fill(vis[j], vis[j] + n, false);
for(int j = 0; j < m; ++j){
if(!(state >> j & 1)){
vis[j][a[i][j]] = true;
adj[i * 32 + state].push_back(i * 32 + (state ^ (1 << j)));
}
}
for(int j = i + 1; j != i; j = (j + 1) % n){
for(int k = 0; k < m; ++k){
if(!(state >> k & 1) && !vis[k][a[j][k]]){
vis[k][a[j][k]] = true;
adj[i * 32 + state].push_back(j * 32 + (state ^ (1 << k)));
}
}
}
for(int j = i + 1; j != i; j = (j + 1) % n){
if(check(i, state, j)){
adj[i * 32 + state].push_back(j * 32 + state);
break;
}
}
for(int j = i - 1; j != i; j = (j - 1 + n) % n){
if(check(i, state, j)){
adj[i * 32 + state].push_back(j * 32 + state);
break;
}
}
}
}
const int INF = 1e9;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
ans[i][j] = INF;
for(int i = 0; i < n; ++i){
static int d[STATES];
for(int j = 0; j < STATES; ++j)
d[j] = INF;
queue<int> q;
for(int j = 0; j < 1; ++j){
q.push(i * 32 + j);
d[i * 32 + j] = 0;
}
while(!q.empty()){
int u = q.front();
q.pop();
check_min(ans[i][u / 32], d[u]);
for(int to: adj[u]){
int cand = d[u] + 1;
if(d[to] > cand){
d[to] = cand;
q.push(to);
}
}
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j)
cout << ans[i][j] << " ";
cout << "\n";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 4168kb
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:
0 1 2 1 2 3 1 2 2 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 2 1 2 1 2 3 2 1 0
result:
wrong answer 9th numbers differ - expected: '1', found: '2'