QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384815 | #2833. Hamilton | ucup-team1209# | WA | 0ms | 3568kb | C++20 | 1.1kb | 2024-04-10 12:58:42 | 2024-04-10 12:58:43 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
const int N = 5005;
int n, m;
int e[N][N];
int main() {
#ifdef zqj
freopen("$.in", "r", stdin);
#endif
std::ios::sync_with_stdio(false), cin.tie(0);
for(;cin >> n;) {
std::vector<int> w, b;
std::mt19937 gen(12400);
for(int i = 1;i <= n;++i) {
for(int j = 1;j <= n;++j) {
char c; cin >> c;
e[i][j] = c & 1;
}
}
for(int i = 1;i <= n;++i) {
for(;w.size();) {
if(b.size() && e[w.back()][b.back()] == 1) {
b.push_back(w.back());
w.pop_back();
} else {
break;
}
}
if(w.empty()) {
w.push_back(i);
} else if(b.empty()) {
b.push_back(i);
} else {
if(e[b.back()][i] == 1) {
b.push_back(i);
} else {
w.push_back(b.back());
w.push_back(i);
b.pop_back();
}
}
for(int i = 1;i < (int) w.size();++i) {
assert(e[w[i - 1]][w[i]] == 0);
}
for(int i = 1;i < (int) b.size();++i) {
assert(e[b[i - 1]][b[i]] == 1);
}
}
for(int x : w) {
cout << x << ' ';
}
for(int x : b) {
cout << x << ' ';
}
cout << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
1 2 3 1 2 3 4
result:
ok 2 cases.
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 3 2 1 3 2 1 3 2 1
result:
wrong answer case #2: found 2 indices